From 5eaa0a533f4ce1ed2bee138c9ca3e210a550394d Mon Sep 17 00:00:00 2001 From: Marcos Date: Thu, 8 Feb 2024 15:10:16 -0300 Subject: [PATCH] chore: Fixed unit tests for CoursewareResultsFilter --- .../CoursewareResultsFilter.test.jsx | 35 ++++++++++++------- .../CoursewareSearchResults.test.jsx.snap | 4 +-- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/course-home/courseware-search/CoursewareResultsFilter.test.jsx b/src/course-home/courseware-search/CoursewareResultsFilter.test.jsx index 997728b5ef..785167003c 100644 --- a/src/course-home/courseware-search/CoursewareResultsFilter.test.jsx +++ b/src/course-home/courseware-search/CoursewareResultsFilter.test.jsx @@ -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(); }); }); @@ -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(); }); }); }); diff --git a/src/course-home/courseware-search/__snapshots__/CoursewareSearchResults.test.jsx.snap b/src/course-home/courseware-search/__snapshots__/CoursewareSearchResults.test.jsx.snap index c38958db29..12178a62ed 100644 --- a/src/course-home/courseware-search/__snapshots__/CoursewareSearchResults.test.jsx.snap +++ b/src/course-home/courseware-search/__snapshots__/CoursewareSearchResults.test.jsx.snap @@ -26,7 +26,7 @@ exports[`CoursewareSearchResults when list of results is provided should match t xmlns="http://www.w3.org/2000/svg" > @@ -140,7 +140,7 @@ exports[`CoursewareSearchResults when list of results is provided should match t xmlns="http://www.w3.org/2000/svg" >