mirror of
https://github.com/wkulhanek/bonob.git
synced 2025-12-21 17:33:29 +01:00
Album view sort by album name not artist name
This commit is contained in:
@@ -99,7 +99,7 @@ export const asResult = <T>([results, total]: [T[], number]) => ({
|
||||
|
||||
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 & {
|
||||
type: AlbumQueryType;
|
||||
|
||||
@@ -632,7 +632,7 @@ function bindSmapiSoapServiceToExpress(
|
||||
});
|
||||
case "albums": {
|
||||
return albums({
|
||||
type: "alphabeticalByArtist",
|
||||
type: "alphabeticalByName",
|
||||
...paging,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
HIP_HOP,
|
||||
SKA,
|
||||
} from "./builders";
|
||||
import _ from "underscore";
|
||||
|
||||
describe("InMemoryMusicService", () => {
|
||||
const service = new InMemoryMusicService();
|
||||
@@ -210,6 +211,7 @@ describe("InMemoryMusicService", () => {
|
||||
const artist3_album2 = anAlbum({ genre: POP });
|
||||
|
||||
const artist1 = anArtist({
|
||||
name: "artist1",
|
||||
albums: [
|
||||
artist1_album1,
|
||||
artist1_album2,
|
||||
@@ -218,8 +220,8 @@ describe("InMemoryMusicService", () => {
|
||||
artist1_album5,
|
||||
],
|
||||
});
|
||||
const artist2 = anArtist({ albums: [artist2_album1] });
|
||||
const artist3 = anArtist({ albums: [artist3_album1, artist3_album2] });
|
||||
const artist2 = anArtist({ name: "artist2", albums: [artist2_album1] });
|
||||
const artist3 = anArtist({ name: "artist3", albums: [artist3_album1, artist3_album2] });
|
||||
const artistWithNoAlbums = anArtist({ albums: [] });
|
||||
|
||||
const allAlbums = [artist1, artist2, artist3, artistWithNoAlbums].flatMap(
|
||||
@@ -265,6 +267,7 @@ describe("InMemoryMusicService", () => {
|
||||
describe("fetching multiple albums", () => {
|
||||
describe("with no filtering", () => {
|
||||
describe("fetching all on one page", () => {
|
||||
describe("alphabeticalByArtist", () => {
|
||||
it("should return all the albums for all the artists", async () => {
|
||||
expect(
|
||||
await musicLibrary.albums({
|
||||
@@ -290,6 +293,24 @@ describe("InMemoryMusicService", () => {
|
||||
});
|
||||
});
|
||||
|
||||
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", () => {
|
||||
it("should return only that page", async () => {
|
||||
expect(
|
||||
|
||||
@@ -77,6 +77,8 @@ export class InMemoryMusicService implements MusicService {
|
||||
switch (q.type) {
|
||||
case "alphabeticalByArtist":
|
||||
return artist2Album;
|
||||
case "alphabeticalByName":
|
||||
return artist2Album.sort((a, b) => a.album.name.localeCompare(b.album.name));
|
||||
case "byGenre":
|
||||
return artist2Album.filter(
|
||||
(it) => it.album.genre?.id === q.genre
|
||||
|
||||
@@ -245,7 +245,7 @@ describe("scenarios", () => {
|
||||
...BLONDIE.albums,
|
||||
...BOB_MARLEY.albums,
|
||||
...MADONNA.albums,
|
||||
].map((it) => it.name)
|
||||
].map((it) => it.name).sort()
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
@@ -1576,7 +1576,7 @@ describe("api", () => {
|
||||
);
|
||||
|
||||
expect(musicLibrary.albums).toHaveBeenCalledWith({
|
||||
type: "alphabeticalByArtist",
|
||||
type: "alphabeticalByName",
|
||||
_index: paging.index,
|
||||
_count: paging.count,
|
||||
});
|
||||
@@ -1622,7 +1622,7 @@ describe("api", () => {
|
||||
);
|
||||
|
||||
expect(musicLibrary.albums).toHaveBeenCalledWith({
|
||||
type: "alphabeticalByArtist",
|
||||
type: "alphabeticalByName",
|
||||
_index: paging.index,
|
||||
_count: paging.count,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user