Skip to content

Commit

Permalink
Allow saving external playlists locally - tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nukeop committed Aug 18, 2024
1 parent 3a568f4 commit 1315341
Show file tree
Hide file tree
Showing 4 changed files with 210 additions and 140 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,44 +24,61 @@ exports[`Deezer playlist adapter should display a Deezer playlist 1`] = `
<div
class="playlist_header"
>
<label
class="playlist_header_label"
>
Playlist
</label>
<div
class="playlist_name"
>
Playlist 1
</div>
<div
class="playlist_details"
class="playlist_header_external_source"
>
<span>
2 tracks
</span>
</div>
<div
class="playlist_buttons"
>
<button
class="ui pink circular button nuclear button play_button"
<div
class="playlist_header_external_source_inner"
>
<i
aria-hidden="true"
class="play icon"
class="external square icon"
/>
Play
</button>
<button
class="ui basic circular button nuclear button more_button"
data-testid="more-button"
Deezer
</div>
</div>
<div
class="playlist_header_inner"
>
<label
class="playlist_header_label"
>
<i
aria-hidden="true"
class="ellipsis horizontal icon"
/>
</button>
Playlist
</label>
<div
class="playlist_name"
>
Playlist 1
</div>
<div
class="playlist_details"
>
<span>
2 tracks
</span>
</div>
<div
class="playlist_buttons"
>
<button
class="ui pink circular button nuclear button play_button"
>
<i
aria-hidden="true"
class="play icon"
/>
Play
</button>
<button
class="ui basic circular button nuclear button more_button"
data-testid="more-button"
>
<i
aria-hidden="true"
class="ellipsis horizontal icon"
/>
</button>
</div>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,60 +24,64 @@ exports[`Playlist view container should display a playlist 1`] = `
<div
class="playlist_header"
>
<label
class="playlist_header_label"
>
Playlist
</label>
<div
class="playlist_name"
class="playlist_header_inner"
>
test playlist
<button
aria-label="Rename this playlist"
class="ui basic icon button nuclear button"
data-testid="rename-button"
<label
class="playlist_header_label"
>
<i
aria-hidden="true"
class="pencil icon"
/>
</button>
</div>
<div
class="playlist_details"
>
<span>
2 tracks
</span>
<span>
·
</span>
<span>
Last modified: 9/11/2001, 8:46:40 AM
</span>
</div>
<div
class="playlist_buttons"
>
<button
class="ui pink circular button nuclear button play_button"
Playlist
</label>
<div
class="playlist_name"
>
<i
aria-hidden="true"
class="play icon"
/>
Play
</button>
<button
class="ui basic circular button nuclear button more_button"
data-testid="more-button"
test playlist
<button
aria-label="Rename this playlist"
class="ui basic icon button nuclear button"
data-testid="rename-button"
>
<i
aria-hidden="true"
class="pencil icon"
/>
</button>
</div>
<div
class="playlist_details"
>
<i
aria-hidden="true"
class="ellipsis horizontal icon"
/>
</button>
<span>
2 tracks
</span>
<span>
·
</span>
<span>
Last modified: 9/11/2001, 8:46:40 AM
</span>
</div>
<div
class="playlist_buttons"
>
<button
class="ui pink circular button nuclear button play_button"
>
<i
aria-hidden="true"
class="play icon"
/>
Play
</button>
<button
class="ui basic circular button nuclear button more_button"
data-testid="more-button"
>
<i
aria-hidden="true"
class="ellipsis horizontal icon"
/>
</button>
</div>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Spotify } from '@nuclear/core/src/rest';

import { mountedComponentFactory, setupI18Next } from '../../../test/testUtils';
import { buildStoreState } from '../../../test/storeBuilders';
import userEvent from '@testing-library/user-event';

jest.mock('@nuclear/core/src/rest/Spotify');

Expand All @@ -27,41 +28,42 @@ describe('Spotfiy playlist adapter', () => {
});

it('should display a Spotify playlist', async () => {
mockSpotifyClient.getPlaylist = jest.fn().mockResolvedValue({
id: '1',
name: 'Test Spotify playlist',
tracks: [{
id: '1',
name: 'Test track',
album: {
id: '1',
name: 'Test album',
images: [
{ width: 300, height: 300, url: 'thumb.jpg' },
{ width: 600, height: 600, url: 'cover.jpg' },
{ width: 450, height: 450, url: 'another.jpg' }
]
},
artists: [{ name: 'Test artist' }],
duration_ms: 1000 * 120
}, {
id: '2',
name: 'Another test track',
album: {
id: '2',
name: 'Another test album',
images: []
},
artists: [{ name: 'Another test artist' }],
duration_ms: 1000 * 180
}]
});
mockSpotifyClient.getPlaylist = jest.fn().mockResolvedValue(getMockedPlaylist());
const { component } = mountComponent();
await component.findByTestId('playlist-view');
expect(component.asFragment()).toMatchSnapshot();
expect(mockSpotifyClient.getPlaylist).toHaveBeenCalledWith('1');
});

it('should save the external playlist locally', async () => {
mockSpotifyClient.getPlaylist = jest.fn().mockResolvedValue(getMockedPlaylist());
const { component, store } = mountComponent();
await component.findByTestId('playlist-view');
userEvent.click(component.getByTestId('more-button'));
userEvent.click(component.getByText('Save locally'));

const state = store.getState();
expect(state.playlists.localPlaylists.data).toHaveLength(1);
expect(state.playlists.localPlaylists.data[0].name).toEqual(getMockedPlaylist().name);
expect(state.playlists.localPlaylists.data[0].tracks).toEqual([{
uuid: '1',
name: 'Test track',
album: 'Test album',
artist: 'Test artist',
duration: 120,
thumbnail: 'thumb.jpg',
stream: null
}, {
uuid: '2',
name: 'Another test track',
album: 'Another test album',
artist: 'Another test artist',
duration: 180,
thumbnail: undefined,
stream: null
}]);
});

const mountComponent = mountedComponentFactory(
['/playlists/spotify/1'],
buildStoreState()
Expand All @@ -71,3 +73,33 @@ describe('Spotfiy playlist adapter', () => {
.build()
);
});

const getMockedPlaylist = () => ({
id: '1',
name: 'Test Spotify playlist',
tracks: [{
id: '1',
name: 'Test track',
album: {
id: '1',
name: 'Test album',
images: [
{ width: 300, height: 300, url: 'thumb.jpg' },
{ width: 600, height: 600, url: 'cover.jpg' },
{ width: 450, height: 450, url: 'another.jpg' }
]
},
artists: [{ name: 'Test artist' }],
duration_ms: 1000 * 120
}, {
id: '2',
name: 'Another test track',
album: {
id: '2',
name: 'Another test album',
images: []
},
artists: [{ name: 'Another test artist' }],
duration_ms: 1000 * 180
}]
});
Loading

0 comments on commit 1315341

Please sign in to comment.