-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Save track id from stream provider (#1048)
* save track id from stream provider when favoriting * add youtube provider get track by id * add getStreamForId for bandcamp + audius * update other stream provider * add unit test * playqueue test for favorite * add favorite track container test
- Loading branch information
1 parent
5891b8b
commit 00c7260
Showing
30 changed files
with
974 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
packages/app/app/containers/FavoritesContainer/FavoritesContainer.tracks.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
|
||
import React from 'react'; | ||
import { render, waitFor } from '@testing-library/react'; | ||
import { createMemoryHistory } from 'history'; | ||
import _ from 'lodash'; | ||
|
||
import { buildStoreState } from '../../../test/storeBuilders'; | ||
import { AnyProps, configureMockStore, setupI18Next, TestRouterProvider, TestStoreProvider } from '../../../test/testUtils'; | ||
import MainContentContainer from '../MainContentContainer'; | ||
|
||
const updateStore = (key: string, value: object) => { | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const store = require('@nuclear/core').store; | ||
store.set(key, value); | ||
}; | ||
|
||
describe('Track view container', () => { | ||
beforeAll(() => { | ||
setupI18Next(); | ||
}); | ||
|
||
beforeEach(() => { | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const { store } = require('@nuclear/core'); | ||
store.clear(); | ||
}); | ||
|
||
it('should display favorite tracks', () => { | ||
const favorites = buildStoreState() | ||
.withFavorites() | ||
.build() | ||
.favorites; | ||
updateStore('favorites', favorites); | ||
const { component } = mountComponent(); | ||
expect(component.asFragment()).toMatchSnapshot(); | ||
}); | ||
|
||
it('should display empty state', () => { | ||
const { component } = mountComponent(); | ||
expect(component.asFragment()).toMatchSnapshot(); | ||
}); | ||
|
||
it('should show popup when click on track', async () => { | ||
const favorites = buildStoreState() | ||
.withFavorites() | ||
.build() | ||
.favorites; | ||
updateStore('favorites', favorites); | ||
const { component } = mountComponent(); | ||
|
||
await waitFor(() => component.getByTestId('fav-track-uuid1').click()); | ||
expect(component.asFragment()).toMatchSnapshot(); | ||
}); | ||
|
||
it('should call provider.search when play track with no stream', async () => { | ||
const favorites = buildStoreState() | ||
.withFavorites() | ||
.build() | ||
.favorites; | ||
updateStore('favorites', favorites); | ||
|
||
const { component, store } = mountComponent(); | ||
const state = store.getState(); | ||
const selectedStreamProvider = _.find( | ||
state.plugin.plugins.streamProviders, | ||
{ sourceName: state.plugin.selected.streamProviders }); | ||
|
||
await waitFor(() => component.getByTestId('fav-track-uuid2').click()); | ||
await waitFor(() => component.getByTestId('track-popup-add-queue').click()); | ||
|
||
expect(selectedStreamProvider.search).toBeCalled(); | ||
expect(selectedStreamProvider.getStreamForId).not.toBeCalled(); | ||
}); | ||
|
||
it('should call provider.getStreamForId when play track with known stream', async () => { | ||
const favorites = buildStoreState() | ||
.withFavorites() | ||
.build() | ||
.favorites; | ||
updateStore('favorites', favorites); | ||
|
||
const { component, store } = mountComponent(); | ||
const state = store.getState(); | ||
const selectedStreamProvider = _.find( | ||
state.plugin.plugins.streamProviders, | ||
{ sourceName: state.plugin.selected.streamProviders }); | ||
|
||
await waitFor(() => component.getByTestId('fav-track-uuid1').click()); | ||
await waitFor(() => component.getByTestId('track-popup-add-queue').click()); | ||
|
||
expect(selectedStreamProvider.search).not.toBeCalled(); | ||
expect(selectedStreamProvider.getStreamForId).toBeCalled(); | ||
}); | ||
|
||
const mountComponent = (initialStore?: AnyProps) => { | ||
const initialState = initialStore || | ||
buildStoreState() | ||
.withPlugins() | ||
.withConnectivity() | ||
.build(); | ||
|
||
const history = createMemoryHistory({ | ||
initialEntries: ['/favorites/tracks'] | ||
}); | ||
const store = configureMockStore(initialState); | ||
const component = render( | ||
<TestRouterProvider | ||
history={history} | ||
> | ||
<TestStoreProvider | ||
store={store} | ||
> | ||
<MainContentContainer /> | ||
</TestStoreProvider> | ||
</TestRouterProvider >, {container: document.body} | ||
); | ||
return { component, history, store }; | ||
}; | ||
}); |
Oops, something went wrong.