Skip to content

Commit 4548504

Browse files
committed
Update tests for listType change
1 parent e2891ae commit 4548504

File tree

12 files changed

+207
-98
lines changed

12 files changed

+207
-98
lines changed

src/components/record/RecordTitleBar.jsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ export default function RecordTitleBar(props, context) {
8484
<SearchResultTraverserContainer
8585
config={config}
8686
csid={csid}
87-
listType={listType}
8887
searchName={searchName}
8988
searchDescriptor={searchDescriptor}
9089
originSearchPageState={originSearchPageState}

src/components/search/SearchResultSummary.jsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import styles from '../../../styles/cspace-ui/SearchResultSummary.css';
1111
import { setSearchPageRecordType, setSearchPageVocabulary } from '../../actions/prefs';
1212
import { setSearchPageAdvanced, setSearchPageKeyword } from '../../actions/searchPage';
1313
import { getSearchError, getSearchResult } from '../../reducers';
14+
import { getListTypeForResult } from '../../helpers/searchHelpers';
1415

1516
const messages = defineMessages({
1617
error: {
@@ -91,20 +92,13 @@ const defaultProps = {
9192
export default function SearchResultSummary(props) {
9293
const {
9394
config,
94-
listType,
9595
searchDescriptor,
9696
searchName,
9797
renderEditLink,
9898
onEditSearchLinkClick,
9999
onPageSizeChange,
100100
} = props;
101101

102-
// let {
103-
// searchError,
104-
// searchResult,
105-
// } = props;
106-
107-
// support both workflows for the time being (prop/hook based)
108102
const searchError = useSelector((state) => getSearchError(state, searchName, searchDescriptor));
109103
const searchResult = useSelector((state) => getSearchResult(state, searchName, searchDescriptor));
110104

@@ -137,6 +131,7 @@ export default function SearchResultSummary(props) {
137131
let pageSize = null;
138132

139133
if (searchResult) {
134+
const listType = getListTypeForResult(config, searchResult);
140135
const listTypeConfig = config.listTypes[listType];
141136
const { listNodeName } = listTypeConfig;
142137

src/components/search/SearchResultTraverser.jsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ const propTypes = {
4040
listTypes: PropTypes.object,
4141
}),
4242
csid: PropTypes.string,
43-
listType: PropTypes.string,
4443
searchName: PropTypes.string,
4544
searchDescriptor: PropTypes.instanceOf(Immutable.Map),
4645
searchState: PropTypes.instanceOf(Immutable.Map),
@@ -76,7 +75,6 @@ export default class SearchResultTraverser extends Component {
7675
search,
7776
} = this.props;
7877

79-
const { listType } = deriveSearchType(config, searchName, searchDescriptor);
8078
if (search) {
8179
if (searchDescriptor && !searchState) {
8280
// We have a search descriptor, but it's not associated with any state. This happens when
@@ -88,6 +86,7 @@ export default class SearchResultTraverser extends Component {
8886
}
8987

9088
if (searchState && !searchState.get('isPending') && searchState.get('result')) {
89+
const { listType } = deriveSearchType(config, searchName, searchDescriptor);
9190
const listTypeConfig = config.listTypes[listType];
9291
const { listNodeName, itemNodeName } = listTypeConfig;
9392

test/helpers/providerHelpers.jsx

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import React from 'react';
2+
import { render } from 'react-dom';
3+
import { act } from 'react-dom/test-utils';
4+
import { IntlProvider } from 'react-intl';
5+
import { Provider } from 'react-redux';
6+
import { MemoryRouter } from 'react-router-dom/cjs/react-router-dom.min';
7+
import { applyMiddleware, compose, createStore as reduxCreateStore } from 'redux';
8+
import thunk from 'redux-thunk';
9+
import ConfigProvider from '../../src/components/config/ConfigProvider';
10+
import reducers from '../../src/reducers';
11+
import createConfigContext from '../../src/helpers/createConfigContext';
12+
import { evaluatePlugin, finalizeRecordTypes, mergeConfig } from '../../src/helpers/configHelpers';
13+
import plugins from '../../src/plugins';
14+
15+
/**
16+
* @returns the CSpace configuration object
17+
*/
18+
export function createCSpaceConfig() {
19+
const configContext = createConfigContext();
20+
21+
const defaultConfig = mergeConfig({
22+
structDateOptionListNames: ['dateQualifiers'],
23+
structDateVocabNames: ['dateera', 'datecertainty', 'datequalifier'],
24+
tags: {
25+
defaultGroup: {
26+
sortOrder: 0,
27+
},
28+
nagpra: {
29+
sortOrder: 1,
30+
},
31+
legacy: {
32+
sortOrder: 3,
33+
},
34+
},
35+
tenantId: '1',
36+
}, {
37+
plugins: plugins.map((plugin) => plugin()),
38+
}, configContext);
39+
40+
const resolvedUiConfig = evaluatePlugin({}, createConfigContext());
41+
return finalizeRecordTypes(mergeConfig(defaultConfig, resolvedUiConfig, configContext));
42+
}
43+
44+
/**
45+
* @returns a redux store
46+
*/
47+
export function createStore() {
48+
return reduxCreateStore(reducers, compose(
49+
applyMiddleware(thunk),
50+
));
51+
}
52+
53+
/**
54+
* Render a React component/function with all expected providers
55+
*
56+
* @param {*} element the React component to render
57+
* @param {*} config the CollectionSpace configuration for the ConfigProvider
58+
* @param {*} store the Redux store for the Redux Provider
59+
* @param {*} container the container to render to
60+
* @returns
61+
*/
62+
export function renderWithProviders(element, config, store, container) {
63+
let resultTree;
64+
65+
const fullTree = (
66+
<IntlProvider locale="en">
67+
<Provider store={store}>
68+
<ConfigProvider config={config}>
69+
<MemoryRouter>
70+
{element}
71+
</MemoryRouter>
72+
</ConfigProvider>
73+
</Provider>
74+
</IntlProvider>
75+
);
76+
77+
act(() => {
78+
resultTree = render(fullTree, container);
79+
});
80+
81+
return resultTree;
82+
}

test/specs/actions/search.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ describe('search action creator', () => {
9898
},
9999
subresources: {
100100
terms: {
101+
listType: 'common',
101102
serviceConfig: {
102103
servicePath: termsServicePath,
103104
},

test/specs/components/media/MediaViewerPanel.spec.jsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -158,16 +158,14 @@ describe('MediaViewerPanel', () => {
158158
let searchedConfig = null;
159159
let searchedSearchName = null;
160160
let searchedSearchDescriptor = null;
161-
let searchedListType = null;
162161
let searchedColumnSetName = null;
163162

164163
const search = (
165-
configArg, searchNameArg, searchDescriptorArg, listTypeArg, columnSetNameArg,
164+
configArg, searchNameArg, searchDescriptorArg, columnSetNameArg,
166165
) => {
167166
searchedConfig = configArg;
168167
searchedSearchName = searchNameArg;
169168
searchedSearchDescriptor = searchDescriptorArg;
170-
searchedListType = listTypeArg;
171169
searchedColumnSetName = columnSetNameArg;
172170
};
173171

@@ -185,24 +183,21 @@ describe('MediaViewerPanel', () => {
185183
searchedConfig.should.equal(config);
186184
searchedSearchName.should.equal(searchName);
187185
searchedSearchDescriptor.should.equal(searchDescriptor);
188-
searchedListType.should.equal('common');
189186
searchedColumnSetName.should.equal('default');
190187
});
191188

192189
it('should call search when a new search descriptor is supplied', function test() {
193190
let searchedConfig = null;
194191
let searchedSearchName = null;
195192
let searchedSearchDescriptor = null;
196-
let searchedListType = null;
197193
let searchedColumnSetName = null;
198194

199195
const search = (
200-
configArg, searchNameArg, searchDescriptorArg, listTypeArg, columnSetNameArg,
196+
configArg, searchNameArg, searchDescriptorArg, columnSetNameArg,
201197
) => {
202198
searchedConfig = configArg;
203199
searchedSearchName = searchNameArg;
204200
searchedSearchDescriptor = searchDescriptorArg;
205-
searchedListType = listTypeArg;
206201
searchedColumnSetName = columnSetNameArg;
207202
};
208203

@@ -239,7 +234,6 @@ describe('MediaViewerPanel', () => {
239234
searchedConfig.should.equal(config);
240235
searchedSearchName.should.equal(searchName);
241236
searchedSearchDescriptor.should.equal(newSearchDescriptor);
242-
searchedListType.should.equal('common');
243237
searchedColumnSetName.should.equal('default');
244238
});
245239
});

test/specs/components/pages/SearchResultPage.spec.jsx

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,16 @@ const searchDescriptor = Immutable.fromJS({
184184
},
185185
});
186186

187+
const optionList = Immutable.Map({
188+
searchResultPagePageSizes: [
189+
{ value: '10' },
190+
{ value: '20' },
191+
{ value: '40' },
192+
],
193+
});
194+
187195
const store = mockStore({
188-
optionList: Immutable.Map({
189-
searchResultPagePageSizes: [
190-
{ value: '10' },
191-
{ value: '20' },
192-
{ value: '40' },
193-
],
194-
}),
196+
optionList,
195197
prefs: Immutable.Map(),
196198
search: Immutable.fromJS({
197199
[SEARCH_RESULT_PAGE_SEARCH_NAME]: {
@@ -640,9 +642,25 @@ describe('SearchResultPage', () => {
640642
'ns2:abstract-common-list': {},
641643
});
642644

645+
const updatedStore = mockStore({
646+
optionList,
647+
prefs: Immutable.Map(),
648+
search: Immutable.fromJS({
649+
[SEARCH_RESULT_PAGE_SEARCH_NAME]: {
650+
byKey: {
651+
[searchKey(searchDescriptor)]: {
652+
result: noTotalItemsSearchResult,
653+
},
654+
},
655+
},
656+
}),
657+
searchToSelect: Immutable.Map(),
658+
user: Immutable.Map(),
659+
});
660+
643661
render(
644662
<IntlProvider locale="en">
645-
<StoreProvider store={store}>
663+
<StoreProvider store={updatedStore}>
646664
<ConfigProvider config={config}>
647665
<Router>
648666
{searchResultPage.renderHeader({ searchResult: noTotalItemsSearchResult })}
@@ -659,10 +677,6 @@ describe('SearchResultPage', () => {
659677
});
660678

661679
it('should render an error message if the search has an error', () => {
662-
const searchError = Immutable.Map({
663-
code: 'ERROR_CODE',
664-
});
665-
666680
const pageContainer = document.createElement('div');
667681

668682
document.body.appendChild(pageContainer);
@@ -689,9 +703,29 @@ describe('SearchResultPage', () => {
689703

690704
document.body.appendChild(headerContainer);
691705

706+
const searchError = Immutable.Map({
707+
code: 'ERROR_CODE',
708+
});
709+
710+
const updatedStore = mockStore({
711+
optionList,
712+
prefs: Immutable.Map(),
713+
search: Immutable.fromJS({
714+
[SEARCH_RESULT_PAGE_SEARCH_NAME]: {
715+
byKey: {
716+
[searchKey(searchDescriptor)]: {
717+
error: searchError,
718+
},
719+
},
720+
},
721+
}),
722+
searchToSelect: Immutable.Map(),
723+
user: Immutable.Map(),
724+
});
725+
692726
render(
693727
<IntlProvider locale="en">
694-
<StoreProvider store={store}>
728+
<StoreProvider store={updatedStore}>
695729
<ConfigProvider config={config}>
696730
<Router>
697731
{searchResultPage.renderHeader({ searchError })}

test/specs/components/pages/search/SearchResults.spec.jsx

Whitespace-only changes.

test/specs/components/search/SearchPanel.spec.jsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -172,16 +172,14 @@ describe('SearchPanel', () => {
172172
let searchedConfig = null;
173173
let searchedSearchName = null;
174174
let searchedSearchDescriptor = null;
175-
let searchedListType = null;
176175
let searchedColumnSetName = null;
177176

178177
const search = (
179-
configArg, searchNameArg, searchDescriptorArg, listTypeArg, columnSetNameArg,
178+
configArg, searchNameArg, searchDescriptorArg, columnSetNameArg,
180179
) => {
181180
searchedConfig = configArg;
182181
searchedSearchName = searchNameArg;
183182
searchedSearchDescriptor = searchDescriptorArg;
184-
searchedListType = listTypeArg;
185183
searchedColumnSetName = columnSetNameArg;
186184
};
187185

@@ -212,7 +210,6 @@ describe('SearchPanel', () => {
212210
searchedConfig.should.equal(config);
213211
searchedSearchName.should.equal(searchName);
214212
searchedSearchDescriptor.should.equal(searchDescriptor);
215-
searchedListType.should.equal('common');
216213
searchedColumnSetName.should.equal('default');
217214

218215
changedToSearchDescriptor.should.equal(searchDescriptor);
@@ -222,16 +219,14 @@ describe('SearchPanel', () => {
222219
let searchedConfig = null;
223220
let searchedSearchName = null;
224221
let searchedSearchDescriptor = null;
225-
let searchedListType = null;
226222
let searchedColumnSetName = null;
227223

228224
const search = (
229-
configArg, searchNameArg, searchDescriptorArg, listTypeArg, columnSetNameArg,
225+
configArg, searchNameArg, searchDescriptorArg, columnSetNameArg,
230226
) => {
231227
searchedConfig = configArg;
232228
searchedSearchName = searchNameArg;
233229
searchedSearchDescriptor = searchDescriptorArg;
234-
searchedListType = listTypeArg;
235230
searchedColumnSetName = columnSetNameArg;
236231
};
237232

@@ -286,7 +281,6 @@ describe('SearchPanel', () => {
286281
searchedConfig.should.equal(config);
287282
searchedSearchName.should.equal(searchName);
288283
searchedSearchDescriptor.should.equal(newSearchDescriptor);
289-
searchedListType.should.equal('common');
290284
searchedColumnSetName.should.equal('default');
291285

292286
changedToSearchDescriptor.should.equal(newSearchDescriptor);

test/specs/components/search/SearchResultSummary.spec.jsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { ERR_API } from '../../../../src/constants/errorCodes';
88
import createTestContainer from '../../../helpers/createTestContainer';
99
import { render } from '../../../helpers/renderHelpers';
1010
import SearchResultSummary from '../../../../src/components/search/SearchResultSummary';
11+
import { searchKey } from '../../../../src/reducers/search';
1112

1213
chai.should();
1314

@@ -51,6 +52,7 @@ describe('SearchResultSummary', () => {
5152
});
5253

5354
it('should render a not allowed message if a 401 search error is supplied', function test() {
55+
const searchName = 'search-summary-test';
5456
const searchError = Immutable.fromJS({
5557
code: ERR_API,
5658
error: {
@@ -60,11 +62,24 @@ describe('SearchResultSummary', () => {
6062
},
6163
});
6264

65+
const storeWithError = mockStore({
66+
search: Immutable.fromJS({
67+
[searchName]: {
68+
byKey: {
69+
[searchKey(searchDescriptor)]: {
70+
error: searchError,
71+
},
72+
},
73+
},
74+
}),
75+
});
76+
6377
render(
6478
<IntlProvider locale="en">
65-
<StoreProvider store={store}>
79+
<StoreProvider store={storeWithError}>
6680
<Router>
6781
<SearchResultSummary
82+
searchName={searchName}
6883
searchDescriptor={searchDescriptor}
6984
searchError={searchError}
7085
/>

0 commit comments

Comments
 (0)