Skip to content

Commit

Permalink
fix: only show course blocks in the search modal
Browse files Browse the repository at this point in the history
  • Loading branch information
rpenido committed Jul 10, 2024
1 parent 09822c2 commit 7136ad1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/search-modal/SearchUI.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ describe('<SearchUI />', () => {
expect(fetchMock).toHaveLastFetched((_url, req) => {
const requestData = JSON.parse(req.body?.toString() ?? '');
const requestedFilter = requestData?.queries[0].filter;
return requestedFilter?.[0] === 'context_key = "course-v1:org+test+123"';
return requestedFilter?.[0] === 'type = "course_block"'
&& requestedFilter?.[1] === 'context_key = "course-v1:org+test+123"';
});
// Now we should see the results:
expect(queryByText('Enter a keyword')).toBeNull();
Expand Down Expand Up @@ -394,7 +395,8 @@ describe('<SearchUI />', () => {
expect(fetchMock).toHaveLastFetched((_url, req) => {
const requestData = JSON.parse(req.body?.toString() ?? '');
const requestedFilter = requestData?.queries[0].filter;
return (requestedFilter?.length === 1); // the filter is: 'context_key = "course-v1:org+test+123"'
// the filter is: ['type = "course_block"', 'context_key = "course-v1:org+test+123"']
return (requestedFilter?.length === 2);
});
// Now we should see the results:
expect(getByText('6 results found')).toBeInTheDocument();
Expand All @@ -419,6 +421,7 @@ describe('<SearchUI />', () => {
const requestData = JSON.parse(req.body?.toString() ?? '');
const requestedFilter = requestData?.queries[0].filter;
return JSON.stringify(requestedFilter) === JSON.stringify([
'type = "course_block"',
'context_key = "course-v1:org+test+123"',
['block_type = problem'], // <-- the newly added filter, sent with the request
]);
Expand All @@ -444,6 +447,7 @@ describe('<SearchUI />', () => {
const requestData = JSON.parse(req.body?.toString() ?? '');
const requestedFilter = requestData?.queries?.[0]?.filter;
return JSON.stringify(requestedFilter) === JSON.stringify([
'type = "course_block"',
'context_key = "course-v1:org+test+123"',
'tags.taxonomy = "ESDC Skills and Competencies"', // <-- the newly added filter, sent with the request
]);
Expand Down Expand Up @@ -477,6 +481,7 @@ describe('<SearchUI />', () => {
const requestData = JSON.parse(req.body?.toString() ?? '');
const requestedFilter = requestData?.queries?.[0]?.filter;
return JSON.stringify(requestedFilter) === JSON.stringify([
'type = "course_block"',
'context_key = "course-v1:org+test+123"',
'tags.level0 = "ESDC Skills and Competencies > Abilities"',
]);
Expand Down
5 changes: 4 additions & 1 deletion src/search-modal/SearchUI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ const SearchUI: React.FC<{ courseId: string, closeSearchModal?: () => void }> =

return (
<SearchContextProvider
extraFilter={searchThisCourse ? `context_key = "${props.courseId}"` : undefined}
extraFilter={[
'type = "course_block"',
...(searchThisCourse ? [`context_key = "${props.courseId}"`] : []),
]}
closeSearchModal={props.closeSearchModal}
>
{/* We need to override z-index here or the <Dropdown.Menu> appears behind the <ModalDialog.Body>
Expand Down

0 comments on commit 7136ad1

Please sign in to comment.