From 967c13ddcad4db47f55dfa06cb3a43689ca3bfa9 Mon Sep 17 00:00:00 2001 From: Marcos Date: Fri, 1 Dec 2023 12:40:45 -0300 Subject: [PATCH] chore: Minor fixes on Courseware Search components --- .../courseware-search/CoursewareResultsFilter.test.jsx | 9 +++------ .../courseware-search/CoursewareSearchEmpty.test.jsx | 2 +- .../__snapshots__/CoursewareSearchEmpty.test.jsx.snap | 10 ++++++++++ .../CoursewareSearchResults.test.jsx.snap | 2 +- .../__snapshots__/map-search-response.test.js.snap | 9 +++++++-- .../courseware-search/map-search-response.js | 6 +++--- .../courseware-search/map-search-response.test.js | 3 ++- .../courseware-search/test-data/mocked-response.json | 2 +- 8 files changed, 28 insertions(+), 15 deletions(-) create mode 100644 src/course-home/courseware-search/__snapshots__/CoursewareSearchEmpty.test.jsx.snap diff --git a/src/course-home/courseware-search/CoursewareResultsFilter.test.jsx b/src/course-home/courseware-search/CoursewareResultsFilter.test.jsx index 0ca7faea62..034c80f2c7 100644 --- a/src/course-home/courseware-search/CoursewareResultsFilter.test.jsx +++ b/src/course-home/courseware-search/CoursewareResultsFilter.test.jsx @@ -11,6 +11,7 @@ import { import { CoursewareSearchResultsFilter, filteredResultsBySelection } from './CoursewareResultsFilter'; import initializeStore from '../../store'; import { useModel } from '../../generic/model-store'; +import searchResultsFactory from './test-data/search-results-factory'; jest.mock('../../generic/model-store', () => ({ useModel: jest.fn(), @@ -64,7 +65,7 @@ describe('CoursewareSearchResultsFilter', () => { describe('filteredResultsBySelection', () => { it('returns a no values array when no results are provided', () => { - const results = filteredResultsBySelection({ results: [] }); + const results = filteredResultsBySelection({}); expect(results.length).toEqual(0); }); @@ -100,11 +101,7 @@ describe('CoursewareSearchResultsFilter', () => { }); it('should render', async () => { - useModel.mockReturnValue({ - total: 6, - results: mockResults, - filters: [], - }); + useModel.mockReturnValue(searchResultsFactory()); await renderComponent(); diff --git a/src/course-home/courseware-search/CoursewareSearchEmpty.test.jsx b/src/course-home/courseware-search/CoursewareSearchEmpty.test.jsx index 486bafc880..7ef5909a15 100644 --- a/src/course-home/courseware-search/CoursewareSearchEmpty.test.jsx +++ b/src/course-home/courseware-search/CoursewareSearchEmpty.test.jsx @@ -19,6 +19,6 @@ describe('CoursewareSearchEmpty', () => { it('should match the snapshot', () => { renderComponent(); - expect(screen.getByTestId('search-results')).toMatchSnapshot(); + expect(screen.getByTestId('no-results')).toMatchSnapshot(); }); }); diff --git a/src/course-home/courseware-search/__snapshots__/CoursewareSearchEmpty.test.jsx.snap b/src/course-home/courseware-search/__snapshots__/CoursewareSearchEmpty.test.jsx.snap new file mode 100644 index 0000000000..e87c856ea0 --- /dev/null +++ b/src/course-home/courseware-search/__snapshots__/CoursewareSearchEmpty.test.jsx.snap @@ -0,0 +1,10 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`CoursewareSearchEmpty should match the snapshot 1`] = ` +

+ No results found. +

+`; 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 7411e80a8d..c38958db29 100644 --- a/src/course-home/courseware-search/__snapshots__/CoursewareSearchResults.test.jsx.snap +++ b/src/course-home/courseware-search/__snapshots__/CoursewareSearchResults.test.jsx.snap @@ -1216,7 +1216,7 @@ exports[`CoursewareSearchResults when list of results is provided should match t xmlns="http://www.w3.org/2000/svg" > diff --git a/src/course-home/courseware-search/__snapshots__/map-search-response.test.js.snap b/src/course-home/courseware-search/__snapshots__/map-search-response.test.js.snap index aacd097783..b3c193539e 100644 --- a/src/course-home/courseware-search/__snapshots__/map-search-response.test.js.snap +++ b/src/course-home/courseware-search/__snapshots__/map-search-response.test.js.snap @@ -14,10 +14,15 @@ Object { "label": "Sequence", }, Object { - "count": 10, + "count": 9, "key": "text", "label": "Text", }, + Object { + "count": 1, + "key": "unknown", + "label": "Unknown", + }, Object { "count": 2, "key": "video", @@ -292,7 +297,7 @@ Object { "location": null, "score": 0.82610154, "title": "External Course Link Test", - "type": "text", + "type": "unknown", "url": "https://www.edx.org", }, ], diff --git a/src/course-home/courseware-search/map-search-response.js b/src/course-home/courseware-search/map-search-response.js index 2c005bd1e5..a03e99b110 100644 --- a/src/course-home/courseware-search/map-search-response.js +++ b/src/course-home/courseware-search/map-search-response.js @@ -1,8 +1,8 @@ const Joi = require('joi'); const endpointSchema = Joi.object({ - took: Joi.number(), - total: Joi.number(), + took: Joi.number().required(), + total: Joi.number().required(), maxScore: Joi.number().allow(null), results: Joi.array().items(Joi.object({ id: Joi.string(), @@ -14,7 +14,7 @@ const endpointSchema = Joi.object({ htmlContent: Joi.string(), transcriptEn: Joi.string(), }), - }).unknown(true)).strict(), + }).required().unknown(true)).strict(), }).unknown(true).strict(); const defaultType = 'text'; diff --git a/src/course-home/courseware-search/map-search-response.test.js b/src/course-home/courseware-search/map-search-response.test.js index 1b7acc6e51..2ad4318a9c 100644 --- a/src/course-home/courseware-search/map-search-response.test.js +++ b/src/course-home/courseware-search/map-search-response.test.js @@ -18,7 +18,8 @@ describe('mapSearchResponse', () => { const expectedFilters = [ { key: 'capa', label: 'CAPA', count: 7 }, { key: 'sequence', label: 'Sequence', count: 2 }, - { key: 'text', label: 'Text', count: 10 }, + { key: 'text', label: 'Text', count: 9 }, + { key: 'unknown', label: 'Unknown', count: 1 }, { key: 'video', label: 'Video', count: 2 }, ]; expect(response.filters).toEqual(expectedFilters); diff --git a/src/course-home/courseware-search/test-data/mocked-response.json b/src/course-home/courseware-search/test-data/mocked-response.json index 7ae8ff1e13..06ff12cb0b 100644 --- a/src/course-home/courseware-search/test-data/mocked-response.json +++ b/src/course-home/courseware-search/test-data/mocked-response.json @@ -554,7 +554,7 @@ "display_name": "External Course Link Test", "html_content": "This should open a new tab when following the link." }, - "content_type": "Text", + "content_type": "Unknown", "id": "random-element-id", "start_date": "2013-02-05T05:00:00+00:00", "content_groups": null,