Skip to content

Commit 4492c63

Browse files
committed
test: update tests
1 parent 2ee751f commit 4492c63

3 files changed

Lines changed: 48 additions & 24 deletions

File tree

src/legacy-libraries-migration/ConfirmationView.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export const ConfirmationView = ({
8181
</Alert>
8282
{legacyLibraries.map((legacyLib) => (
8383
<ConfirmationCard
84+
key={legacyLib.libraryKey}
8485
legacyLib={legacyLib}
8586
destinationName={destination.title}
8687
/>

src/legacy-libraries-migration/LegacyLibMigrationPage.test.tsx

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
render,
77
screen,
88
waitFor,
9+
within,
910
} from '@src/testUtils';
1011
import studioHomeMock from '@src/studio-home/__mocks__/studioHomeMock';
1112
import { mockGetContentLibraryV2List } from '@src/library-authoring/data/api.mocks';
@@ -184,7 +185,7 @@ describe('<LegacyLibMigrationPage />', () => {
184185
nextButton.click();
185186

186187
// Should show alert of SelectDestinationView
187-
expect(await screen.findByText(/any legacy libraries that are used/i)).toBeInTheDocument();
188+
expect(await screen.findByText(/you selected will be migrated to this new library/i)).toBeInTheDocument();
188189

189190
const backButton = screen.getByRole('button', { name: /back/i });
190191
backButton.click();
@@ -210,7 +211,7 @@ describe('<LegacyLibMigrationPage />', () => {
210211
nextButton.click();
211212

212213
// Should show alert of SelectDestinationView
213-
expect(await screen.findByText(/any legacy libraries that are used/i)).toBeInTheDocument();
214+
expect(await screen.findByText(/you selected will be migrated to this new library/i)).toBeInTheDocument();
214215

215216
// The next button is disabled
216217
expect(nextButton).toBeDisabled();
@@ -224,24 +225,31 @@ describe('<LegacyLibMigrationPage />', () => {
224225
});
225226

226227
it('should back to select library destination', async () => {
228+
const user = userEvent.setup();
227229
renderPage();
228230
expect(await screen.findByText('Migrate Legacy Libraries')).toBeInTheDocument();
229231
expect(await screen.findByText('MBA')).toBeInTheDocument();
230232

231233
const legacyLibrary = screen.getByRole('checkbox', { name: 'MBA' });
232-
legacyLibrary.click();
234+
await user.click(legacyLibrary);
233235

234-
const nextButton = screen.getByRole('button', { name: /next/i });
235-
nextButton.click();
236+
const nextButton = await screen.findByRole('button', { name: /next/i });
237+
await user.click(nextButton);
236238

237239
// Should show alert of SelectDestinationView
238-
expect(await screen.findByText(/any legacy libraries that are used/i)).toBeInTheDocument();
240+
expect(await screen.findByText(/you selected will be migrated to this new library/i)).toBeInTheDocument();
239241
expect(await screen.findByText('Test Library 1')).toBeInTheDocument();
240242
const radioButton = screen.getByRole('radio', { name: /test library 1/i });
241-
radioButton.click();
243+
await user.click(radioButton);
242244

243-
nextButton.click();
244-
expect(await screen.findByText(/these 1 legacy library will be migrated to/i)).toBeInTheDocument();
245+
await user.click(nextButton);
246+
const alert = await screen.findByRole('alert');
247+
expect(await within(alert).findByText(
248+
/All content from the 1 legacy library you selected will be migrated to/i,
249+
)).toBeInTheDocument();
250+
expect(await within(alert).findByText(
251+
/test library 1/i,
252+
)).toBeInTheDocument();
245253

246254
const backButton = screen.getByRole('button', { name: /back/i });
247255
backButton.click();
@@ -269,7 +277,7 @@ describe('<LegacyLibMigrationPage />', () => {
269277
nextButton.click();
270278

271279
// Should show alert of SelectDestinationView
272-
expect(await screen.findByText(/any legacy libraries that are used/i)).toBeInTheDocument();
280+
expect(await screen.findByText(/you selected will be migrated to this new library/i)).toBeInTheDocument();
273281

274282
const createButton = await screen.findByRole('button', { name: /create new library/i });
275283
expect(createButton).toBeInTheDocument();
@@ -336,18 +344,24 @@ describe('<LegacyLibMigrationPage />', () => {
336344
legacyLibrary3.click();
337345

338346
const nextButton = screen.getByRole('button', { name: /next/i });
339-
nextButton.click();
347+
await user.click(nextButton);
340348

341349
// Should show alert of SelectDestinationView
342-
expect(await screen.findByText(/any legacy libraries that are used/i)).toBeInTheDocument();
350+
expect(await screen.findByText(/you selected will be migrated to this new library/i)).toBeInTheDocument();
343351
expect(await screen.findByText('Test Library 1')).toBeInTheDocument();
344352
const radioButton = screen.getByRole('radio', { name: /test library 1/i });
345-
radioButton.click();
353+
await user.click(radioButton);
346354

347-
nextButton.click();
355+
await user.click(nextButton);
348356

349357
// Should show alert of ConfirmationView
350-
expect(await screen.findByText(/these 3 legacy libraries will be migrated to/i)).toBeInTheDocument();
358+
const alert = await screen.findByRole('alert');
359+
expect(await within(alert).findByText(
360+
/All content from the 3 legacy libraries you selected will be migrated to/i,
361+
)).toBeInTheDocument();
362+
expect(await within(alert).findByText(
363+
/test library 1/i,
364+
)).toBeInTheDocument();
351365
expect(screen.getByText('MBA')).toBeInTheDocument();
352366
expect(screen.getByText('Legacy library 1')).toBeInTheDocument();
353367
expect(screen.getByText('MBA 1')).toBeInTheDocument();
@@ -390,18 +404,26 @@ describe('<LegacyLibMigrationPage />', () => {
390404
legacyLibrary3.click();
391405

392406
const nextButton = screen.getByRole('button', { name: /next/i });
393-
nextButton.click();
407+
await user.click(nextButton);
394408

395409
// Should show alert of SelectDestinationView
396-
expect(await screen.findByText(/any legacy libraries that are used/i)).toBeInTheDocument();
410+
expect(await screen.findByText(/you selected will be migrated to this new library/i)).toBeInTheDocument();
397411
expect(await screen.findByText('Test Library 1')).toBeInTheDocument();
398412
const radioButton = screen.getByRole('radio', { name: /test library 1/i });
399-
radioButton.click();
413+
await user.click(radioButton);
400414

401-
nextButton.click();
415+
await user.click(nextButton);
402416

403417
// Should show alert of ConfirmationView
404-
expect(await screen.findByText(/these 3 legacy libraries will be migrated to/i)).toBeInTheDocument();
418+
const alert = await screen.findByRole('alert');
419+
expect(await within(alert).findByText(
420+
/All content from the 3 legacy libraries you selected will be migrated to /i,
421+
{ exact: false },
422+
)).toBeInTheDocument();
423+
expect(await within(alert).findByText(
424+
/test library 1/i,
425+
{ exact: false },
426+
)).toBeInTheDocument();
405427
expect(screen.getByText('MBA')).toBeInTheDocument();
406428
expect(screen.getByText('Legacy library 1')).toBeInTheDocument();
407429
expect(screen.getByText('MBA 1')).toBeInTheDocument();

src/library-authoring/data/apiHooks.test.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -329,10 +329,11 @@ describe('library api hooks', () => {
329329
// Keys should be invalidated:
330330
// 1. library
331331
// 2. containerChildren
332-
// 3. containerHierarchy
333-
// 4 & 5. subsections
334-
// 6 all hierarchies
335-
expect(spy).toHaveBeenCalledTimes(6);
332+
// 3. container
333+
// 4. containerHierarchy
334+
// 5 & 6. subsections
335+
// 7 all hierarchies
336+
expect(spy).toHaveBeenCalledTimes(7);
336337
});
337338

338339
describe('publishContainer', () => {

0 commit comments

Comments
 (0)