Skip to content

Commit

Permalink
chore: Fixed unit tests for CoursewareResultsFilter
Browse files Browse the repository at this point in the history
  • Loading branch information
rijuma committed Feb 8, 2024
1 parent f7149bd commit 5eaa0a5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
35 changes: 23 additions & 12 deletions src/course-home/courseware-search/CoursewareResultsFilter.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,29 +68,38 @@ describe('CoursewareSearchResultsFilter', () => {

it('should render without errors', async () => {
await waitFor(() => {
expect(screen.queryByTestId('courseware-search-results-tabs')).toBeInTheDocument();
expect(screen.queryByTestId('courseware-search-results-tabs-all')).toBeInTheDocument();
expect(screen.queryByTestId('courseware-search-results-tabs-text')).toBeInTheDocument();
expect(screen.queryByTestId('courseware-search-results-tabs-video')).toBeInTheDocument();
expect(screen.queryByTestId('courseware-search-results-tabs-sequence')).toBeInTheDocument();
expect(screen.queryByTestId('courseware-search-results-tabs-other')).toBeInTheDocument();
expect(useCoursewareSearchParams).toBeCalled();
});

expect(screen.queryByTestId('courseware-search-results-tabs')).toBeInTheDocument();
expect(screen.queryByTestId('courseware-search-results-tabs-all')).toBeInTheDocument();
expect(screen.queryByTestId('courseware-search-results-tabs-text')).toBeInTheDocument();
expect(screen.queryByTestId('courseware-search-results-tabs-video')).toBeInTheDocument();
expect(screen.queryByTestId('courseware-search-results-tabs-sequence')).toBeInTheDocument();
expect(screen.queryByTestId('courseware-search-results-tabs-other')).toBeInTheDocument();
});
});

describe('when returning only one result type', () => {
beforeEach(async () => {
// Filter only videos
const results = searchResultsFactory().filter(({ type }) => type === 'video');
// Get results for only videos
const data = searchResultsFactory();
const onlyVideos = data.results.filter(({ type }) => type === 'video');
const filteredResults = {
...data,
results: onlyVideos,
};

useModel.mockReturnValue(results);
useModel.mockReturnValue(filteredResults);
await renderComponent();
});

it('should render without errors', async () => {
it('should not render', async () => {
await waitFor(() => {
expect(screen.queryByTestId('courseware-search-results-tabs')).not.toBeInTheDocument();
expect(useCoursewareSearchParams).toBeCalled();
});

expect(screen.queryByTestId('courseware-search-results-tabs')).not.toBeInTheDocument();
});
});

Expand All @@ -108,8 +117,10 @@ describe('CoursewareSearchResultsFilter', () => {

it('should not render', async () => {
await waitFor(() => {
expect(screen.queryByTestId('courseware-search-results-tabs')).not.toBeInTheDocument();
expect(useCoursewareSearchParams).toBeCalled();
});

expect(screen.queryByTestId('courseware-search-results-tabs')).not.toBeInTheDocument();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ exports[`CoursewareSearchResults when list of results is provided should match t
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M3 3v18h18V3H3Zm11 14H7v-2h7v2Zm3-4H7v-2h10v2Zm0-4H7V7h10v2Z"
d="M10 4H2v16h20V6H12l-2-2z"
fill="currentColor"
/>
</svg>
Expand Down Expand Up @@ -140,7 +140,7 @@ exports[`CoursewareSearchResults when list of results is provided should match t
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M3 3v18h18V3H3Zm11 14H7v-2h7v2Zm3-4H7v-2h10v2Zm0-4H7V7h10v2Z"
d="M10 4H2v16h20V6H12l-2-2z"
fill="currentColor"
/>
</svg>
Expand Down

0 comments on commit 5eaa0a5

Please sign in to comment.