forked from openedx/frontend-app-authoring
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCourseRerun.test.jsx
More file actions
64 lines (53 loc) · 2.1 KB
/
CourseRerun.test.jsx
File metadata and controls
64 lines (53 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { useSelector } from 'react-redux';
import {
initializeMocks,
fireEvent,
render,
waitFor,
} from '@src/testUtils';
import studioHomeMock from '@src/studio-home/__mocks__/studioHomeMock';
import { getStudioHomeApiUrl } from '../studio-home/data/api';
import { RequestStatus } from '../data/constants';
import messages from './messages';
import CourseRerun from '.';
jest.mock('react-redux', () => ({
...jest.requireActual('react-redux'),
useSelector: jest.fn(),
}));
const mockNavigate = jest.fn();
jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'), // use actual for all non-hook parts
useNavigate: () => mockNavigate,
}));
describe('<CourseRerun />', () => {
beforeEach(() => {
const { axiosMock } = initializeMocks();
axiosMock.onGet(getStudioHomeApiUrl()).reply(200, studioHomeMock);
useSelector.mockReturnValue(studioHomeMock);
});
it('should render successfully', () => {
const { getByText, getAllByRole } = render(<CourseRerun />);
expect(getByText(messages.rerunTitle.defaultMessage));
expect(getAllByRole('button', { name: messages.cancelButton.defaultMessage }).length).toBe(2);
});
it('should navigate to /home on cancel button click', async () => {
const { getAllByRole } = render(<CourseRerun />);
const cancelButton = getAllByRole('button', { name: messages.cancelButton.defaultMessage })[0];
fireEvent.click(cancelButton);
await waitFor(() => {
expect(mockNavigate).toHaveBeenCalledWith('/home');
});
});
it('shows the spinner before the query is complete', async () => {
useSelector.mockReturnValue({ organizationLoadingStatus: RequestStatus.IN_PROGRESS });
const { findByRole } = render(<CourseRerun />);
const spinner = await findByRole('status');
expect(spinner.textContent).toEqual('Loading...');
});
it('should show footer', async () => {
const { findByText } = render(<CourseRerun />);
await findByText('Looking for help with Studio?');
const lmsElement = await findByText('LMS');
expect(lmsElement).toHaveAttribute('href', process.env.LMS_BASE_URL);
});
});