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
13 changes: 7 additions & 6 deletions src/disco/containers/InstallButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import config from 'config';
import { AddonManager } from 'disco/addonManager';
import {
DOWNLOADING,
EXTENSION_TYPE,
INSTALLED,
INSTALL_CATEGORY,
THEME_INSTALL,
Expand Down Expand Up @@ -115,7 +116,7 @@ export function makeProgressHandler(dispatch, guid) {
};
}

export function mapDispatchToProps(dispatch) {
export function mapDispatchToProps(dispatch, { _tracking = tracking } = {}) {
if (config.get('server')) {
return {};
}
Expand All @@ -135,13 +136,13 @@ export function mapDispatchToProps(dispatch) {
install({ guid, installURL, name }) {
const addonManager = new AddonManager(guid, installURL, makeProgressHandler(dispatch, guid));
dispatch({type: 'START_DOWNLOAD', payload: {guid}});
tracking.sendEvent({action: 'addon', category: INSTALL_CATEGORY, label: name});
_tracking.sendEvent({action: 'addon', category: INSTALL_CATEGORY, label: name});
return addonManager.install();
},

installTheme(node, guid, name, _themeAction = themeAction) {
_themeAction(node, THEME_INSTALL);
tracking.sendEvent({action: 'theme', category: INSTALL_CATEGORY, label: name});
_tracking.sendEvent({action: 'theme', category: INSTALL_CATEGORY, label: name});
return new Promise((resolve) => {
setTimeout(() => {
dispatch({type: 'INSTALL_STATE', payload: {guid, status: INSTALLED}});
Expand All @@ -154,10 +155,10 @@ export function mapDispatchToProps(dispatch) {
const addonManager = new AddonManager(guid, installURL);
dispatch({type: 'START_UNINSTALL', payload: {guid}});
const action = {
ADDON_TYPE: 'addon',
THEME_TYPE: 'theme',
[EXTENSION_TYPE]: 'addon',
[THEME_TYPE]: 'theme',
}[type] || 'invalid';
tracking.sendEvent({action, category: UNINSTALL_CATEGORY, label: name});
_tracking.sendEvent({action, category: UNINSTALL_CATEGORY, label: name});
return addonManager.uninstall()
.then(() => dispatch({type: 'UNINSTALL_COMPLETE', payload: {guid}}));
},
Expand Down
98 changes: 98 additions & 0 deletions tests/client/disco/containers/TestInstallButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ import {
} from 'disco/containers/InstallButton';
import {
DOWNLOADING,
INSTALL_CATEGORY,
INSTALLED,
INSTALLING,
THEME_INSTALL,
THEME_TYPE,
UNINSTALLED,
UNINSTALL_CATEGORY,
UNINSTALLING,
UNKNOWN,
} from 'disco/constants';
Expand Down Expand Up @@ -276,6 +278,25 @@ describe('<InstallButton />', () => {
});
});

it('tracks an addon inntall', () => {
stubAddonManager();
const name = 'hai-addon';
const type = 'extension';
const dispatch = sinon.spy();
const fakeTracking = {
sendEvent: sinon.spy(),
};
const { install } = mapDispatchToProps(dispatch, {_tracking: fakeTracking});
return install({guid, installURL, name, type})
.then(() => {
assert(fakeTracking.sendEvent.calledWith({
action: 'addon',
category: INSTALL_CATEGORY,
label: 'hai-addon',
}));
});
});

it('should dispatch START_DOWNLOAD', () => {
stubAddonManager();
const dispatch = sinon.spy();
Expand Down Expand Up @@ -303,6 +324,63 @@ describe('<InstallButton />', () => {
});
});

it('tracks an addon uninstall', () => {
stubAddonManager();
const dispatch = sinon.spy();
const name = 'whatevs';
const type = 'extension';
const fakeTracking = {
sendEvent: sinon.spy(),
};
const { uninstall } = mapDispatchToProps(dispatch, {_tracking: fakeTracking});
return uninstall({guid, installURL, name, type})
.then(() => {
assert.ok(fakeTracking.sendEvent.calledWith({
action: 'addon',
category: UNINSTALL_CATEGORY,
label: 'whatevs',
}), 'correctly called');
});
});

it('tracks a theme uninstall', () => {
stubAddonManager();
const dispatch = sinon.spy();
const name = 'whatevs';
const type = 'persona';
const fakeTracking = {
sendEvent: sinon.spy(),
};
const { uninstall } = mapDispatchToProps(dispatch, {_tracking: fakeTracking});
return uninstall({guid, installURL, name, type})
.then(() => {
assert(fakeTracking.sendEvent.calledWith({
action: 'theme',
category: UNINSTALL_CATEGORY,
label: 'whatevs',
}));
});
});

it('tracks a unknown type uninstall', () => {
stubAddonManager();
const dispatch = sinon.spy();
const name = 'whatevs';
const type = 'foo';
const fakeTracking = {
sendEvent: sinon.spy(),
};
const { uninstall } = mapDispatchToProps(dispatch, {_tracking: fakeTracking});
return uninstall({guid, installURL, name, type})
.then(() => {
assert(fakeTracking.sendEvent.calledWith({
action: 'invalid',
category: UNINSTALL_CATEGORY,
label: 'whatevs',
}));
});
});

it('should dispatch START_UNINSTALL', () => {
stubAddonManager();
const dispatch = sinon.spy();
Expand Down Expand Up @@ -332,6 +410,26 @@ describe('<InstallButton />', () => {
}));
});
});

it('tracks a theme install', () => {
const name = 'hai-theme';
const guid = '{install-theme}';
const node = sinon.stub();
const dispatch = sinon.spy();
const spyThemeAction = sinon.spy();
const fakeTracking = {
sendEvent: sinon.spy(),
};
const { installTheme } = mapDispatchToProps(dispatch, {_tracking: fakeTracking});
return installTheme(node, guid, name, spyThemeAction)
.then(() => {
assert(fakeTracking.sendEvent.calledWith({
action: 'theme',
category: INSTALL_CATEGORY,
label: 'hai-theme',
}));
});
});
});

describe('mapDispatchToProps', () => {
Expand Down