bigbuffet-rw/app/soapbox/reducers/__tests__/search-test.js

106 lines
2.6 KiB
JavaScript
Raw Normal View History

import { Map as ImmutableMap, List as ImmutableList, fromJS } from 'immutable';
import {
SEARCH_CHANGE,
SEARCH_CLEAR,
SEARCH_EXPAND_SUCCESS,
} from 'soapbox/actions/search';
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({
2020-06-09 18:08:07 -07:00
value: '',
submitted: false,
submittedValue: '',
2020-06-09 18:08:07 -07:00
hidden: false,
results: ImmutableMap(),
filter: 'accounts',
2020-06-09 18:08:07 -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);
});
});
describe(SEARCH_EXPAND_SUCCESS, () => {
it('imports hashtags as maps', () => {
const state = ImmutableMap({
value: 'artist',
submitted: true,
submittedValue: 'artist',
hidden: false,
results: ImmutableMap({
hashtags: ImmutableList(),
}),
filter: 'hashtags',
});
const action = {
type: SEARCH_EXPAND_SUCCESS,
results: {
accounts: [],
statuses: [],
hashtags: [{
name: 'artist',
url: 'https://gleasonator.com/tags/artist',
history: [],
}],
},
searchTerm: 'artist',
searchType: 'hashtags',
};
const expected = ImmutableMap({
value: 'artist',
submitted: true,
submittedValue: 'artist',
hidden: false,
results: ImmutableMap({
hashtags: fromJS([{
name: 'artist',
url: 'https://gleasonator.com/tags/artist',
history: [],
}]),
hashtagsHasMore: false,
hashtagsLoaded: true,
}),
filter: 'hashtags',
});
expect(reducer(state, action)).toEqual(expected);
});
});
2020-06-09 18:08:07 -07:00
});