Skip to content

Commit

Permalink
feat(addon): mozilla#870 Turn recommendations on as experiment
Browse files Browse the repository at this point in the history
  • Loading branch information
sarracini committed Jul 21, 2016
1 parent 91911dd commit f3a415a
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 9 deletions.
3 changes: 2 additions & 1 deletion content-src/reducers/Experiments.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const definitions = require("../../experiments.json");
const defaultState = {values: {}, error: false};
const defaultState = {values: {}, error: false, init: false};

// Start with control values
Object.keys(definitions).forEach(key => {
Expand All @@ -19,6 +19,7 @@ module.exports = function Experiments(prevState = defaultState, action) {
};
} else {
return {
init: true,
error: false,
values: action.data
};
Expand Down
8 changes: 5 additions & 3 deletions content-src/selectors/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,10 @@ module.exports.selectNewTabSites = createSelector(
[
selectTopSites,
state => state.History,
selectSpotlight
selectSpotlight,
state => state.Experiments
],
(TopSites, History, Spotlight) => {
(TopSites, History, Spotlight, Experiments) => {

// Remove duplicates
// Note that we have to limit the length of topsites, spotlight so we
Expand All @@ -119,7 +120,8 @@ module.exports.selectNewTabSites = createSelector(
TopSites: Object.assign({}, TopSites, {rows: topSitesRows}),
Spotlight: Object.assign({}, Spotlight, {rows: spotlightRows}),
TopActivity: Object.assign({}, History, {rows: historyRows}),
isReady: TopSites.init && History.init && Spotlight.init
isReady: TopSites.init && History.init && Spotlight.init && Experiments.init,
showRecommendationOption: Experiments.values.recommendedHighlight
};
}
);
Expand Down
1 change: 0 additions & 1 deletion content-src/static/img/glyph-pocket-16.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion content-src/styles/icons.scss
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,4 @@
&.icon-pocket {
background-image: url('img/glyph-pocket-16.svg');
}

}
5 changes: 5 additions & 0 deletions content-test/components/NewTabPage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ describe("NewTabPage", () => {
TestUtils.Simulate.click(instance.refs.settingsLink);
assert.equal(instance.refs.settingsMenu.props.visible, true);
});
it("should show the setting button if we have recommendations", () => {
let fakePropsWithRecommendations = Object.assign({}, mockData, {showRecommendationOption: true});
instance = renderWithProvider(<NewTabPage {...fakePropsWithRecommendations} dispatch={() => {}} />);
assert.equal(instance.refs.settingsLink.hidden, false);
});
});

describe("hide recommendations", () => {
Expand Down
11 changes: 10 additions & 1 deletion content-test/selectors/selectors.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ describe("selectors", () => {
[
"Spotlight",
"TopActivity",
"TopSites"
"TopSites",
"showRecommendationOption"
].forEach(prop => {
assert.property(state, prop);
});
Expand All @@ -196,6 +197,14 @@ describe("selectors", () => {
const groups = [state.TopSites.rows, state.Spotlight.rows, state.TopActivity.rows];
assert.deepEqual(groups, dedupe.group(groups));
});
it("should not give showRecommendationOption if we are not in the experiment", () => {
assert.deepEqual(state.showRecommendationOption, undefined);
});
it("should give a showRecommendationOption if we are in the experiment", () => {
const experimentsData = {Experiments: {values: {recommendedHighlight: true}}};
state = selectNewTabSites(Object.assign({}, fakeState, experimentsData));
assert.isTrue(state.showRecommendationOption);
});
});
describe("selectSiteIcon", () => {
const siteWithFavicon = {
Expand Down
2 changes: 1 addition & 1 deletion content-test/test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function overrideConsoleError(onError = () => {}) {

module.exports = {
rawMockData: mockData,
mockData: Object.assign({}, mockData, selectNewTabSites(mockData), {showRecommendationOption: true}),
mockData: Object.assign({}, mockData, selectNewTabSites(mockData)),
createMockProvider,
renderWithProvider,
faker: require("test/faker"),
Expand Down
14 changes: 14 additions & 0 deletions experiments.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,19 @@
"threshold": 0.5,
"description": "Block is first, delete is second"
}
},
"recommendedHighlight": {
"name": "Recommended Highlights",
"description": "Show a recommendation from Pocket to the user",
"control": {
"value": false,
"description": "Do not show a recommendation"
},
"variant": {
"id": "exp-002-recommended-highlights",
"value": true,
"threshold": 0.3,
"description": "Show a recommendation in the third highlights spot"
}
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
"name": "recommendations",
"title": "Show me recommendations",
"type": "bool",
"value": false
"value": true
}
],
"repository": "mozilla/activity-stream",
Expand Down

0 comments on commit f3a415a

Please sign in to comment.