Skip to content
This repository has been archived by the owner on Feb 29, 2020. It is now read-only.

Commit

Permalink
Bug 1581570 - Spocs placement bug impacting non placements fixed (#5310)
Browse files Browse the repository at this point in the history
* Bug 1581570 - Spocs placement bug impacting non placements fixed
  • Loading branch information
ScottDowne committed Sep 18, 2019
1 parent 8a0e0d7 commit c9c543c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
10 changes: 8 additions & 2 deletions common/Reducers.jsm
Expand Up @@ -526,15 +526,21 @@ function DiscoveryStream(prevState = INITIAL_STATE.DiscoveryStream, action) {
const { data, placements } = prevState.spocs;
const result = {};

placements.forEach(placement => {
const forPlacement = placement => {
const placementSpocs = data[placement.name];

if (!placementSpocs || !placementSpocs.length) {
return;
}

result[placement.name] = handleSites(placementSpocs);
});
};

if (!placements || !placements.length) {
[{ name: "spocs" }].forEach(forPlacement);
} else {
placements.forEach(forPlacement);
}
return result;
};

Expand Down
22 changes: 22 additions & 0 deletions test/unit/common/Reducers.test.js
Expand Up @@ -992,6 +992,28 @@ describe("Reducers", () => {
placements: [],
});
});
it("should default to a single spoc placement", () => {
const deleteAction = {
type: at.DISCOVERY_STREAM_LINK_BLOCKED,
data: { url: "https://foo.com" },
};
const oldState = {
spocs: {
data: {
spocs: [{ url: "test-spoc.com" }],
},
loaded: true,
},
feeds: {
data: {},
loaded: true,
},
};

const newState = DiscoveryStream(oldState, deleteAction);

assert.equal(newState.spocs.data.spocs.length, 1);
});
it("should handle no data from DISCOVERY_STREAM_SPOCS_UPDATE", () => {
const data = null;
const state = DiscoveryStream(undefined, {
Expand Down

0 comments on commit c9c543c

Please sign in to comment.