diff --git a/app/soapbox/reducers/__tests__/search-test.js b/app/soapbox/reducers/__tests__/search-test.js index aa66b6849..b1138b663 100644 --- a/app/soapbox/reducers/__tests__/search-test.js +++ b/app/soapbox/reducers/__tests__/search-test.js @@ -1,8 +1,9 @@ -import { Map as ImmutableMap } from 'immutable'; +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'; @@ -52,4 +53,53 @@ describe('search reducer', () => { 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); + }); + }); }); diff --git a/app/soapbox/reducers/search.js b/app/soapbox/reducers/search.js index 86e4222a5..bdc5cb58e 100644 --- a/app/soapbox/reducers/search.js +++ b/app/soapbox/reducers/search.js @@ -55,7 +55,15 @@ const paginateResults = (state, searchType, results, searchTerm) => { if (state.get('value') === searchTerm) { state.setIn(['results', `${searchType}HasMore`], results[searchType].length >= 20); state.setIn(['results', `${searchType}Loaded`], true); - state.updateIn(['results', searchType], items => items.concat(results[searchType].map(item => item.id))); + state.updateIn(['results', searchType], items => { + const data = results[searchType]; + // Hashtags are a list of maps. Others are IDs. + if (searchType === 'hashtags') { + return items.concat(fromJS(data)); + } else { + return items.concat(toIds(data)); + } + }); } }); };