2022-01-10 14:01:24 -08:00
|
|
|
import { Map as ImmutableMap } from 'immutable';
|
2021-10-28 11:23:54 -07:00
|
|
|
import {
|
|
|
|
SEARCH_CHANGE,
|
|
|
|
SEARCH_CLEAR,
|
|
|
|
} from 'soapbox/actions/search';
|
2022-01-10 14:01:24 -08:00
|
|
|
import reducer from '../search';
|
2020-06-09 18:08:07 -07:00
|
|
|
|
|
|
|
describe('search reducer', () => {
|
|
|
|
it('should return the initial state', () => {
|
|
|
|
expect(reducer(undefined, {})).toEqual(ImmutableMap({
|
|
|
|
value: '',
|
|
|
|
submitted: false,
|
2021-08-07 11:42:39 -07:00
|
|
|
submittedValue: '',
|
2020-06-09 18:08:07 -07:00
|
|
|
hidden: false,
|
|
|
|
results: ImmutableMap(),
|
2021-08-02 12:10:41 -07:00
|
|
|
filter: 'accounts',
|
2020-06-09 18:08:07 -07:00
|
|
|
}));
|
|
|
|
});
|
2021-10-28 11:23:54 -07:00
|
|
|
|
|
|
|
describe('SEARCH_CHANGE', () => {
|
|
|
|
it('sets the value', () => {
|
|
|
|
const state = ImmutableMap({ value: 'hell' });
|
|
|
|
const action = { type: SEARCH_CHANGE, value: 'hello' };
|
|
|
|
expect(reducer(state, action).get('value')).toEqual('hello');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('SEARCH_CLEAR', () => {
|
|
|
|
it('resets the state', () => {
|
|
|
|
const state = ImmutableMap({
|
|
|
|
value: 'hello world',
|
|
|
|
submitted: true,
|
|
|
|
submittedValue: 'hello world',
|
|
|
|
hidden: false,
|
|
|
|
results: ImmutableMap(),
|
|
|
|
filter: 'statuses',
|
|
|
|
});
|
|
|
|
|
|
|
|
const action = { type: SEARCH_CLEAR };
|
|
|
|
|
|
|
|
const expected = ImmutableMap({
|
|
|
|
value: '',
|
|
|
|
submitted: false,
|
|
|
|
submittedValue: '',
|
|
|
|
hidden: false,
|
|
|
|
results: ImmutableMap(),
|
|
|
|
filter: 'accounts',
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(reducer(state, action)).toEqual(expected);
|
|
|
|
});
|
|
|
|
});
|
2020-06-09 18:08:07 -07:00
|
|
|
});
|