Genres on main menu

This commit is contained in:
simojenki
2021-03-07 11:37:13 +11:00
parent 3f607c5304
commit 86a2411f21
2 changed files with 83 additions and 9 deletions

View File

@@ -164,6 +164,12 @@ const container = ({
title,
});
const genre = (genre: string) => ({
itemType: "container",
id: `genre:${genre}`,
title: genre,
})
const album = (album: AlbumSummary) => ({
itemType: "album",
id: `album:${album.id}`,
@@ -237,9 +243,10 @@ function bindSmapiSoapServiceToExpress(
mediaCollection: [
container({ id: "artists", title: "Artists" }),
container({ id: "albums", title: "Albums" }),
container({ id: "genres", title: "Genres" }),
],
index: 0,
total: 2,
total: 3,
});
case "artists":
return await musicLibrary.artists(paging).then((result) =>
@@ -263,6 +270,17 @@ function bindSmapiSoapServiceToExpress(
total: result.total,
})
);
case "genres":
return await musicLibrary
.genres()
.then(slice2(paging))
.then(([page, total]) =>
getMetadataResult({
mediaCollection: page.map(genre),
index: paging._index,
total,
})
);
case "artist":
return await musicLibrary
.artist(typeId!)

View File

@@ -353,23 +353,79 @@ describe("api", () => {
mediaCollection: [
{ itemType: "container", id: "artists", title: "Artists" },
{ itemType: "container", id: "albums", title: "Albums" },
{ itemType: "container", id: "genres", title: "Genres" },
],
index: 0,
total: 2,
total: 3,
})
);
});
});
describe("asking for a genres", () => {
const artist1 = anArtist({
albums: [anAlbum({ genre: "Pop" }), anAlbum({ genre: "Rock" })],
});
const artist2 = anArtist({
albums: [
anAlbum({ genre: "Trip-Hop" }),
anAlbum({ genre: "Punk" }),
anAlbum({ genre: "Pop" }),
],
});
const expectedGenres = ["Pop", "Punk", "Rock", "Trip-Hop"];
beforeEach(() => {
musicService.hasArtists(artist1, artist2);
});
describe("asking for all genres", () => {
it("should return a collection of genres", async () => {
const result = await ws.getMetadataAsync({
id: `genres`,
index: 0,
count: 100,
});
expect(result[0]).toEqual(
getMetadataResult({
mediaCollection: expectedGenres.map((genre) => ({
itemType: "container",
id: `genre:${genre}`,
title: genre,
})),
index: 0,
total: expectedGenres.length,
})
);
});
});
describe("asking for a page of genres", () => {
it("should return just that page", async () => {
const result = await ws.getMetadataAsync({
id: `genres`,
index: 1,
count: 2,
});
expect(result[0]).toEqual(
getMetadataResult({
mediaCollection: ["Punk", "Rock"].map((genre) => ({
itemType: "container",
id: `genre:${genre}`,
title: genre,
})),
index: 1,
total: expectedGenres.length,
})
);
});
});
});
describe("asking for a single artist", () => {
const artistWithManyAlbums = anArtist({
albums: [
anAlbum(),
anAlbum(),
anAlbum(),
anAlbum(),
anAlbum(),
],
albums: [anAlbum(), anAlbum(), anAlbum(), anAlbum(), anAlbum()],
});
beforeEach(() => {