Skip to content

Transform snapshot into rtl test 1/2 #1756

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
228 changes: 0 additions & 228 deletions src/__snapshots__/index.test.jsx.snap

This file was deleted.

10 changes: 7 additions & 3 deletions src/course-home/courseware-search/CoursewareSearchEmpty.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
screen,
} from '../../setupTest';
import CoursewareSearchEmpty from './CoursewareSearchEmpty';
import messages from './messages';

function renderComponent() {
const { container } = render(<CoursewareSearchEmpty />);
Expand All @@ -16,9 +17,12 @@ describe('CoursewareSearchEmpty', () => {
initializeMockApp();
});

it('should match the snapshot', () => {
it('render empty results text and corresponding classes', () => {
renderComponent();

expect(screen.getByTestId('no-results')).toMatchSnapshot();
const emptyText = screen.getByText(messages.searchResultsNone.defaultMessage);
expect(emptyText).toBeInTheDocument();
expect(emptyText).toHaveClass('courseware-search-results__empty');
expect(emptyText).toHaveAttribute('data-testid', 'no-results');
expect(emptyText.parentElement).toHaveClass('courseware-search-results');
});
});
12 changes: 10 additions & 2 deletions src/course-home/courseware-search/CoursewareSearchResults.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
import CoursewareSearchResults from './CoursewareSearchResults';
import messages from './messages';
import searchResultsFactory from './test-data/search-results-factory';
import * as mock from './test-data/mocked-response.json';

jest.mock('react-redux');

Expand Down Expand Up @@ -34,8 +35,15 @@ describe('CoursewareSearchResults', () => {
renderComponent({ results });
});

it('should match the snapshot', () => {
expect(screen.getByTestId('search-results')).toMatchSnapshot();
it('should render complete list', () => {
const courses = screen.getAllByRole('link');
expect(courses.length).toBe(mock.results.length);
});

it('should render correct title for first course', () => {
const courses = screen.getAllByRole('link');
const firstCourseTitle = courses[0].querySelector('.courseware-search-results__title span');
expect(firstCourseTitle.innerHTML).toEqual(mock.results[0].data.content.display_name);
});
});
});

This file was deleted.

Loading