Bug 1822503 - Pocket newtab fixing startup reset from happening during experiment load. r=nanj,mconley,barret

Differential Revision: https://phabricator.services.mozilla.com/D173342
This commit is contained in:
scottdowne 2023-03-22 21:41:50 +00:00
parent 34e0e21dc3
commit add966c63f
2 changed files with 26 additions and 9 deletions

View file

@ -89,15 +89,21 @@ class PrefsFeed {
*/ */
onPocketExperimentUpdated(event, reason) { onPocketExperimentUpdated(event, reason) {
const value = lazy.NimbusFeatures.pocketNewtab.getAllVariables() || {}; const value = lazy.NimbusFeatures.pocketNewtab.getAllVariables() || {};
this.store.dispatch( // Loaded experiments are set up inside init()
ac.BroadcastToContent({ if (
type: at.PREF_CHANGED, reason !== "feature-experiment-loaded" &&
data: { reason !== "feature-rollout-loaded"
name: "pocketConfig", ) {
value, this.store.dispatch(
}, ac.BroadcastToContent({
}) type: at.PREF_CHANGED,
); data: {
name: "pocketConfig",
value,
},
})
);
}
} }
init() { init() {

View file

@ -177,6 +177,17 @@ describe("PrefsFeed", () => {
}) })
); );
}); });
it("should not send a PREF_CHANGED actions when onPocketExperimentUpdated is called during startup", () => {
sandbox
.stub(global.NimbusFeatures.pocketNewtab, "getAllVariables")
.returns({
prefsButtonIcon: "icon-new",
});
feed.onPocketExperimentUpdated({}, "feature-experiment-loaded");
assert.notCalled(feed.store.dispatch);
feed.onPocketExperimentUpdated({}, "feature-rollout-loaded");
assert.notCalled(feed.store.dispatch);
});
it("should send a PREF_CHANGED actions when onExperimentUpdated is called", () => { it("should send a PREF_CHANGED actions when onExperimentUpdated is called", () => {
sandbox.stub(global.NimbusFeatures.newtab, "getAllVariables").returns({ sandbox.stub(global.NimbusFeatures.newtab, "getAllVariables").returns({
prefsButtonIcon: "icon-new", prefsButtonIcon: "icon-new",