Skip to content

Commit

Permalink
test: update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rpenido committed Apr 22, 2024
1 parent c34dce7 commit 33b131e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
5 changes: 5 additions & 0 deletions src/custom.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@ declare module '*.svg' {
const content: string;
export default content;
}

declare module '*.json' {
const value: any;
export default value;
}
13 changes: 6 additions & 7 deletions src/search-modal/SearchUI.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,10 @@ import {
import fetchMock from 'fetch-mock-jest';

import initializeStore from '../store';
// @ts-ignore
import mockResult from './__mocks__/search-result.json';
// @ts-ignore
import mockEmptyResult from './__mocks__/empty-search-result.json';
// @ts-ignore
import mockTagsFacetResult from './__mocks__/facet-search.json';
// @ts-ignore
import mockTagsFacetResultLevel0 from './__mocks__/facet-search-level0.json';
// @ts-ignore
import mockTagsFacetResultLevel1 from './__mocks__/facet-search-level1.json';
import SearchUI from './SearchUI';
import { getContentSearchConfigUrl } from './data/api';
Expand Down Expand Up @@ -164,14 +159,18 @@ describe('<SearchUI />', () => {
window.open = jest.fn();
fireEvent.click(within(resultItem).getByRole('button', { name: 'Open in new window' }));
expect(window.open).toHaveBeenCalledWith(
'/course/course-v1:edx+TestCourse+24?show=block-v1%3Aedx%2BTestCourse%2B24%2Btype%40html%2Bblock%40test_html',
'/course/course-v1:edx+TestCourse+24/container/block-v1:edx+TestCourse+24+type@vertical+block@vertical_3_1'
+ '?show=block-v1%3Aedx%2BTestCourse%2B24%2Btype%40html%2Bblock%40test_html',
'_blank',
);
window.open = open;

// Clicking in the result should navigate to the result's URL:
fireEvent.click(resultItem);
expect(mockNavigate).toHaveBeenCalledWith('/course/course-v1:edx+TestCourse+24?show=block-v1%3Aedx%2BTestCourse%2B24%2Btype%40html%2Bblock%40test_html');
expect(mockNavigate).toHaveBeenCalledWith(
'/course/course-v1:edx+TestCourse+24/container/block-v1:edx+TestCourse+24+type@vertical+block@vertical_3_1'
+ '?show=block-v1%3Aedx%2BTestCourse%2B24%2Btype%40html%2Bblock%40test_html',
);
});

it('defaults to searching "This Course" if used in a course', async () => {
Expand Down
17 changes: 12 additions & 5 deletions src/search-modal/__mocks__/search-result.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@
"context_key": "course-v1:edx+TestCourse+24",
"org": "edx",
"breadcrumbs": [
{ "display_name": "TheCourse" },
{ "display_name": "Section 2" },
{ "display_name": "Subsection 3" },
{ "display_name": "The Little Unit That Could" }
{ "display_name": "TheCourse", "usage_key": "course-v1:edx+TestCourse+24" },
{ "display_name": "Section 2", "usage_key": "block-v1:edx+TestCourse+24+type@chapter+block@chapter_2" },
{
"display_name": "Subsection 3",
"usage_key": "block-v1:edx+TestCourse+24+type@sequential+block@sequential_3"
},
{
"display_name": "The Little Unit That Could",
"usage_key": "block-v1:edx+TestCourse+24+type@vertical+block@vertical_3_1"
}
],
"tags": {
"taxonomy": [
Expand Down Expand Up @@ -64,7 +70,8 @@
"org": "edx",
"breadcrumbs": [
{
"display_name": "libafter2"
"display_name": "libafter2",
"usage_key": "lib:org1:libafter1"
}
],
"type": "library_block"
Expand Down

0 comments on commit 33b131e

Please sign in to comment.