diff --git a/src/core/installAddon.js b/src/core/installAddon.js index 0086a27eb16..3e561bbc755 100644 --- a/src/core/installAddon.js +++ b/src/core/installAddon.js @@ -23,6 +23,7 @@ import { INSTALL_ERROR, INSTALL_CANCELLED, INSTALL_FAILED, + INSTALLING, SET_ENABLE_NOT_AVAILABLE, SHOW_INFO, START_DOWNLOAD, @@ -67,6 +68,8 @@ export function makeProgressHandler(dispatch, guid) { type: DOWNLOAD_PROGRESS, payload: { guid, downloadProgress }, }); + } else if (event.type === 'onDownloadEnded') { + dispatch(setInstallState({ guid, status: INSTALLING })); } else if (event.type === 'onDownloadFailed') { dispatch({ type: INSTALL_ERROR, diff --git a/tests/unit/core/TestInstallAddon.js b/tests/unit/core/TestInstallAddon.js index 7a2c7715606..6eabc5d81b0 100644 --- a/tests/unit/core/TestInstallAddon.js +++ b/tests/unit/core/TestInstallAddon.js @@ -21,6 +21,7 @@ import { INSTALL_CANCELLED, INSTALL_FAILED, INSTALLED, + INSTALLING, SET_ENABLE_NOT_AVAILABLE, SHOW_INFO, START_DOWNLOAD, @@ -441,10 +442,10 @@ describe('withInstallHelpers inner functions', () => { const guid = 'foo@addon'; const handler = makeProgressHandler(dispatch, guid); handler({ state: 'STATE_DOWNLOADING', progress: 300, maxProgress: 990 }); - expect(dispatch.calledWith({ + sinon.assert.calledWith(dispatch, { type: DOWNLOAD_PROGRESS, payload: { downloadProgress: 30, guid }, - })).toBeTruthy(); + }); }); it('sets status to error on onDownloadFailed', () => { @@ -452,10 +453,20 @@ describe('withInstallHelpers inner functions', () => { const guid = '{my-addon}'; const handler = makeProgressHandler(dispatch, guid); handler({ state: 'STATE_SOMETHING' }, { type: 'onDownloadFailed' }); - expect(dispatch.calledWith({ + sinon.assert.calledWith(dispatch, { type: 'INSTALL_ERROR', payload: { guid, error: DOWNLOAD_FAILED }, - })).toBeTruthy(); + }); + }); + + it('sets status to installing onDownloadEnded', () => { + const dispatch = sinon.spy(); + const guid = '{my-addon}'; + const handler = makeProgressHandler(dispatch, guid); + handler({ state: 'STATE_SOMETHING' }, { type: 'onDownloadEnded' }); + sinon.assert.calledWith(dispatch, setInstallState({ + guid, status: INSTALLING, + })); }); it('resets status to uninstalled on onInstallCancelled', () => { @@ -463,7 +474,7 @@ describe('withInstallHelpers inner functions', () => { const guid = '{my-addon}'; const handler = makeProgressHandler(dispatch, guid); handler({ state: 'STATE_SOMETHING' }, { type: 'onInstallCancelled' }); - expect(dispatch.firstCall.args[0]).toEqual({ + sinon.assert.calledWith(dispatch, { type: INSTALL_CANCELLED, payload: { guid }, }); @@ -474,7 +485,7 @@ describe('withInstallHelpers inner functions', () => { const guid = '{my-addon}'; const handler = makeProgressHandler(dispatch, guid); handler({ state: 'STATE_SOMETHING' }, { type: 'onInstallFailed' }); - expect(dispatch.firstCall.args[0]).toEqual({ + sinon.assert.calledWith(dispatch, { type: 'INSTALL_ERROR', payload: { guid, error: INSTALL_FAILED }, }); @@ -485,7 +496,7 @@ describe('withInstallHelpers inner functions', () => { const guid = 'foo@addon'; const handler = makeProgressHandler(dispatch, guid); handler({ state: 'WAT' }, { type: 'onNothingPerformed' }); - expect(dispatch.called).toBeFalsy(); + sinon.assert.notCalled(dispatch); }); });