forked from openedx/frontend-app-authoring
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReviewImportDetails.test.tsx
More file actions
286 lines (260 loc) · 11.4 KB
/
ReviewImportDetails.test.tsx
File metadata and controls
286 lines (260 loc) · 11.4 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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
import { useCourseDetails } from '@src/course-outline/data/apiHooks';
import { useLibraryBlockLimits, useMigrationInfo } from '@src/library-authoring/data/apiHooks';
import { useGetBlockTypes, useGetContentHits } from '@src/search-manager';
import { render as baseRender, screen, initializeMocks } from '@src/testUtils';
import { LibraryProvider } from '@src/library-authoring/common/context/LibraryContext';
import { mockContentLibrary } from '@src/library-authoring/data/api.mocks';
import { ReviewImportDetails } from './ReviewImportDetails';
import messages from '../messages';
mockContentLibrary.applyMock();
const { libraryId } = mockContentLibrary;
const markAnalysisComplete = jest.fn();
// Mock the useCourseDetails hook
jest.mock('@src/course-outline/data/apiHooks', () => ({
useCourseDetails: jest.fn().mockReturnValue({ isPending: true, data: null }),
}));
// Mock the useMigrationInfo hook
jest.mock('@src/library-authoring/data/apiHooks', () => ({
useMigrationInfo: jest.fn().mockReturnValue({ isPending: true, data: null }),
useContentLibrary: jest.fn().mockReturnValue({}),
useLibraryBlockLimits: jest.fn().mockReturnValue({ isPending: true, data: null }),
}));
// Mock the useGetBlockTypes hook
jest.mock('@src/search-manager', () => ({
useGetBlockTypes: jest.fn().mockReturnValue({ isPending: true, data: null }),
useGetContentHits: jest.fn().mockReturnValue({ isPending: true, data: null }),
}));
const render = (element: React.ReactElement) => {
const params: { libraryId: string } = { libraryId };
return baseRender(element, {
path: '/libraries/:libraryId/import/course',
params,
extraWrapper: ({ children }) => (
<LibraryProvider
libraryId={libraryId}
>
{ children }
</LibraryProvider>
),
});
};
describe('ReviewImportDetails', () => {
beforeEach(() => {
initializeMocks();
});
it('renders loading spinner when isPending is true', async () => {
render(<ReviewImportDetails markAnalysisComplete={markAnalysisComplete} courseId="test-course-id" />);
const spinners = await screen.findAllByRole('status');
spinners.every((spinner) => expect(spinner.textContent).toEqual('Loading...'));
expect(markAnalysisComplete).toHaveBeenCalledWith(false);
});
it('renders import progress status when isBlockDataPending or migrationInfoIsPending is true', async () => {
(useCourseDetails as jest.Mock).mockReturnValue({ isPending: false, data: { title: 'Test Course' } });
(useLibraryBlockLimits as jest.Mock).mockReturnValue({
isPending: false,
data: { maxBlocksPerContentLibrary: 100 },
});
(useMigrationInfo as jest.Mock).mockReturnValue({
isPending: true,
data: null,
});
render(<ReviewImportDetails markAnalysisComplete={markAnalysisComplete} courseId="test-course-id" />);
expect(await screen.findByRole('alert')).toBeInTheDocument();
expect(await screen.findByText(/Import Analysis in Progress/i)).toBeInTheDocument();
expect(markAnalysisComplete).toHaveBeenCalledWith(false);
});
it('renders warning when reimport', async () => {
(useCourseDetails as jest.Mock).mockReturnValue({ isPending: false, data: { title: 'Test Course' } });
(useLibraryBlockLimits as jest.Mock).mockReturnValue({
isPending: false,
data: { maxBlocksPerContentLibrary: 100 },
});
(useMigrationInfo as jest.Mock).mockReturnValue({
isPending: false,
data: {
'test-course-id': [{
targetKey: libraryId,
targetTitle: 'Library title',
}],
},
});
(useGetBlockTypes as jest.Mock).mockReturnValueOnce({
isPending: false,
data: { html: 1 },
});
render(<ReviewImportDetails markAnalysisComplete={markAnalysisComplete} courseId="test-course-id" />);
expect(await screen.findByRole('alert')).toBeInTheDocument();
expect(await screen.findByText(/Import Analysis Completed: Reimport/i)).toBeInTheDocument();
expect(await screen.findByText(
messages.importCourseAnalysisCompleteReimportBody.defaultMessage
.replace('{courseName}', 'Test Course')
.replace('{libraryName}', 'Library title'),
)).toBeInTheDocument();
expect(markAnalysisComplete).toHaveBeenCalledWith(true);
});
it('renders warning when unsupportedBlockPercentage > 0', async () => {
(useCourseDetails as jest.Mock).mockReturnValue({ isPending: false, data: { title: 'Test Course' } });
(useLibraryBlockLimits as jest.Mock).mockReturnValue({
isPending: false,
data: { maxBlocksPerContentLibrary: 100 },
});
(useMigrationInfo as jest.Mock).mockReturnValue({
isPending: false,
data: null,
});
(useGetBlockTypes as jest.Mock).mockReturnValueOnce({
isPending: false,
data: {
chapter: 1,
sequential: 2,
vertical: 3,
'problem-builder': 1,
html: 1,
},
});
render(<ReviewImportDetails markAnalysisComplete={markAnalysisComplete} courseId="test-course-id" />);
expect(await screen.findByRole('alert')).toBeInTheDocument();
expect(await screen.findByText(/Import Analysis Complete/i)).toBeInTheDocument();
expect(await screen.findByText(
/12.50% of content cannot be imported. For details see below./i,
)).toBeInTheDocument();
expect(await screen.findByText(/Total Blocks/i)).toBeInTheDocument();
expect(await screen.findByText('7/8')).toBeInTheDocument();
expect(await screen.findByText('Sections')).toBeInTheDocument();
expect(await screen.findByText('1')).toBeInTheDocument();
expect(await screen.findByText('Subsections')).toBeInTheDocument();
expect(await screen.findByText('2')).toBeInTheDocument();
expect(await screen.findByText('Units')).toBeInTheDocument();
expect(await screen.findByText('3')).toBeInTheDocument();
expect(await screen.findByText('Components')).toBeInTheDocument();
expect(await screen.findByText('1/2')).toBeInTheDocument();
expect(markAnalysisComplete).toHaveBeenCalledWith(true);
});
it('renders warning when components exceed the limit', async () => {
(useCourseDetails as jest.Mock).mockReturnValue({ isPending: false, data: { title: 'Test Course' } });
(useLibraryBlockLimits as jest.Mock).mockReturnValue({
isPending: false,
data: { maxBlocksPerContentLibrary: 20 },
});
(useMigrationInfo as jest.Mock).mockReturnValue({
isPending: false,
data: null,
});
(useGetBlockTypes as jest.Mock).mockReturnValueOnce({
isPending: false,
data: {
chapter: 1,
sequential: 2,
vertical: 3,
'problem-builder': 1,
html: 25,
},
});
render(<ReviewImportDetails markAnalysisComplete={markAnalysisComplete} courseId="test-course-id" />);
expect(await screen.findByRole('alert')).toBeInTheDocument();
expect(await screen.findByText(/Import Analysis Complete/i)).toBeInTheDocument();
expect(await screen.findByText(
/18.75% of content cannot be imported. For details see below./i,
)).toBeInTheDocument();
expect(await screen.findByText(/Total Blocks/i)).toBeInTheDocument();
expect(await screen.findByText('26/32')).toBeInTheDocument();
expect(await screen.findByText('Sections')).toBeInTheDocument();
expect(await screen.findByText('1')).toBeInTheDocument();
expect(await screen.findByText('Subsections')).toBeInTheDocument();
expect(await screen.findByText('2')).toBeInTheDocument();
expect(await screen.findByText('Units')).toBeInTheDocument();
expect(await screen.findByText('3')).toBeInTheDocument();
expect(await screen.findByText('Components')).toBeInTheDocument();
expect(await screen.findByText('20/26')).toBeInTheDocument();
expect(markAnalysisComplete).toHaveBeenCalledWith(true);
});
it('considers children blocks of unsupportedBlocks', async () => {
(useCourseDetails as jest.Mock).mockReturnValue({ isPending: false, data: { title: 'Test Course' } });
(useLibraryBlockLimits as jest.Mock).mockReturnValue({
isPending: false,
data: { maxBlocksPerContentLibrary: 100 },
});
(useMigrationInfo as jest.Mock).mockReturnValue({
isPending: false,
data: null,
});
(useGetContentHits as jest.Mock).mockReturnValue({
isPending: false,
data: {
hits: [{ usage_key: 'some-usage-key' }],
estimatedTotalHits: 1,
},
});
(useGetBlockTypes as jest.Mock).mockReturnValueOnce({
isPending: false,
data: {
chapter: 1,
sequential: 2,
vertical: 3,
library_content: 1,
html: 1,
problem: 4,
},
}).mockReturnValueOnce({
isPending: false,
data: {
problem: 2,
},
});
render(<ReviewImportDetails markAnalysisComplete={markAnalysisComplete} courseId="test-course-id" />);
expect(await screen.findByRole('alert')).toBeInTheDocument();
expect(await screen.findByText(/Import Analysis Complete/i)).toBeInTheDocument();
expect(await screen.findByText(
/25.00% of content cannot be imported. For details see below./i,
)).toBeInTheDocument();
expect(await screen.findByText(/Total Blocks/i)).toBeInTheDocument();
expect(await screen.findByText('9/12')).toBeInTheDocument();
expect(await screen.findByText('Sections')).toBeInTheDocument();
expect(await screen.findByText('1')).toBeInTheDocument();
expect(await screen.findByText('Subsections')).toBeInTheDocument();
expect(await screen.findByText('2')).toBeInTheDocument();
expect(await screen.findByText('Units')).toBeInTheDocument();
expect(await screen.findByText('3')).toBeInTheDocument();
expect(await screen.findByText('Components')).toBeInTheDocument();
expect(await screen.findByText('3/6')).toBeInTheDocument();
expect(markAnalysisComplete).toHaveBeenCalledWith(true);
});
it('renders success alert when no unsupported blocks', async () => {
(useCourseDetails as jest.Mock).mockReturnValue({ isPending: false, data: { title: 'Test Course' } });
(useLibraryBlockLimits as jest.Mock).mockReturnValue({
isPending: false,
data: { maxBlocksPerContentLibrary: 100 },
});
(useMigrationInfo as jest.Mock).mockReturnValue({
isPending: false,
data: null,
});
(useGetBlockTypes as jest.Mock).mockReturnValueOnce({
isPending: false,
data: {
chapter: 1,
sequential: 2,
vertical: 3,
html: 5,
problem: 3,
},
});
render(<ReviewImportDetails markAnalysisComplete={markAnalysisComplete} courseId="test-course-id" />);
expect(await screen.findByRole('alert')).toBeInTheDocument();
expect(await screen.findByText(
messages.importCourseAnalysisCompleteAllContentBody.defaultMessage
.replace('{courseName}', 'Test Course'),
)).toBeInTheDocument();
expect(await screen.findByText(/Total Blocks/i)).toBeInTheDocument();
expect(await screen.findByText('14')).toBeInTheDocument();
expect(await screen.findByText('Sections')).toBeInTheDocument();
expect(await screen.findByText('1')).toBeInTheDocument();
expect(await screen.findByText('Subsections')).toBeInTheDocument();
expect(await screen.findByText('2')).toBeInTheDocument();
expect(await screen.findByText('Units')).toBeInTheDocument();
expect(await screen.findByText('3')).toBeInTheDocument();
expect(await screen.findByText('Components')).toBeInTheDocument();
expect(await screen.findByText('8')).toBeInTheDocument();
expect(markAnalysisComplete).toHaveBeenCalledWith(true);
});
});