Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/core/installAddon.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
INSTALL_ERROR,
INSTALL_CANCELLED,
INSTALL_FAILED,
INSTALLING,
SET_ENABLE_NOT_AVAILABLE,
SHOW_INFO,
START_DOWNLOAD,
Expand Down Expand Up @@ -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,
Expand Down
25 changes: 18 additions & 7 deletions tests/unit/core/TestInstallAddon.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
INSTALL_CANCELLED,
INSTALL_FAILED,
INSTALLED,
INSTALLING,
SET_ENABLE_NOT_AVAILABLE,
SHOW_INFO,
START_DOWNLOAD,
Expand Down Expand Up @@ -441,29 +442,39 @@ 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', () => {
const dispatch = sinon.spy();
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', () => {
const dispatch = sinon.spy();
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 },
});
Expand All @@ -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 },
});
Expand All @@ -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);
});
});

Expand Down