Suggestions: fix optimistic dismissal

merge-requests/784/head
Alex Gleason 2021-10-02 15:18:27 -05:00
rodzic fcd9e47a99
commit 1be73d13a1
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 7211D1F99744FBB7
2 zmienionych plików z 29 dodań i 3 usunięć

Wyświetl plik

@ -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);
});
});
});

Wyświetl plik

@ -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) {