forked from openedx/frontend-app-authoring
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCourseChecklist.test.jsx
More file actions
154 lines (126 loc) · 5.3 KB
/
CourseChecklist.test.jsx
File metadata and controls
154 lines (126 loc) · 5.3 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import {
render,
waitFor,
screen,
initializeMocks,
} from '@src/testUtils';
import '@testing-library/jest-dom';
import { getConfig, setConfig } from '@edx/frontend-platform';
import { CourseAuthoringProvider } from '@src/CourseAuthoringContext';
import { RequestStatus } from '../data/constants';
import { executeThunk } from '../utils';
import { getCourseLaunchApiUrl, getCourseBestPracticesApiUrl } from './data/api';
import { fetchCourseLaunchQuery, fetchCourseBestPracticesQuery } from './data/thunks';
import {
courseId,
generateCourseLaunchData,
generateCourseBestPracticesData,
} from './factories/mockApiResponses';
import messages from './messages';
import CourseChecklist from './index';
let axiosMock;
let store;
const renderComponent = () => {
render(
<CourseAuthoringProvider courseId={courseId}>
<CourseChecklist />
</CourseAuthoringProvider>,
);
};
const mockStore = async (status) => {
axiosMock.onGet(getCourseLaunchApiUrl(courseId)).reply(status, generateCourseLaunchData());
axiosMock.onGet(getCourseBestPracticesApiUrl(courseId)).reply(status, generateCourseBestPracticesData());
await executeThunk(fetchCourseLaunchQuery(courseId), store.dispatch);
await executeThunk(fetchCourseBestPracticesQuery(courseId), store.dispatch);
};
describe('CourseChecklistPage', () => {
beforeEach(async () => {
const mocks = initializeMocks();
store = mocks.reduxStore;
axiosMock = mocks.axiosMock;
});
describe('renders', () => {
describe('if enable_quality prop is true', () => {
it('two checklist components ', async () => {
renderComponent();
await mockStore(200);
expect(screen.getByText(messages.launchChecklistLabel.defaultMessage)).toBeVisible();
expect(screen.getByText(messages.bestPracticesChecklistLabel.defaultMessage)).toBeVisible();
});
describe('an aria-live region with', () => {
it('an aria-live region', () => {
renderComponent();
const ariaLiveRegion = screen.getByRole('status');
expect(ariaLiveRegion).toBeDefined();
expect(ariaLiveRegion.classList.contains('sr-only')).toBe(true);
});
it('correct content when the launch checklist has loaded', async () => {
renderComponent();
await mockStore(404);
await waitFor(() => {
const { launchChecklistStatus } = store.getState().courseChecklist.loadingStatus;
expect(launchChecklistStatus).not.toEqual(RequestStatus.SUCCESSFUL);
expect(screen.getByText(messages.launchChecklistDoneLoadingLabel.defaultMessage)).toBeInTheDocument();
});
});
it('correct content when the best practices checklist is loading', async () => {
renderComponent();
await mockStore(404);
await waitFor(() => {
const { bestPracticeChecklistStatus } = store.getState().courseChecklist.loadingStatus;
expect(bestPracticeChecklistStatus).not.toEqual(RequestStatus.IN_PROGRESS);
expect(
screen.getByText(messages.bestPracticesChecklistDoneLoadingLabel.defaultMessage),
).toBeInTheDocument();
});
});
});
});
describe('if enable_quality prop is false', () => {
beforeEach(() => {
setConfig({
...getConfig(),
ENABLE_CHECKLIST_QUALITY: 'false',
});
});
it('one checklist components ', async () => {
renderComponent();
await mockStore(200);
expect(screen.getByText(messages.launchChecklistLabel.defaultMessage)).toBeVisible();
expect(screen.queryByText(messages.bestPracticesChecklistLabel.defaultMessage)).toBeNull();
});
describe('an aria-live region with', () => {
it('correct content when the launch checklist has loaded', async () => {
renderComponent();
await mockStore(404);
await waitFor(() => {
const { launchChecklistStatus } = store.getState().courseChecklist.loadingStatus;
expect(launchChecklistStatus).not.toEqual(RequestStatus.SUCCESSFUL);
expect(screen.getByText(messages.launchChecklistDoneLoadingLabel.defaultMessage)).toBeInTheDocument();
});
});
it('correct content when the best practices checklist is loading', async () => {
renderComponent();
await mockStore(404);
await waitFor(() => {
const { bestPracticeChecklistStatus } = store.getState().courseChecklist.loadingStatus;
expect(bestPracticeChecklistStatus).not.toEqual(RequestStatus.IN_PROGRESS);
expect(screen.queryByText(messages.bestPracticesChecklistDoneLoadingLabel.defaultMessage)).toBeNull();
});
});
});
});
it('displays an alert and sets status to DENIED when API responds with 403', async () => {
const courseLaunchApiUrl = getCourseLaunchApiUrl({
courseId, gradedOnly: true, validateOras: true, all: true,
});
axiosMock.onGet(courseLaunchApiUrl).reply(403);
renderComponent();
await waitFor(() => {
const { launchChecklistStatus } = store.getState().courseChecklist.loadingStatus;
expect(launchChecklistStatus).toEqual(RequestStatus.DENIED);
expect(screen.getByRole('alert')).toBeInTheDocument();
});
});
});
});