Fixes bug 1504165 - Two Sponsored cards are wrongly displayed after increasing the number of Pocket recommendation rows

This commit is contained in:
ScottDowne 2018-11-05 15:58:49 -05:00 коммит произвёл Kate Hudson
Родитель e99d002a5c
Коммит 2b4610af92
2 изменённых файлов: 10 добавлений и 2 удалений

Просмотреть файл

@ -271,7 +271,10 @@ function Sections(prevState = INITIAL_STATE.Sections, action) {
const rows = Array.from(action.data.rows);
section.rows.forEach((card, index) => {
if (card.pinned) {
rows.splice(index, 0, card);
// Only add it if it's not already there.
if (rows[index].guid !== card.guid) {
rows.splice(index, 0, card);
}
}
});
return Object.assign({}, section, initialized, Object.assign({}, action.data, {rows}));

Просмотреть файл

@ -338,7 +338,12 @@ describe("Reducers", () => {
let updatedSection = newState.find(section => section.id === "foo_bar_2");
assert.deepEqual(updatedSection.rows, [ROW]);
const PINNED_ROW = {id: "pinned", pinned: true};
const PINNED_ROW = {id: "pinned", pinned: true, guid: "pinned"};
newState = Sections(newState, {type: at.SECTION_UPDATE, data: Object.assign({rows: [PINNED_ROW]}, {id: "foo_bar_2"})});
updatedSection = newState.find(section => section.id === "foo_bar_2");
assert.deepEqual(updatedSection.rows, [PINNED_ROW]);
// Updating the section again should not duplicate pinned cards
newState = Sections(newState, {type: at.SECTION_UPDATE, data: Object.assign({rows: [PINNED_ROW]}, {id: "foo_bar_2"})});
updatedSection = newState.find(section => section.id === "foo_bar_2");
assert.deepEqual(updatedSection.rows, [PINNED_ROW]);