- Sponsor
-
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.
Downloads tests and improvements (#1116)
* Convert components to typescript and create a snapshot test * More tests for downloads container
- v0.6.42
- v0.6.41
- v0.6.40
- v0.6.39
- v0.6.38
- v0.6.37
- v0.6.36
- v0.6.35
- v0.6.34
- v0.6.33
- v0.6.32
- v0.6.31
- v0.6.30
- v0.6.29
- v0.6.28
- v0.6.27
- v0.6.26
- v0.6.25
- v0.6.24
- v0.6.23
- v0.6.22
- v0.6.21
- v0.6.20
- v0.6.19
- v0.6.18
- nightly
- latest
- fd06a3
- f5ec0d
- f2f59d
- eac584
- e94388
- e8fcb6
- e8d6cc
- c9cb81
- bc8b7b
- b6e5b2
- b2a752
- ${GITHUB_SHA}
- 52769a
- 9545bf
- 8988ba
- 549e4d
- 0437ae
- 268b26
- 95cfe0
- 58dfc7
- 27f5b2a
- 23bcaf
- 15c5eb
- 9f77fc
- 3f9007
- 2f1ec0
- 2ec701
- 2dd909
- 2c7b60
- 2a872a
Showing
16 changed files
with
643 additions
and
248 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
67 changes: 0 additions & 67 deletions
67
packages/app/app/components/Downloads/DownloadsHeader/index.js
This file was deleted.
Oops, something went wrong.
57 changes: 57 additions & 0 deletions
57
packages/app/app/components/Downloads/DownloadsHeader/index.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,57 @@ | ||
import React, { useCallback } from 'react'; | ||
import _ from 'lodash'; | ||
import { | ||
Button, | ||
Icon, | ||
Segment | ||
} from 'semantic-ui-react'; | ||
import { remote } from 'electron'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
import { setStringOption } from '../../../actions/settings'; | ||
import styles from './styles.scss'; | ||
|
||
type DownloadsHeaderProps = { | ||
directory: string; | ||
setStringOption: typeof setStringOption; | ||
}; | ||
|
||
const DownloadsHeader: React.FC<DownloadsHeaderProps> = ({ | ||
directory, | ||
setStringOption | ||
}) => { | ||
const { t } = useTranslation('settings'); | ||
const setDirectory = useCallback(async () => { | ||
const dialogResult = await remote.dialog.showOpenDialog({ | ||
properties: ['openDirectory'] | ||
}); | ||
if (!dialogResult.canceled && !_.isEmpty(dialogResult.filePaths)) { | ||
setStringOption( | ||
'downloads.dir', | ||
_.head(dialogResult.filePaths) | ||
); | ||
} | ||
}, [setStringOption]); | ||
|
||
return ( | ||
<Segment className={styles.downloads_header}> | ||
<span className={styles.label}> | ||
{t('saving-in')} | ||
<span className={styles.directory}> | ||
{_.isEmpty(directory) ? remote.app.getPath('downloads') : directory} | ||
</span> | ||
</span> | ||
<Button | ||
icon | ||
inverted | ||
labelPosition='left' | ||
onClick={setDirectory} | ||
> | ||
<Icon name='folder open' /> | ||
{t('downloads-dir-button')} | ||
</Button> | ||
</Segment> | ||
); | ||
}; | ||
|
||
export default DownloadsHeader; |
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
83 changes: 83 additions & 0 deletions
83
packages/app/app/containers/DownloadsContainer/DownloadsContainer.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,83 @@ | ||
import { store as electronStore } from '@nuclear/core'; | ||
import { waitFor } from '@testing-library/dom'; | ||
import { buildStoreState } from '../../../test/storeBuilders'; | ||
import { mountedComponentFactory, setupI18Next } from '../../../test/testUtils'; | ||
|
||
const initialStoreState = | ||
buildStoreState() | ||
.withDownloads() | ||
.withPlugins() | ||
.withConnectivity() | ||
.build(); | ||
|
||
describe('Downloads container', () => { | ||
beforeAll(() => { | ||
setupI18Next(); | ||
}); | ||
|
||
beforeEach(() => { | ||
electronStore.set( | ||
'downloads', | ||
initialStoreState.downloads | ||
); | ||
}); | ||
|
||
it('should display downloads', () => { | ||
const { component } = mountComponent(); | ||
expect(component.asFragment()).toMatchSnapshot(); | ||
}); | ||
|
||
it('should clear finished downloads', async () => { | ||
const { component } = mountComponent(); | ||
await waitFor(() => component.getByText(/clear finished tracks/i).click()); | ||
|
||
expect(component.queryByText(/test artist 1 - finished track/i)).toBeNull(); | ||
}); | ||
|
||
it('should remove a track', async () => { | ||
const { component } = mountComponent(); | ||
await waitFor(() => component.getAllByTestId(/remove-download/i)[0].click()); | ||
|
||
expect(component.queryByText(/test artist 1 - finished track/i)).toBeNull(); | ||
}); | ||
|
||
it('should pause a download in progress', async () => { | ||
const { component, store } = mountComponent(); | ||
await waitFor(() => component.getAllByTestId(/download-action/i)[3].click()); | ||
|
||
const state = store.getState(); | ||
expect(state.downloads[3].status).toBe('Paused'); | ||
}); | ||
|
||
it('should resume a paused download', async () => { | ||
const { component, store } = mountComponent(); | ||
await waitFor(() => component.getAllByTestId(/download-action/i)[2].click()); | ||
|
||
const state = store.getState(); | ||
expect(state.downloads[2].status).toBe('Waiting'); | ||
}); | ||
|
||
it('should retry a download with error', async () => { | ||
const { component, store } = mountComponent(); | ||
await waitFor(() => component.getAllByTestId(/download-action/i)[1].click()); | ||
|
||
const state = store.getState(); | ||
expect(state.downloads[1].status).toBe('Waiting'); | ||
}); | ||
|
||
it('should set downloads dir', async () => { | ||
const { component } = mountComponent(); | ||
await waitFor(() => component.getByText(/choose a directory.../i).click()); | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const remote = require('electron').remote; | ||
expect(remote.dialog.showOpenDialog).toHaveBeenCalledWith({ | ||
properties: ['openDirectory'] | ||
}); | ||
}); | ||
|
||
const mountComponent = mountedComponentFactory( | ||
['/downloads'], | ||
initialStoreState | ||
); | ||
}); |
316 changes: 316 additions & 0 deletions
316
...ages/app/app/containers/DownloadsContainer/__snapshots__/DownloadsContainer.test.tsx.snap
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,316 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Downloads container should display downloads 1`] = ` | ||
<DocumentFragment> | ||
<div | ||
class="main_layout_container" | ||
> | ||
<div | ||
class="downloads_container" | ||
> | ||
<div | ||
class="ui segment downloads_header" | ||
> | ||
<span | ||
class="label" | ||
> | ||
Saving in: | ||
<span | ||
class="directory" | ||
/> | ||
</span> | ||
<button | ||
class="ui icon inverted left labeled button" | ||
> | ||
<i | ||
aria-hidden="true" | ||
class="folder open icon" | ||
/> | ||
Choose a directory... | ||
</button> | ||
</div> | ||
<div | ||
class="header_container" | ||
> | ||
Downloads | ||
</div> | ||
<div | ||
class="ui inverted segment" | ||
> | ||
<button | ||
class="ui primary button" | ||
> | ||
<i | ||
aria-hidden="true" | ||
class="trash icon" | ||
/> | ||
Clear finished tracks | ||
</button> | ||
<table | ||
class="ui inverted table downloads_list" | ||
> | ||
<thead | ||
class="" | ||
> | ||
<tr | ||
class="" | ||
> | ||
<th | ||
class="" | ||
> | ||
Status | ||
</th> | ||
<th | ||
class="" | ||
> | ||
Name | ||
<i | ||
aria-hidden="true" | ||
class="caret up icon" | ||
/> | ||
</th> | ||
<th | ||
class="" | ||
> | ||
Completion | ||
</th> | ||
<th | ||
class="" | ||
/> | ||
</tr> | ||
</thead> | ||
<tbody | ||
class="" | ||
> | ||
<tr | ||
class="downloads_item" | ||
> | ||
<td | ||
class="" | ||
> | ||
<i | ||
aria-hidden="true" | ||
class="green checkmark icon" | ||
/> | ||
Finished | ||
</td> | ||
<td | ||
class="" | ||
> | ||
test artist 1 - finished track | ||
</td> | ||
<td | ||
class="" | ||
> | ||
100% | ||
</td> | ||
<td | ||
class="item_buttons" | ||
> | ||
<a | ||
data-testid="download-action" | ||
href="#" | ||
> | ||
<i | ||
aria-hidden="true" | ||
class="redo fitted icon" | ||
/> | ||
</a> | ||
<a | ||
data-testid="remove-download" | ||
href="#" | ||
> | ||
<i | ||
aria-hidden="true" | ||
class="times fitted icon" | ||
/> | ||
</a> | ||
</td> | ||
</tr> | ||
<tr | ||
class="downloads_item" | ||
> | ||
<td | ||
class="" | ||
> | ||
<i | ||
aria-hidden="true" | ||
class="red times icon" | ||
/> | ||
Error | ||
</td> | ||
<td | ||
class="" | ||
> | ||
test artist 2 - track with errorx | ||
</td> | ||
<td | ||
class="" | ||
> | ||
10% | ||
</td> | ||
<td | ||
class="item_buttons" | ||
> | ||
<a | ||
data-testid="download-action" | ||
href="#" | ||
> | ||
<i | ||
aria-hidden="true" | ||
class="redo fitted icon" | ||
/> | ||
</a> | ||
<a | ||
data-testid="remove-download" | ||
href="#" | ||
> | ||
<i | ||
aria-hidden="true" | ||
class="times fitted icon" | ||
/> | ||
</a> | ||
</td> | ||
</tr> | ||
<tr | ||
class="downloads_item" | ||
> | ||
<td | ||
class="" | ||
> | ||
<i | ||
aria-hidden="true" | ||
class="pause circle icon" | ||
/> | ||
Paused | ||
</td> | ||
<td | ||
class="" | ||
> | ||
test artist 3 - paused track | ||
</td> | ||
<td | ||
class="" | ||
> | ||
30% | ||
</td> | ||
<td | ||
class="item_buttons" | ||
> | ||
<a | ||
data-testid="download-action" | ||
href="#" | ||
> | ||
<i | ||
aria-hidden="true" | ||
class="play fitted icon" | ||
/> | ||
</a> | ||
<a | ||
data-testid="remove-download" | ||
href="#" | ||
> | ||
<i | ||
aria-hidden="true" | ||
class="times fitted icon" | ||
/> | ||
</a> | ||
</td> | ||
</tr> | ||
<tr | ||
class="downloads_item" | ||
> | ||
<td | ||
class="" | ||
> | ||
<i | ||
aria-hidden="true" | ||
class="cloud download icon" | ||
/> | ||
Started | ||
</td> | ||
<td | ||
class="" | ||
> | ||
test artist 4 - started track | ||
</td> | ||
<td | ||
class="" | ||
> | ||
50% | ||
</td> | ||
<td | ||
class="item_buttons" | ||
> | ||
<a | ||
data-testid="download-action" | ||
href="#" | ||
> | ||
<i | ||
aria-hidden="true" | ||
class="pause fitted icon" | ||
/> | ||
</a> | ||
<a | ||
data-testid="remove-download" | ||
href="#" | ||
> | ||
<i | ||
aria-hidden="true" | ||
class="times fitted icon" | ||
/> | ||
</a> | ||
</td> | ||
</tr> | ||
<tr | ||
class="downloads_item" | ||
> | ||
<td | ||
class="" | ||
> | ||
<i | ||
aria-hidden="true" | ||
class="hourglass start icon" | ||
/> | ||
Waiting | ||
</td> | ||
<td | ||
class="" | ||
> | ||
test artist 5 - waiting track | ||
</td> | ||
<td | ||
class="" | ||
> | ||
0% | ||
</td> | ||
<td | ||
class="item_buttons" | ||
> | ||
<a | ||
data-testid="download-action" | ||
href="#" | ||
> | ||
<i | ||
aria-hidden="true" | ||
class="pause fitted icon" | ||
/> | ||
</a> | ||
<a | ||
data-testid="remove-download" | ||
href="#" | ||
> | ||
<i | ||
aria-hidden="true" | ||
class="times fitted icon" | ||
/> | ||
</a> | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
</div> | ||
</div> | ||
</div> | ||
</DocumentFragment> | ||
`; |
This file was deleted.
Oops, something went wrong.
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,33 @@ | ||
import React, { useEffect } from 'react'; | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
import _ from 'lodash'; | ||
|
||
import * as DownloadActions from '../../actions/downloads'; | ||
import * as SettingsActions from '../../actions/settings'; | ||
import { downloadsSelector } from '../../selectors/downloads'; | ||
import { settingsSelector } from '../../selectors/settings'; | ||
import Downloads from '../../components/Downloads'; | ||
|
||
const DownloadsContainer: React.FC = () => { | ||
const dispatch = useDispatch(); | ||
const downloads = useSelector(downloadsSelector); | ||
const settings = useSelector(settingsSelector); | ||
|
||
useEffect(() => { | ||
dispatch(DownloadActions.readDownloads()); | ||
}, [dispatch]); | ||
|
||
return ( | ||
<Downloads | ||
downloads={downloads} | ||
downloadsDir={_.get(settings, 'downloads.dir')} | ||
clearFinishedTracks={() => dispatch(DownloadActions.clearFinishedDownloads())} | ||
pauseDownload={(uuid: string) => dispatch(DownloadActions.onDownloadPause(uuid))} | ||
resumeDownload={(uuid: string) => dispatch(DownloadActions.onDownloadResume(uuid))} | ||
removeDownload={(uuid: string) => dispatch(DownloadActions.onDownloadRemoved(uuid))} | ||
setStringOption={(option, state, fromMain) => dispatch(SettingsActions.setStringOption(option, state, fromMain))} | ||
/> | ||
); | ||
}; | ||
|
||
export default DownloadsContainer; |
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,3 @@ | ||
import { RootState } from '../reducers'; | ||
|
||
export const downloadsSelector = (s: RootState) => s.downloads; |
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