Skip to content

Commit

Permalink
chore: Minor fixes on Courseware Search components
Browse files Browse the repository at this point in the history
  • Loading branch information
rijuma committed Dec 1, 2023
1 parent f5350ee commit a9db775
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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);
});
Expand Down Expand Up @@ -100,11 +101,7 @@ describe('CoursewareSearchResultsFilter', () => {
});

it('should render', async () => {
useModel.mockReturnValue({
total: 6,
results: mockResults,
filters: [],
});
useModel.mockReturnValue(searchResultsFactory());

await renderComponent();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ describe('CoursewareSearchEmpty', () => {
it('should match the snapshot', () => {
renderComponent();

expect(screen.getByTestId('search-results')).toMatchSnapshot();
expect(screen.getByTestId('no-results')).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`CoursewareSearchEmpty should match the snapshot 1`] = `
<p
class="courseware-search-results__empty"
data-testid="no-results"
>
No results found.
</p>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -1216,7 +1216,7 @@ exports[`CoursewareSearchResults when list of results is provided should match t
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M2.5 4v3h5v12h3V7h5V4h-13zm19 5h-9v3h3v7h3v-7h3V9z"
d="M3 3v18h18V3H3Zm11 14H7v-2h7v2Zm3-4H7v-2h10v2Zm0-4H7V7h10v2Z"
fill="currentColor"
/>
</svg>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -292,7 +297,7 @@ Object {
"location": null,
"score": 0.82610154,
"title": "External Course Link Test",
"type": "text",
"type": "unknown",
"url": "https://www.edx.org",
},
],
Expand Down
6 changes: 3 additions & 3 deletions src/course-home/courseware-search/map-search-response.js
Original file line number Diff line number Diff line change
@@ -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(),
Expand All @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ 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: 'video', label: 'Video', count: 2 },
{ key: 'unknown', label: 'Unknown', count: 1 },
];
expect(response.filters).toEqual(expectedFilters);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit a9db775

Please sign in to comment.