Skip to content

Commit 3ee4a34

Browse files
committed
test: fix failing tests
1 parent 12767d9 commit 3ee4a34

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/search-modal/SearchUI.test.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,12 @@ describe('<SearchUI />', () => {
100100
// because otherwise Instantsearch will update the UI and change the query,
101101
// leading to unexpected results in the test cases.
102102
mockResult.results[0].query = query;
103+
mockResult.results[2].query = query;
103104
// And fake the required '_formatted' fields; it contains the highlighting <mark>...</mark> around matched words
104105
// eslint-disable-next-line no-underscore-dangle, no-param-reassign
105106
mockResult.results[0]?.hits.forEach((hit) => { hit._formatted = { ...hit }; });
107+
// eslint-disable-next-line no-underscore-dangle, no-param-reassign
108+
mockResult.results[2]?.hits.forEach((hit) => { hit._formatted = { ...hit }; });
106109
return mockResult;
107110
});
108111
fetchMock.post(tagsKeywordSearchEndpoint, mockTagsKeywordSearchResult);
@@ -174,8 +177,8 @@ describe('<SearchUI />', () => {
174177
expect(fetchMock).toHaveLastFetched((_url, req) => {
175178
const requestData = JSON.parse(req.body?.toString() ?? '');
176179
const requestedFilter = requestData?.queries[0].filter;
177-
return requestedFilter?.[1] === 'type = "course_block"'
178-
&& requestedFilter?.[2] === 'context_key = "course-v1:org+test+123"';
180+
return requestedFilter?.[2] === 'type = "course_block"'
181+
&& requestedFilter?.[3] === 'context_key = "course-v1:org+test+123"';
179182
});
180183
// Now we should see the results:
181184
expect(queryByText('Enter a keyword')).toBeNull();
@@ -398,8 +401,9 @@ describe('<SearchUI />', () => {
398401
expect(fetchMock).toHaveLastFetched((_url, req) => {
399402
const requestData = JSON.parse(req.body?.toString() ?? '');
400403
const requestedFilter = requestData?.queries[0].filter;
401-
// the filter is: ['type = "course_block"', 'context_key = "course-v1:org+test+123"']
402-
return (requestedFilter?.length === 3);
404+
// the filter is:
405+
// ['NOT type == "collection"', '', 'type = "course_block"', 'context_key = "course-v1:org+test+123"']
406+
return (requestedFilter?.length === 4);
403407
});
404408
// Now we should see the results:
405409
expect(getByText('6 results found')).toBeInTheDocument();
@@ -425,6 +429,7 @@ describe('<SearchUI />', () => {
425429
const requestData = JSON.parse(req.body?.toString() ?? '');
426430
const requestedFilter = requestData?.queries[0].filter;
427431
return JSON.stringify(requestedFilter) === JSON.stringify([
432+
'NOT type = "collection"',
428433
[
429434
'block_type = problem',
430435
'content.problem_types = choiceresponse',
@@ -458,6 +463,7 @@ describe('<SearchUI />', () => {
458463
const requestData = JSON.parse(req.body?.toString() ?? '');
459464
const requestedFilter = requestData?.queries?.[0]?.filter;
460465
return JSON.stringify(requestedFilter) === JSON.stringify([
466+
'NOT type = "collection"',
461467
[],
462468
'type = "course_block"',
463469
'context_key = "course-v1:org+test+123"',
@@ -493,6 +499,7 @@ describe('<SearchUI />', () => {
493499
const requestData = JSON.parse(req.body?.toString() ?? '');
494500
const requestedFilter = requestData?.queries?.[0]?.filter;
495501
return JSON.stringify(requestedFilter) === JSON.stringify([
502+
'NOT type = "collection"',
496503
[],
497504
'type = "course_block"',
498505
'context_key = "course-v1:org+test+123"',

0 commit comments

Comments
 (0)