Suggestions: fix optimistic dismissal
This commit is contained in:
parent
fcd9e47a99
commit
1be73d13a1
2 changed files with 29 additions and 3 deletions
|
@ -1,5 +1,6 @@
|
|||
import reducer from '../suggestions';
|
||||
import { Map as ImmutableMap, List as ImmutableList } from 'immutable';
|
||||
import { Map as ImmutableMap, List as ImmutableList, fromJS } from 'immutable';
|
||||
import { SUGGESTIONS_DISMISS } from 'soapbox/actions/suggestions';
|
||||
|
||||
describe('suggestions reducer', () => {
|
||||
it('should return the initial state', () => {
|
||||
|
@ -8,4 +9,29 @@ describe('suggestions reducer', () => {
|
|||
isLoading: false,
|
||||
}));
|
||||
});
|
||||
|
||||
describe('SUGGESTIONS_DISMISS', () => {
|
||||
it('should remove the account', () => {
|
||||
const action = { type: SUGGESTIONS_DISMISS, id: '123' };
|
||||
|
||||
const state = fromJS({
|
||||
items: [
|
||||
{ account: '123', source: 'past_interactions' },
|
||||
{ account: '456', source: 'past_interactions' },
|
||||
{ account: '789', source: 'past_interactions' },
|
||||
],
|
||||
isLoading: false,
|
||||
});
|
||||
|
||||
const expected = fromJS({
|
||||
items: [
|
||||
{ account: '456', source: 'past_interactions' },
|
||||
{ account: '789', source: 'past_interactions' },
|
||||
],
|
||||
isLoading: false,
|
||||
});
|
||||
|
||||
expect(reducer(state, action)).toEqual(expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -39,11 +39,11 @@ const importSuggestions = (state, suggestions) => {
|
|||
};
|
||||
|
||||
const dismissAccount = (state, accountId) => {
|
||||
return state.update('items', list => list.filterNot(x => x.account === accountId));
|
||||
return state.update('items', items => items.filterNot(item => item.get('account') === accountId));
|
||||
};
|
||||
|
||||
const dismissAccounts = (state, accountIds) => {
|
||||
return state.update('items', list => list.filterNot(x => accountIds.includes(x.account)));
|
||||
return state.update('items', items => items.filterNot(item => accountIds.includes(item.get('account'))));
|
||||
};
|
||||
|
||||
export default function suggestionsReducer(state = initialState, action) {
|
||||
|
|
Loading…
Reference in a new issue