|
7 | 7 | import CoursewareSearchResults from './CoursewareSearchResults';
|
8 | 8 | import messages from './messages';
|
9 | 9 | import searchResultsFactory from './test-data/search-results-factory';
|
| 10 | +import * as mock from './test-data/mocked-response.json'; |
10 | 11 |
|
11 | 12 | jest.mock('react-redux');
|
12 | 13 |
|
@@ -34,8 +35,53 @@ describe('CoursewareSearchResults', () => {
|
34 | 35 | renderComponent({ results });
|
35 | 36 | });
|
36 | 37 |
|
37 |
| - it('should match the snapshot', () => { |
38 |
| - expect(screen.getByTestId('search-results')).toMatchSnapshot(); |
| 38 | + it('should render complete list', () => { |
| 39 | + const courses = screen.getAllByRole('link'); |
| 40 | + expect(courses.length).toBe(mock.results.length); |
| 41 | + }); |
| 42 | + |
| 43 | + it('should render correct link for internal course', () => { |
| 44 | + const courses = screen.getAllByRole('link'); |
| 45 | + const firstCourse = courses[0]; |
| 46 | + const firstCourseTitle = firstCourse.querySelector('.courseware-search-results__title span'); |
| 47 | + expect(firstCourseTitle.innerHTML).toEqual(mock.results[0].data.content.display_name); |
| 48 | + expect(firstCourse.href).toContain(mock.results[0].data.url); |
| 49 | + expect(firstCourse).not.toHaveAttribute('target', '_blank'); |
| 50 | + expect(firstCourse).not.toHaveAttribute('rel', 'nofollow'); |
| 51 | + }); |
| 52 | + |
| 53 | + it('should render correct link if is External url course', () => { |
| 54 | + const courses = screen.getAllByRole('link'); |
| 55 | + const externalCourse = courses[courses.length - 1]; |
| 56 | + const externalCourseTitle = externalCourse.querySelector('.courseware-search-results__title span'); |
| 57 | + expect(externalCourseTitle.innerHTML).toEqual(mock.results[mock.results.length - 1].data.content.display_name); |
| 58 | + expect(externalCourse.href).toContain(mock.results[mock.results.length - 1].data.url); |
| 59 | + expect(externalCourse).toHaveAttribute('target', '_blank'); |
| 60 | + expect(externalCourse).toHaveAttribute('rel', 'nofollow'); |
| 61 | + const icon = externalCourse.querySelector('svg'); |
| 62 | + expect(icon).toBeInTheDocument(); |
| 63 | + }); |
| 64 | + |
| 65 | + it('should render location breadcrumbs', () => { |
| 66 | + const breadcrumbs = screen.getAllByText(mock.results[0].data.location[0]); |
| 67 | + expect(breadcrumbs.length).toBeGreaterThan(0); |
| 68 | + const firstBreadcrumb = breadcrumbs[0].closest('li'); |
| 69 | + expect(firstBreadcrumb).toBeInTheDocument(); |
| 70 | + expect(firstBreadcrumb.querySelector('div').textContent).toBe(mock.results[0].data.location[0]); |
| 71 | + expect(firstBreadcrumb.nextSibling.querySelector('div').textContent).toBe(mock.results[0].data.location[1]); |
| 72 | + }); |
| 73 | + }); |
| 74 | + |
| 75 | + describe('when results are provided with content hits', () => { |
| 76 | + beforeEach(() => { |
| 77 | + const { results } = searchResultsFactory('Passing'); |
| 78 | + renderComponent({ results }); |
| 79 | + }); |
| 80 | + |
| 81 | + it('should render content hits', () => { |
| 82 | + const contentHits = screen.getByText('1'); |
| 83 | + expect(contentHits).toBeInTheDocument(); |
| 84 | + expect(contentHits.tagName).toBe('EM'); |
39 | 85 | });
|
40 | 86 | });
|
41 | 87 | });
|
0 commit comments