Skip to content
This repository was archived by the owner on Feb 29, 2020. It is now read-only.
Open
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
32 changes: 30 additions & 2 deletions lib/DiscoveryStreamFeed.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -1263,13 +1263,41 @@ this.DiscoveryStreamFeed = class DiscoveryStreamFeed {
case at.PREF_CHANGED:
switch (action.data.name) {
case PREF_CONFIG:
// Clear the cached config and broadcast the newly computed value
this._prefCache.config = null;
this.store.dispatch(
ac.BroadcastToContent({
type: at.DISCOVERY_STREAM_CONFIG_CHANGE,
data: this.config,
})
);
break;
case PREF_ENABLED:
case PREF_HARDCODED_BASIC_LAYOUT:
// Clear the cached config and broadcast the newly computed value
this._prefCache.config = null;
// If we're turning this from off to on, we should not update open tabs.
if (action.data.value) {
this.store.dispatch(
ac.AlsoToPreloaded({
type: at.DISCOVERY_STREAM_CONFIG_CHANGE,
data: this.config,
})
);
} else {
this.store.dispatch(
ac.BroadcastToContent({
type: at.DISCOVERY_STREAM_CONFIG_CHANGE,
data: this.config,
})
);
}
break;
case PREF_SPOCS_ENDPOINT:
case PREF_HARDCODED_BASIC_LAYOUT:
// Clear the cached config and broadcast the newly computed value
this._prefCache.config = null;
this.store.dispatch(
ac.BroadcastToContent({
ac.AlsoToPreloaded({
type: at.DISCOVERY_STREAM_CONFIG_CHANGE,
data: this.config,
})
Expand Down
102 changes: 101 additions & 1 deletion test/unit/lib/DiscoveryStreamFeed.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1689,7 +1689,7 @@ describe("DiscoveryStreamFeed", () => {
layout_endpoint: "foo",
});
});
it("should fire loadSpocs is showSponsored pref changes", async () => {
it("should fire loadSpocs if showSponsored pref changes", async () => {
sandbox.stub(feed, "loadSpocs").returns(Promise.resolve());

await feed.onAction({
Expand Down Expand Up @@ -1719,6 +1719,106 @@ describe("DiscoveryStreamFeed", () => {

assert.calledOnce(feed.clearSpocs);
});
it("should fire BroadcastToContent for config changes", async () => {
sandbox.spy(feed.store, "dispatch");

await feed.onAction({
type: at.PREF_CHANGED,
data: { name: CONFIG_PREF_NAME },
});

assert.calledWith(
feed.store.dispatch,
ac.BroadcastToContent({
data: {
enabled: false,
layout_endpoint: "https://getpocket.cdn.mozilla.net/dummy",
show_spocs: false,
},
type: "DISCOVERY_STREAM_CONFIG_CHANGE",
})
);
});
it("should fire BroadcastToContent for enabled false", async () => {
sandbox.spy(feed.store, "dispatch");

await feed.onAction({
type: at.PREF_CHANGED,
data: { name: "discoverystream.enabled", value: false },
});

assert.calledWith(
feed.store.dispatch,
ac.BroadcastToContent({
data: {
enabled: false,
layout_endpoint: "https://getpocket.cdn.mozilla.net/dummy",
show_spocs: false,
},
type: "DISCOVERY_STREAM_CONFIG_CHANGE",
})
);
});
it("should fire AlsoToPreloaded for enabled true", async () => {
sandbox.spy(feed.store, "dispatch");

await feed.onAction({
type: at.PREF_CHANGED,
data: { name: "discoverystream.enabled", value: true },
});

assert.calledWith(
feed.store.dispatch,
ac.AlsoToPreloaded({
data: {
enabled: false,
layout_endpoint: "https://getpocket.cdn.mozilla.net/dummy",
show_spocs: false,
},
type: "DISCOVERY_STREAM_CONFIG_CHANGE",
})
);
});
it("should fire AlsoToPreloaded for hardcoded basic layout", async () => {
sandbox.spy(feed.store, "dispatch");

await feed.onAction({
type: at.PREF_CHANGED,
data: { name: "discoverystream.hardcoded-basic-layout" },
});

assert.calledWith(
feed.store.dispatch,
ac.AlsoToPreloaded({
data: {
enabled: false,
layout_endpoint: "https://getpocket.cdn.mozilla.net/dummy",
show_spocs: false,
},
type: "DISCOVERY_STREAM_CONFIG_CHANGE",
})
);
});
it("should fire AlsoToPreloaded for spocs endpoint changes", async () => {
sandbox.spy(feed.store, "dispatch");

await feed.onAction({
type: at.PREF_CHANGED,
data: { name: "discoverystream.spocs-endpoint" },
});

assert.calledWith(
feed.store.dispatch,
ac.AlsoToPreloaded({
data: {
enabled: false,
layout_endpoint: "https://getpocket.cdn.mozilla.net/dummy",
show_spocs: false,
},
type: "DISCOVERY_STREAM_CONFIG_CHANGE",
})
);
});
});

describe("#onAction: SYSTEM_TICK", () => {
Expand Down