kopia lustrzana https://gitlab.com/soapbox-pub/soapbox
Suggestions: fix optimistic dismissal
rodzic
fcd9e47a99
commit
1be73d13a1
|
@ -1,5 +1,6 @@
|
||||||
import reducer from '../suggestions';
|
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', () => {
|
describe('suggestions reducer', () => {
|
||||||
it('should return the initial state', () => {
|
it('should return the initial state', () => {
|
||||||
|
@ -8,4 +9,29 @@ describe('suggestions reducer', () => {
|
||||||
isLoading: false,
|
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) => {
|
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) => {
|
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) {
|
export default function suggestionsReducer(state = initialState, action) {
|
||||||
|
|
Ładowanie…
Reference in New Issue