Skip to content

Commit bd82c1d

Browse files
authored
fix: publish status of container on adding new children (#2587)
Updates publish status of container when adding new child components to a unit or other containers.
1 parent 75ae9d5 commit bd82c1d

File tree

5 files changed

+58
-30
lines changed

5 files changed

+58
-30
lines changed

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/legacy-libraries-migration/messages.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,18 @@ const messages = defineMessages({
6565
id: 'legacy-libraries-migration.select-destination.alert.text',
6666
defaultMessage: 'All content from the'
6767
+ ' {count, plural, one {{count} legacy library} other {{count} legacy libraries}} you selected will'
68-
+ ' be migrated to this new library, organized into collections. Any legacy libraries that are used in'
69-
+ ' problem banks will maintain their link with migrated content the first time they are migrated.',
68+
+ ' be migrated to this new library, organized into collections. Legacy library content used in courses will'
69+
+ ' continue to work as-is. To receive any future changes to migrated content, you must update these'
70+
+ ' references within your course.',
7071
description: 'Alert text in the select destination step of the legacy libraries migration page.',
7172
},
7273
confirmationViewAlert: {
7374
id: 'legacy-libraries-migration.select-destination.alert.text',
74-
defaultMessage: 'These {count, plural, one {{count} legacy library} other {{count} legacy libraries}}'
75-
+ ' will be migrated to <b>{libraryName}</b> and organized as collections. Legacy library content used'
76-
+ ' in courses will continue to work as-is. To receive any future changes to migrated content,'
77-
+ ' you must update these references within your course.',
75+
defaultMessage: 'All content from the'
76+
+ ' {count, plural, one {{count} legacy library} other {{count} legacy libraries}} you selected will'
77+
+ ' be migrated to <b>{libraryName}</b>, organized into collections. Legacy library content used in courses will'
78+
+ ' continue to work as-is. To receive any future changes to migrated content, you must update these'
79+
+ ' references within your course.',
7880
description: 'Alert text in the confirmation step of the legacy libraries migration page.',
7981
},
8082
previouslyMigratedAlert: {

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', () => {

src/library-authoring/data/apiHooks.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,8 @@ export const useAddItemsToContainer = (containerId?: string) => {
817817
// It would be complex to bring the entire hierarchy and only update the items within that hierarchy.
818818
queryClient.invalidateQueries({ queryKey: libraryAuthoringQueryKeys.containerHierarchy(undefined) });
819819
queryClient.invalidateQueries({ queryKey: xblockQueryKeys.componentHierarchy(undefined) });
820+
// Invalidate the container to update its publish status
821+
queryClient.invalidateQueries({ queryKey: libraryAuthoringQueryKeys.container(containerId) });
820822

821823
const containerType = getBlockType(containerId);
822824
if (containerType === 'section') {

0 commit comments

Comments
 (0)