2022-06-08 14:43:27 -07:00
|
|
|
import { Map as ImmutableMap, List as ImmutableList, Record as ImmutableRecord } from 'immutable';
|
2022-01-10 14:25:06 -08:00
|
|
|
|
2021-10-28 11:23:54 -07:00
|
|
|
import {
|
|
|
|
SEARCH_CHANGE,
|
|
|
|
SEARCH_CLEAR,
|
2022-05-06 09:36:55 -07:00
|
|
|
SEARCH_EXPAND_SUCCESS,
|
2021-10-28 11:23:54 -07:00
|
|
|
} from 'soapbox/actions/search';
|
2022-01-10 14:25:06 -08:00
|
|
|
|
2022-05-17 08:37:16 -07:00
|
|
|
import reducer from '../search';
|
2020-06-09 18:08:07 -07:00
|
|
|
|
|
|
|
describe('search reducer', () => {
|
|
|
|
it('should return the initial state', () => {
|
2022-06-08 14:43:27 -07:00
|
|
|
expect(reducer(undefined, {}).toJS()).toEqual({
|
2020-06-09 18:08:07 -07:00
|
|
|
value: '',
|
|
|
|
submitted: false,
|
2021-08-07 11:42:39 -07:00
|
|
|
submittedValue: '',
|
2020-06-09 18:08:07 -07:00
|
|
|
hidden: false,
|
2022-06-08 14:43:27 -07:00
|
|
|
results: {
|
|
|
|
accounts: [],
|
|
|
|
statuses: [],
|
|
|
|
hashtags: [],
|
|
|
|
accountsHasMore: false,
|
|
|
|
statusesHasMore: false,
|
|
|
|
hashtagsHasMore: false,
|
|
|
|
accountsLoaded: false,
|
|
|
|
statusesLoaded: false,
|
|
|
|
hashtagsLoaded: false,
|
|
|
|
},
|
2021-08-02 12:10:41 -07:00
|
|
|
filter: 'accounts',
|
2022-06-08 14:43:27 -07:00
|
|
|
});
|
2020-06-09 18:08:07 -07:00
|
|
|
});
|
2021-10-28 11:23:54 -07:00
|
|
|
|
|
|
|
describe('SEARCH_CHANGE', () => {
|
|
|
|
it('sets the value', () => {
|
2022-05-17 08:37:16 -07:00
|
|
|
const state = ImmutableMap({ value: 'hell' });
|
2021-10-28 11:23:54 -07:00
|
|
|
const action = { type: SEARCH_CHANGE, value: 'hello' };
|
|
|
|
expect(reducer(state, action).get('value')).toEqual('hello');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('SEARCH_CLEAR', () => {
|
|
|
|
it('resets the state', () => {
|
2022-06-08 14:43:27 -07:00
|
|
|
const state = ImmutableRecord({
|
2021-10-28 11:23:54 -07:00
|
|
|
value: 'hello world',
|
|
|
|
submitted: true,
|
|
|
|
submittedValue: 'hello world',
|
|
|
|
hidden: false,
|
2022-06-08 14:43:27 -07:00
|
|
|
results: ImmutableRecord({})(),
|
2021-10-28 11:23:54 -07:00
|
|
|
filter: 'statuses',
|
2022-06-08 14:43:27 -07:00
|
|
|
})();
|
2021-10-28 11:23:54 -07:00
|
|
|
|
|
|
|
const action = { type: SEARCH_CLEAR };
|
|
|
|
|
2022-06-08 14:43:27 -07:00
|
|
|
const expected = {
|
2021-10-28 11:23:54 -07:00
|
|
|
value: '',
|
|
|
|
submitted: false,
|
|
|
|
submittedValue: '',
|
|
|
|
hidden: false,
|
2022-06-08 14:43:27 -07:00
|
|
|
results: {
|
|
|
|
accounts: [],
|
|
|
|
statuses: [],
|
|
|
|
hashtags: [],
|
|
|
|
accountsHasMore: false,
|
|
|
|
statusesHasMore: false,
|
|
|
|
hashtagsHasMore: false,
|
|
|
|
accountsLoaded: false,
|
|
|
|
statusesLoaded: false,
|
|
|
|
hashtagsLoaded: false,
|
|
|
|
},
|
2021-10-28 11:23:54 -07:00
|
|
|
filter: 'accounts',
|
2022-06-08 14:43:27 -07:00
|
|
|
};
|
2021-10-28 11:23:54 -07:00
|
|
|
|
2022-06-08 14:43:27 -07:00
|
|
|
expect(reducer(state, action).toJS()).toEqual(expected);
|
2021-10-28 11:23:54 -07:00
|
|
|
});
|
|
|
|
});
|
2022-05-06 09:36:55 -07:00
|
|
|
|
|
|
|
describe(SEARCH_EXPAND_SUCCESS, () => {
|
|
|
|
it('imports hashtags as maps', () => {
|
2022-06-08 14:43:27 -07:00
|
|
|
const state = ImmutableRecord({
|
2022-05-06 09:36:55 -07:00
|
|
|
value: 'artist',
|
|
|
|
submitted: true,
|
|
|
|
submittedValue: 'artist',
|
|
|
|
hidden: false,
|
2022-06-08 14:43:27 -07:00
|
|
|
results: ImmutableRecord({
|
2022-05-06 09:36:55 -07:00
|
|
|
hashtags: ImmutableList(),
|
2022-06-08 14:43:27 -07:00
|
|
|
hashtagsHasMore: false,
|
|
|
|
hashtagsLoaded: true,
|
|
|
|
})(),
|
2022-05-06 09:36:55 -07:00
|
|
|
filter: 'hashtags',
|
2022-06-08 14:43:27 -07:00
|
|
|
})();
|
2022-05-06 09:36:55 -07:00
|
|
|
|
|
|
|
const action = {
|
|
|
|
type: SEARCH_EXPAND_SUCCESS,
|
|
|
|
results: {
|
|
|
|
accounts: [],
|
|
|
|
statuses: [],
|
|
|
|
hashtags: [{
|
|
|
|
name: 'artist',
|
|
|
|
url: 'https://gleasonator.com/tags/artist',
|
|
|
|
history: [],
|
|
|
|
}],
|
|
|
|
},
|
|
|
|
searchTerm: 'artist',
|
|
|
|
searchType: 'hashtags',
|
|
|
|
};
|
|
|
|
|
2022-06-08 14:43:27 -07:00
|
|
|
const expected = {
|
2022-05-06 09:36:55 -07:00
|
|
|
value: 'artist',
|
|
|
|
submitted: true,
|
|
|
|
submittedValue: 'artist',
|
|
|
|
hidden: false,
|
2022-06-08 14:43:27 -07:00
|
|
|
results: {
|
|
|
|
hashtags: [
|
|
|
|
{
|
|
|
|
name: 'artist',
|
|
|
|
url: 'https://gleasonator.com/tags/artist',
|
|
|
|
history: [],
|
|
|
|
},
|
|
|
|
],
|
2022-05-06 09:36:55 -07:00
|
|
|
hashtagsHasMore: false,
|
|
|
|
hashtagsLoaded: true,
|
2022-06-08 14:43:27 -07:00
|
|
|
},
|
2022-05-06 09:36:55 -07:00
|
|
|
filter: 'hashtags',
|
2022-06-08 14:43:27 -07:00
|
|
|
};
|
2022-05-06 09:36:55 -07:00
|
|
|
|
2022-06-08 14:43:27 -07:00
|
|
|
expect(reducer(state, action).toJS()).toEqual(expected);
|
2022-05-06 09:36:55 -07:00
|
|
|
});
|
|
|
|
});
|
2020-06-09 18:08:07 -07:00
|
|
|
});
|