Skip to content

Commit

Permalink
Artist albums sorting test
Browse files Browse the repository at this point in the history
  • Loading branch information
nukeop committed Aug 15, 2024
1 parent c2cea01 commit 2312496
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -245,57 +245,17 @@ describe('Artist view container', () => {

it('should filter artist\'s albums', async () => {
const protoState = buildStoreState()
.withPlugins().build();
.withArtistDetails()
.withPlugins()
.build();

const mockFetchArtistAlbums = jest.fn().mockResolvedValue([
{
id: 'test-album-1',
title: ' Test album 1',
artist: 'test artist 1',
genres: ['genre 1', 'genre 2'],
images: ['image 1'],
thumb: 'image 1',
coverImage: 'image 1',
tracklist: [
{
uuid: 'track-1',
artist: 'test artist 1',
title: 'test track 1',
duration: 10
}
],
year: '2019',
source: SearchResultsSource.Discogs
},
{
id: 'test-album-2',
title: ' Test album 2',
artist: 'test artist 2',
genres: ['genre 2', 'genre 3'],
images: ['image 2'],
thumb: 'image 2',
coverImage: 'image 2',
tracklist: [
{
uuid: 'track-2',
artist: 'test artist 2',
title: 'test track 2',
duration: 40
}
],
year: '2021',
source: SearchResultsSource.Discogs
}
]);
const mockFetchArtistAlbums = jest.fn().mockResolvedValue(
protoState.search.artistDetails['test-artist-id'].releases
);

const { component, store } = mountComponent(
buildStoreState()
.withArtistDetails()
.withPlaylists([{
id: 'test-playlist-id',
name: 'test playlist',
tracks: []
}])
.withPlugins({
metaProviders: [{
...protoState.plugin.plugins.metaProviders[0],
Expand All @@ -306,14 +266,56 @@ describe('Artist view container', () => {
.build()
);

await waitFor(() => expect(store.getState().search.artistDetails['test-artist-id'].releases).toHaveLength(2));
await waitFor(() => expect(store.getState().search.artistDetails['test-artist-id'].releases).toHaveLength(3));

await userEvent.type(component.getByPlaceholderText('Filter...'), 'album 1');
userEvent.type(await component.findByPlaceholderText('Filter...'), 'album 1');
const albumCells = await component.findAllByTestId('album-card');
expect(albumCells).toHaveLength(1);
expect(albumCells[0]).toHaveTextContent('Test album 1');
});

it.each([{
name: 'release date',
text: 'Sort by release date',
order: ['First test album', 'Test album 2', 'Test album 1']
}, {
name: 'A-Z',
text: 'Sort A-Z',
order: ['First test album', 'Test album 1', 'Test album 2']
}])('should sort artist\'s albums by $name', async ({ text, order }) => {
const protoState = buildStoreState()
.withArtistDetails()
.withPlugins()
.build();

const mockFetchArtistAlbums = jest.fn().mockResolvedValue(
protoState.search.artistDetails['test-artist-id'].releases
);

const { component, store } = mountComponent(
buildStoreState()
.withArtistDetails()
.withPlugins({
metaProviders: [{
...protoState.plugin.plugins.metaProviders[0],
fetchArtistAlbums: mockFetchArtistAlbums
}]
})
.withConnectivity()
.build()
);

await waitFor(() => expect(store.getState().search.artistDetails['test-artist-id'].releases).toHaveLength(3));

userEvent.click(await component.findByRole('listbox'));
const options = await component.findAllByRole('option');
const targetOption = options.find(el => el.textContent === text);
userEvent.click(targetOption);

const albumCells = await component.findAllByTestId('album-card');
await waitFor(() => expect(albumCells.map(cell => cell.textContent)).toEqual(order));
});


const mountComponent = (initialStore?: AnyProps) => {
const initialState = initialStore ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ exports[`Artist view container should display an artist 1`] = `
<span
class="text"
>
Sort by A-Z
Sort A-Z
</span>
</div>
</div>
Expand Down
29 changes: 24 additions & 5 deletions packages/app/test/storeBuilders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ export const buildStoreState = () => {
releases: [
{
id: 'test-album-1',
title: ' Test album 1',
artist: 'test artist 1',
title: 'Test album 1',
artist: 'test artist',
genres: ['genre 1', 'genre 2'],
images: ['image 1'],
thumb: 'image 1',
Expand All @@ -177,12 +177,12 @@ export const buildStoreState = () => {
duration: 10
}
],
year: '2019',
year: '2020',
source: SearchResultsSource.Discogs
},
{
id: 'test-album-2',
title: ' Test album 2',
title: 'Test album 2',
artist: 'test artist 2',
genres: ['genre 2', 'genre 3'],
images: ['image 2'],
Expand All @@ -196,7 +196,26 @@ export const buildStoreState = () => {
duration: 40
}
],
year: '2021',
year: '2019',
source: SearchResultsSource.Discogs
},
{
id: 'test-album-3',
title: 'First test album',
artist: 'test artist',
genres: ['genre 4', 'genre 5'],
images: ['image 3'],
thumb: 'image 3',
coverImage: 'image 3',
tracklist: [
{
uuid: 'track-3',
artist: 'test artist',
title: 'test track 3',
duration: 40
}
],
year: '2010',
source: SearchResultsSource.Discogs
}
],
Expand Down
2 changes: 1 addition & 1 deletion packages/i18n/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"artist-albums": {
"header": "Albums",
"sort-by-release-date": "Sort by release date",
"sort-by-az": "Sort by A-Z",
"sort-by-az": "Sort A-Z",
"sort-by-most-played": "Sort by most played",
"filter-placeholder": "Filter..."
}
Expand Down

0 comments on commit 2312496

Please sign in to comment.