Album view sort by album name not artist name

This commit is contained in:
simojenki
2021-08-16 10:13:16 +10:00
parent db0351da39
commit c67f74bf08
6 changed files with 52 additions and 29 deletions

View File

@@ -99,7 +99,7 @@ export const asResult = <T>([results, total]: [T[], number]) => ({
export type ArtistQuery = Paging; export type ArtistQuery = Paging;
export type AlbumQueryType = 'alphabeticalByArtist' | 'byGenre' | 'random' | 'recent' | 'frequent' | 'newest' | 'starred'; export type AlbumQueryType = 'alphabeticalByArtist' | 'alphabeticalByName' | 'byGenre' | 'random' | 'recent' | 'frequent' | 'newest' | 'starred';
export type AlbumQuery = Paging & { export type AlbumQuery = Paging & {
type: AlbumQueryType; type: AlbumQueryType;

View File

@@ -632,7 +632,7 @@ function bindSmapiSoapServiceToExpress(
}); });
case "albums": { case "albums": {
return albums({ return albums({
type: "alphabeticalByArtist", type: "alphabeticalByName",
...paging, ...paging,
}); });
} }

View File

@@ -16,6 +16,7 @@ import {
HIP_HOP, HIP_HOP,
SKA, SKA,
} from "./builders"; } from "./builders";
import _ from "underscore";
describe("InMemoryMusicService", () => { describe("InMemoryMusicService", () => {
const service = new InMemoryMusicService(); const service = new InMemoryMusicService();
@@ -210,6 +211,7 @@ describe("InMemoryMusicService", () => {
const artist3_album2 = anAlbum({ genre: POP }); const artist3_album2 = anAlbum({ genre: POP });
const artist1 = anArtist({ const artist1 = anArtist({
name: "artist1",
albums: [ albums: [
artist1_album1, artist1_album1,
artist1_album2, artist1_album2,
@@ -218,8 +220,8 @@ describe("InMemoryMusicService", () => {
artist1_album5, artist1_album5,
], ],
}); });
const artist2 = anArtist({ albums: [artist2_album1] }); const artist2 = anArtist({ name: "artist2", albums: [artist2_album1] });
const artist3 = anArtist({ albums: [artist3_album1, artist3_album2] }); const artist3 = anArtist({ name: "artist3", albums: [artist3_album1, artist3_album2] });
const artistWithNoAlbums = anArtist({ albums: [] }); const artistWithNoAlbums = anArtist({ albums: [] });
const allAlbums = [artist1, artist2, artist3, artistWithNoAlbums].flatMap( const allAlbums = [artist1, artist2, artist3, artistWithNoAlbums].flatMap(
@@ -265,29 +267,48 @@ describe("InMemoryMusicService", () => {
describe("fetching multiple albums", () => { describe("fetching multiple albums", () => {
describe("with no filtering", () => { describe("with no filtering", () => {
describe("fetching all on one page", () => { describe("fetching all on one page", () => {
it("should return all the albums for all the artists", async () => { describe("alphabeticalByArtist", () => {
expect( it("should return all the albums for all the artists", async () => {
await musicLibrary.albums({ expect(
_index: 0, await musicLibrary.albums({
_count: 100, _index: 0,
type: "alphabeticalByArtist", _count: 100,
}) type: "alphabeticalByArtist",
).toEqual({ })
results: [ ).toEqual({
albumToAlbumSummary(artist1_album1), results: [
albumToAlbumSummary(artist1_album2), albumToAlbumSummary(artist1_album1),
albumToAlbumSummary(artist1_album3), albumToAlbumSummary(artist1_album2),
albumToAlbumSummary(artist1_album4), albumToAlbumSummary(artist1_album3),
albumToAlbumSummary(artist1_album5), albumToAlbumSummary(artist1_album4),
albumToAlbumSummary(artist1_album5),
albumToAlbumSummary(artist2_album1),
albumToAlbumSummary(artist2_album1),
albumToAlbumSummary(artist3_album1),
albumToAlbumSummary(artist3_album2), albumToAlbumSummary(artist3_album1),
], albumToAlbumSummary(artist3_album2),
total: totalAlbumCount, ],
total: totalAlbumCount,
});
}); });
}); });
describe("alphabeticalByName", () => {
it("should return all the albums for all the artists", async () => {
expect(
await musicLibrary.albums({
_index: 0,
_count: 100,
type: "alphabeticalByName",
})
).toEqual({
results:
_.sortBy(allAlbums, 'name').map(albumToAlbumSummary),
total: totalAlbumCount,
});
});
});
}); });
describe("fetching a page", () => { describe("fetching a page", () => {

View File

@@ -77,7 +77,9 @@ export class InMemoryMusicService implements MusicService {
switch (q.type) { switch (q.type) {
case "alphabeticalByArtist": case "alphabeticalByArtist":
return artist2Album; return artist2Album;
case "byGenre": case "alphabeticalByName":
return artist2Album.sort((a, b) => a.album.name.localeCompare(b.album.name));
case "byGenre":
return artist2Album.filter( return artist2Album.filter(
(it) => it.album.genre?.id === q.genre (it) => it.album.genre?.id === q.genre
); );

View File

@@ -245,7 +245,7 @@ describe("scenarios", () => {
...BLONDIE.albums, ...BLONDIE.albums,
...BOB_MARLEY.albums, ...BOB_MARLEY.albums,
...MADONNA.albums, ...MADONNA.albums,
].map((it) => it.name) ].map((it) => it.name).sort()
) )
); );
}); });

View File

@@ -1576,7 +1576,7 @@ describe("api", () => {
); );
expect(musicLibrary.albums).toHaveBeenCalledWith({ expect(musicLibrary.albums).toHaveBeenCalledWith({
type: "alphabeticalByArtist", type: "alphabeticalByName",
_index: paging.index, _index: paging.index,
_count: paging.count, _count: paging.count,
}); });
@@ -1622,7 +1622,7 @@ describe("api", () => {
); );
expect(musicLibrary.albums).toHaveBeenCalledWith({ expect(musicLibrary.albums).toHaveBeenCalledWith({
type: "alphabeticalByArtist", type: "alphabeticalByName",
_index: paging.index, _index: paging.index,
_count: paging.count, _count: paging.count,
}); });