diff --git a/app/browser/reducers/downloadsReducer.js b/app/browser/reducers/downloadsReducer.js index cca41ad8b00..08459427f0f 100644 --- a/app/browser/reducers/downloadsReducer.js +++ b/app/browser/reducers/downloadsReducer.js @@ -50,11 +50,9 @@ const downloadsReducer = (state, action) => { break case PAUSE: pauseDownload(action.downloadId) - state = state.setIn(['downloads', action.downloadId, 'state'], downloadStates.PAUSED) break case RESUME: resumeDownload(action.downloadId) - state = state.setIn(['downloads', action.downloadId, 'state'], downloadStates.IN_PROGRESS) break } break diff --git a/app/filtering.js b/app/filtering.js index 977815d7b7d..ae5053e1b9e 100644 --- a/app/filtering.js +++ b/app/filtering.js @@ -517,11 +517,7 @@ function registerForDownloadListener (session) { win.webContents.send(messages.SHOW_DOWNLOADS_TOOLBAR) } item.on('updated', function () { - let state = downloadStates.IN_PROGRESS - const downloadItem = appStore.getState().getIn(['downloads', downloadId]) - if (downloadItem && downloadItem.get('state') === downloadStates.PAUSED) { - state = downloadStates.PAUSED - } + const state = item.isPaused() ? downloadStates.PAUSED : downloadStates.IN_PROGRESS updateDownloadState(downloadId, item, state) }) item.on('done', function (e, state) { diff --git a/test/lib/selectors.js b/test/lib/selectors.js index 500ee024835..c4b8e9f1d85 100644 --- a/test/lib/selectors.js +++ b/test/lib/selectors.js @@ -114,5 +114,16 @@ module.exports = { msgBoxSuppress: '[data-test-id^="msgBoxTab_"] .switchMiddle', msgBoxSuppressTrue: '[data-test-id^="msgBoxTab_"] .switchMiddle .switchBackground.switchedOn', msgBoxMessage: '[data-test-id="msgBoxMessage"]', - msgBoxTitle: '[data-test-id="msgBoxTitle"]' + msgBoxTitle: '[data-test-id="msgBoxTitle"]', + + // download + downloadBar: '.downloadsBar', + downloadItem: '.downloadItem', + downloadPause: '[data-test-id="pauseButton"]', + downloadResume: '[data-test-id="resumeButton"]', + downloadCancel: '[data-test-id="cancelButton"]', + downloadReDownload: '[data-test-id="redownloadButton"]', + downloadDelete: '[data-test-id="deleteButton"]', + downloadDeleteConfirm: '[data-test-id="confirmDeleteButton"]', + downloadRemoveFromList: '[data-test-id="downloadRemoveFromList"]' } diff --git a/test/misc-components/downloadItemTest.js b/test/misc-components/downloadItemTest.js new file mode 100644 index 00000000000..8bfefb08ec6 --- /dev/null +++ b/test/misc-components/downloadItemTest.js @@ -0,0 +1,98 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ +/* global describe, it, before */ + +const Brave = require('../lib/brave') +const { + urlInput, + downloadBar, + downloadItem, + downloadPause, + downloadResume, + downloadCancel, + downloadReDownload, + downloadRemoveFromList, + downloadDelete, + downloadDeleteConfirm +} = require('../lib/selectors') + +function * setup (client) { + yield client + .waitForUrl(Brave.newTabUrl) + .waitForBrowserWindow() + .waitForVisible(urlInput) +} + +describe('downloadItem test', function () { + Brave.beforeAll(this) + before(function * () { + this.downloadSite = 'http://releases.ubuntu.com/16.04.2/ubuntu-16.04.2-desktop-amd64.iso' + yield setup(this.app.client) + + yield this.app.client + .waitForUrl(Brave.newTabUrl) + .url(this.downloadSite) + }) + + it('check if download bar is shown', function * () { + yield this.app.client + .windowByUrl(Brave.browserWindowUrl) + .waitForElementCount(downloadBar, 1) + }) + + it('check if you can pause download', function * () { + yield this.app.client + .moveToObject(downloadItem) + .waitForElementCount(downloadPause, 1) + .click(downloadPause) + .waitForElementCount(downloadResume, 1) + }) + + it('check if you can resume download', function * () { + yield this.app.client + .waitForElementCount(downloadResume, 1) + .click(downloadResume) + .waitForElementCount(downloadPause, 1) + }) + + it('check if you can cancel download', function * () { + yield this.app.client + .waitForElementCount(downloadPause, 1) + .click(downloadCancel) + .waitForElementCount(downloadReDownload, 1) + }) + + it('check if you can re-download', function * () { + yield this.app.client + .waitForElementCount(downloadReDownload, 1) + .click(downloadReDownload) + .waitForElementCount(downloadPause, 1) + }) + + it('check if you can remove item from the list', function * () { + yield this.app.client + .moveToObject(downloadItem) + .waitForElementCount(downloadPause, 1) + .click(downloadCancel) + .waitForElementCount(downloadReDownload, 1) + .click(downloadRemoveFromList) + .waitForElementCount(downloadBar, 0) + }) + + it('check if you can delete downloaded item', function * () { + yield this.app.client + .tabByIndex(0) + .url(this.downloadSite) + .windowByUrl(Brave.browserWindowUrl) + .waitForElementCount(downloadBar, 1) + .moveToObject(downloadItem) + .waitForElementCount(downloadPause, 1) + .click(downloadCancel) + .waitForElementCount(downloadReDownload, 1) + .click(downloadDelete) + .waitForElementCount(downloadDeleteConfirm, 1) + .click(downloadDeleteConfirm) + .waitForElementCount(downloadBar, 0) + }) +})