Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: only show course blocks in the search modal #1148

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading