Skip to content

Commit cbee617

Browse files
committed
test: Test for new state in ReviewImportDetails
1 parent 2c76950 commit cbee617

File tree

2 files changed

+152
-63
lines changed

2 files changed

+152
-63
lines changed

src/library-authoring/import-course/stepper/ReviewImportDetails.test.tsx

Lines changed: 151 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import messages from '../messages';
1010
mockContentLibrary.applyMock();
1111
const { libraryId } = mockContentLibrary;
1212
const markAnalysisComplete = jest.fn();
13+
const setImportIsBlocked = jest.fn();
1314

1415
// Mock the useCourseDetails hook
1516
jest.mock('@src/course-outline/data/apiHooks', () => ({
@@ -50,7 +51,11 @@ describe('ReviewImportDetails', () => {
5051
});
5152

5253
it('renders loading spinner when isPending is true', async () => {
53-
render(<ReviewImportDetails markAnalysisComplete={markAnalysisComplete} courseId="test-course-id" />);
54+
render(<ReviewImportDetails
55+
markAnalysisComplete={markAnalysisComplete}
56+
courseId="test-course-id"
57+
setImportIsBlocked={setImportIsBlocked}
58+
/>);
5459

5560
const spinners = await screen.findAllByRole('status');
5661
spinners.every((spinner) => expect(spinner.textContent).toEqual('Loading...'));
@@ -68,7 +73,11 @@ describe('ReviewImportDetails', () => {
6873
data: null,
6974
});
7075

71-
render(<ReviewImportDetails markAnalysisComplete={markAnalysisComplete} courseId="test-course-id" />);
76+
render(<ReviewImportDetails
77+
markAnalysisComplete={markAnalysisComplete}
78+
courseId="test-course-id"
79+
setImportIsBlocked={setImportIsBlocked}
80+
/>);
7281

7382
expect(await screen.findByRole('alert')).toBeInTheDocument();
7483
expect(await screen.findByText(/Import Analysis in Progress/i)).toBeInTheDocument();
@@ -90,12 +99,16 @@ describe('ReviewImportDetails', () => {
9099
}],
91100
},
92101
});
93-
(useGetBlockTypes as jest.Mock).mockReturnValueOnce({
102+
(useGetBlockTypes as jest.Mock).mockReturnValue({
94103
isPending: false,
95104
data: { html: 1 },
96105
});
97106

98-
render(<ReviewImportDetails markAnalysisComplete={markAnalysisComplete} courseId="test-course-id" />);
107+
render(<ReviewImportDetails
108+
markAnalysisComplete={markAnalysisComplete}
109+
courseId="test-course-id"
110+
setImportIsBlocked={setImportIsBlocked}
111+
/>);
99112

100113
expect(await screen.findByRole('alert')).toBeInTheDocument();
101114
expect(await screen.findByText(/Import Analysis Completed: Reimport/i)).toBeInTheDocument();
@@ -117,18 +130,40 @@ describe('ReviewImportDetails', () => {
117130
isPending: false,
118131
data: null,
119132
});
120-
(useGetBlockTypes as jest.Mock).mockReturnValueOnce({
121-
isPending: false,
122-
data: {
123-
chapter: 1,
124-
sequential: 2,
125-
vertical: 3,
126-
'problem-builder': 1,
127-
html: 1,
128-
},
133+
(useGetBlockTypes as jest.Mock).mockImplementation((args) => {
134+
// Block types query for children of unsupported blocks
135+
if (args.length === 2) {
136+
return {
137+
isPending: false,
138+
data: {},
139+
};
140+
}
141+
142+
// Block types query from the course
143+
if (args[0] === 'context_key = "test-course-id"') {
144+
return {
145+
isPending: false,
146+
data: {
147+
chapter: 1,
148+
sequential: 2,
149+
vertical: 3,
150+
'problem-builder': 1,
151+
html: 1,
152+
},
153+
};
154+
}
155+
156+
return {
157+
isPending: true,
158+
data: null,
159+
};
129160
});
130161

131-
render(<ReviewImportDetails markAnalysisComplete={markAnalysisComplete} courseId="test-course-id" />);
162+
render(<ReviewImportDetails
163+
markAnalysisComplete={markAnalysisComplete}
164+
courseId="test-course-id"
165+
setImportIsBlocked={setImportIsBlocked}
166+
/>);
132167

133168
expect(await screen.findByRole('alert')).toBeInTheDocument();
134169
expect(await screen.findByText(/Import Analysis Complete/i)).toBeInTheDocument();
@@ -158,35 +193,48 @@ describe('ReviewImportDetails', () => {
158193
isPending: false,
159194
data: null,
160195
});
161-
(useGetBlockTypes as jest.Mock).mockReturnValueOnce({
162-
isPending: false,
163-
data: {
164-
chapter: 1,
165-
sequential: 2,
166-
vertical: 3,
167-
'problem-builder': 1,
168-
html: 25,
169-
},
196+
(useGetBlockTypes as jest.Mock).mockImplementation((args) => {
197+
// Block types query for children of unsupported blocks
198+
if (args.length === 2) {
199+
return {
200+
isPending: false,
201+
data: {},
202+
};
203+
}
204+
205+
// Block types query from the course
206+
if (args[0] === 'context_key = "test-course-id"') {
207+
return {
208+
isPending: false,
209+
data: {
210+
chapter: 1,
211+
sequential: 2,
212+
vertical: 3,
213+
'problem-builder': 1,
214+
html: 25,
215+
},
216+
};
217+
}
218+
219+
return {
220+
isPending: true,
221+
data: null,
222+
};
170223
});
171224

172-
render(<ReviewImportDetails markAnalysisComplete={markAnalysisComplete} courseId="test-course-id" />);
225+
render(<ReviewImportDetails
226+
markAnalysisComplete={markAnalysisComplete}
227+
courseId="test-course-id"
228+
setImportIsBlocked={setImportIsBlocked}
229+
/>);
173230

174231
expect(await screen.findByRole('alert')).toBeInTheDocument();
175-
expect(await screen.findByText(/Import Analysis Complete/i)).toBeInTheDocument();
232+
expect(await screen.findByText(/Import Blocked/i)).toBeInTheDocument();
176233
expect(await screen.findByText(
177-
/18.75% of content cannot be imported. For details see below./i,
234+
/This import would exceed the Content Library limit of 20 items/i,
178235
)).toBeInTheDocument();
179-
expect(await screen.findByText(/Total Blocks/i)).toBeInTheDocument();
180-
expect(await screen.findByText('26/32')).toBeInTheDocument();
181-
expect(await screen.findByText('Sections')).toBeInTheDocument();
182-
expect(await screen.findByText('1')).toBeInTheDocument();
183-
expect(await screen.findByText('Subsections')).toBeInTheDocument();
184-
expect(await screen.findByText('2')).toBeInTheDocument();
185-
expect(await screen.findByText('Units')).toBeInTheDocument();
186-
expect(await screen.findByText('3')).toBeInTheDocument();
187-
expect(await screen.findByText('Components')).toBeInTheDocument();
188-
expect(await screen.findByText('20/26')).toBeInTheDocument();
189236
expect(markAnalysisComplete).toHaveBeenCalledWith(true);
237+
expect(setImportIsBlocked).toHaveBeenCalledWith(true);
190238
});
191239

192240
it('considers children blocks of unsupportedBlocks', async () => {
@@ -206,24 +254,43 @@ describe('ReviewImportDetails', () => {
206254
estimatedTotalHits: 1,
207255
},
208256
});
209-
(useGetBlockTypes as jest.Mock).mockReturnValueOnce({
210-
isPending: false,
211-
data: {
212-
chapter: 1,
213-
sequential: 2,
214-
vertical: 3,
215-
library_content: 1,
216-
html: 1,
217-
problem: 4,
218-
},
219-
}).mockReturnValueOnce({
220-
isPending: false,
221-
data: {
222-
problem: 2,
223-
},
257+
(useGetBlockTypes as jest.Mock).mockImplementation((args) => {
258+
// Block types query for children of unsupported blocks
259+
if (args.length === 2) {
260+
return {
261+
isPending: false,
262+
data: {
263+
problem: 2,
264+
},
265+
};
266+
}
267+
268+
// Block types query from the course
269+
if (args[0] === 'context_key = "test-course-id"') {
270+
return {
271+
isPending: false,
272+
data: {
273+
chapter: 1,
274+
sequential: 2,
275+
vertical: 3,
276+
library_content: 1,
277+
html: 1,
278+
problem: 4,
279+
},
280+
};
281+
}
282+
283+
return {
284+
isPending: true,
285+
data: null,
286+
};
224287
});
225288

226-
render(<ReviewImportDetails markAnalysisComplete={markAnalysisComplete} courseId="test-course-id" />);
289+
render(<ReviewImportDetails
290+
markAnalysisComplete={markAnalysisComplete}
291+
courseId="test-course-id"
292+
setImportIsBlocked={setImportIsBlocked}
293+
/>);
227294

228295
expect(await screen.findByRole('alert')).toBeInTheDocument();
229296
expect(await screen.findByText(/Import Analysis Complete/i)).toBeInTheDocument();
@@ -253,18 +320,40 @@ describe('ReviewImportDetails', () => {
253320
isPending: false,
254321
data: null,
255322
});
256-
(useGetBlockTypes as jest.Mock).mockReturnValueOnce({
257-
isPending: false,
258-
data: {
259-
chapter: 1,
260-
sequential: 2,
261-
vertical: 3,
262-
html: 5,
263-
problem: 3,
264-
},
323+
(useGetBlockTypes as jest.Mock).mockImplementation((args) => {
324+
// Block types query for children of unsupported blocks
325+
if (args.length === 2) {
326+
return {
327+
isPending: false,
328+
data: {},
329+
};
330+
}
331+
332+
// Block types query from the course
333+
if (args[0] === 'context_key = "test-course-id"') {
334+
return {
335+
isPending: false,
336+
data: {
337+
chapter: 1,
338+
sequential: 2,
339+
vertical: 3,
340+
html: 5,
341+
problem: 3,
342+
},
343+
};
344+
}
345+
346+
return {
347+
isPending: true,
348+
data: null,
349+
};
265350
});
266351

267-
render(<ReviewImportDetails markAnalysisComplete={markAnalysisComplete} courseId="test-course-id" />);
352+
render(<ReviewImportDetails
353+
markAnalysisComplete={markAnalysisComplete}
354+
courseId="test-course-id"
355+
setImportIsBlocked={setImportIsBlocked}
356+
/>);
268357

269358
expect(await screen.findByRole('alert')).toBeInTheDocument();
270359
expect(await screen.findByText(

src/library-authoring/import-course/stepper/ReviewImportDetails.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ export const ReviewImportDetails = ({
212212
},
213213
0,
214214
) - finalUnsupportedBlocks;
215-
}, [blockTypes, finalUnsupportedBlocks, libraryBlockLimits]);
215+
}, [blockTypes, finalUnsupportedBlocks]);
216216

217217
/** Calculate the unsupported block percentage based on the final total blocks and unsupported blocks. */
218218
const unsupportedBlockPercentage = useMemo(() => {

0 commit comments

Comments
 (0)