Skip to content

Commit 1b5c85c

Browse files
committed
refactor: Generate the migration summary in the front using migration blocks data
1 parent a9292cc commit 1b5c85c

6 files changed

Lines changed: 177 additions & 119 deletions

File tree

src/data/api.mocks.ts

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,6 @@ mockGetMigrationStatus.migrationStatusData = {
4848
key: 'coll',
4949
title: 'Test Collection',
5050
},
51-
migrationSummary: {
52-
totalBlocks: 6,
53-
sections: 1,
54-
subsections: 1,
55-
units: 1,
56-
components: 3,
57-
unsupported: 0,
58-
},
5951
},
6052
],
6153
} as api.MigrateTaskStatusData;
@@ -82,14 +74,6 @@ mockGetMigrationStatus.migrationStatusFailedData = {
8274
forwardSourceToTarget: true,
8375
isFailed: true,
8476
targetCollection: null,
85-
migrationSummary: {
86-
totalBlocks: 0,
87-
sections: 0,
88-
subsections: 0,
89-
units: 0,
90-
components: 0,
91-
unsupported: 0,
92-
},
9377
},
9478
],
9579
} as api.MigrateTaskStatusData;
@@ -116,14 +100,6 @@ mockGetMigrationStatus.migrationStatusFailedMultipleData = {
116100
forwardSourceToTarget: true,
117101
isFailed: true,
118102
targetCollection: null,
119-
migrationSummary: {
120-
totalBlocks: 0,
121-
sections: 0,
122-
subsections: 0,
123-
units: 0,
124-
components: 0,
125-
unsupported: 0,
126-
},
127103
},
128104
{
129105
id: 2,
@@ -136,14 +112,6 @@ mockGetMigrationStatus.migrationStatusFailedMultipleData = {
136112
forwardSourceToTarget: true,
137113
isFailed: true,
138114
targetCollection: null,
139-
migrationSummary: {
140-
totalBlocks: 0,
141-
sections: 0,
142-
subsections: 0,
143-
units: 0,
144-
components: 0,
145-
unsupported: 0,
146-
},
147115
},
148116
],
149117
} as api.MigrateTaskStatusData;
@@ -170,14 +138,6 @@ mockGetMigrationStatus.migrationStatusFailedOneLibraryData = {
170138
forwardSourceToTarget: true,
171139
isFailed: true,
172140
targetCollection: null,
173-
migrationSummary: {
174-
totalBlocks: 0,
175-
sections: 0,
176-
subsections: 0,
177-
units: 0,
178-
components: 0,
179-
unsupported: 0,
180-
},
181141
},
182142
{
183143
id: 2,
@@ -190,14 +150,6 @@ mockGetMigrationStatus.migrationStatusFailedOneLibraryData = {
190150
forwardSourceToTarget: true,
191151
isFailed: false,
192152
targetCollection: null,
193-
migrationSummary: {
194-
totalBlocks: 0,
195-
sections: 0,
196-
subsections: 0,
197-
units: 0,
198-
components: 0,
199-
unsupported: 0,
200-
},
201153
},
202154
],
203155
} as api.MigrateTaskStatusData;
@@ -225,14 +177,6 @@ mockGetMigrationStatus.migrationStatusInProgressData = {
225177
forwardSourceToTarget: true,
226178
isFailed: false,
227179
targetCollection: null,
228-
migrationSummary: {
229-
totalBlocks: 0,
230-
sections: 0,
231-
subsections: 0,
232-
units: 0,
233-
components: 0,
234-
unsupported: 0,
235-
},
236180
},
237181
],
238182
} as api.MigrateTaskStatusData;
@@ -262,14 +206,6 @@ mockGetMigrationStatus.migrationStatusPartialData = {
262206
key: 'coll',
263207
title: 'Test Collection',
264208
},
265-
migrationSummary: {
266-
totalBlocks: 7,
267-
sections: 1,
268-
subsections: 1,
269-
units: 1,
270-
components: 3,
271-
unsupported: 1,
272-
},
273209
},
274210
],
275211
} as api.MigrateTaskStatusData;

src/data/api.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,6 @@ export interface MigrateParameters {
9797
key: string;
9898
title: string;
9999
} | null;
100-
migrationSummary: {
101-
totalBlocks: number;
102-
sections: number;
103-
subsections: number;
104-
units: number;
105-
components: number;
106-
unsupported: number;
107-
}
108100
}
109101

110102
export interface MigrateTaskStatusData {

src/generic/key-utils.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,18 @@ export function normalizeContainerType(containerType: ContainerType | string) {
126126
return containerType;
127127
}
128128
}
129+
130+
/**
131+
* Given a usage key of V1 block like `block-v1:org+type@html+block@1`, get the type (e.g. `html`)
132+
* @param usageKey e.g. `block-v1:org+type@html+block@1`
133+
* @returns The block type as a string
134+
*/
135+
export function getBlockTypeBlockV1(usageKey: string): string {
136+
if (usageKey && usageKey.startsWith('block-v1:')) {
137+
const blockType = usageKey.match(/type@([^+]+)/);
138+
if (blockType) {
139+
return blockType[1];
140+
}
141+
}
142+
throw new Error(`Invalid usageKey: ${usageKey}`);
143+
}

src/library-authoring/data/api.mocks.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,52 @@ export const mockGetContentLibraryV2List = {
3434
}),
3535
};
3636

37+
export const mockGetModulestoreMigratedBlocksInfo = {
38+
applyMockSuccess: () => jest.spyOn(api, 'getModulestoreMigrationBlocksInfo').mockResolvedValue(
39+
[
40+
{
41+
sourceKey: 'block-v1:UNIX+UX2+2025_T2+type@chapter+block@1',
42+
targetKey: '1',
43+
unsupportedReason: undefined,
44+
},
45+
{
46+
sourceKey: 'block-v1:UNIX+UX2+2025_T2+type@sequential+block@2',
47+
targetKey: '2',
48+
unsupportedReason: undefined,
49+
},
50+
{
51+
sourceKey: 'block-v1:UNIX+UX2+2025_T2+type@vertical+block@2',
52+
targetKey: '3',
53+
unsupportedReason: undefined,
54+
},
55+
{
56+
sourceKey: 'block-v1:UNIX+UX2+2025_T2+type@html+block@3',
57+
targetKey: '4',
58+
unsupportedReason: undefined,
59+
},
60+
],
61+
),
62+
applyMockPartial: () => jest.spyOn(api, 'getModulestoreMigrationBlocksInfo').mockResolvedValue(
63+
[
64+
{
65+
sourceKey: 'block-v1:UNIX+UX2+2025_T2+type@library_content+block@test_lib_content',
66+
targetKey: null,
67+
unsupportedReason: 'The "library_content" XBlock (ID: "test_lib_content") has children, so it not supported in content libraries. It has 2 children blocks.',
68+
},
69+
{
70+
sourceKey: 'block-v1:UNIX+UX2+2025_T2+type@html+block@1',
71+
targetKey: '1',
72+
unsupportedReason: undefined,
73+
},
74+
{
75+
sourceKey: 'block-v1:UNIX+UX2+2025_T2+type@chapter+block@1',
76+
targetKey: '2',
77+
unsupportedReason: undefined,
78+
},
79+
],
80+
),
81+
};
82+
3783
/**
3884
* Mock for `getContentLibrary()`
3985
*

src/library-authoring/import-course/ImportDetailsPage.test.tsx

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ import { bulkModulestoreMigrateUrl } from '@src/data/api';
1010
import { useGetContentHits } from '@src/search-manager';
1111
import { ImportDetailsPage } from './ImportDetailsPage';
1212
import { LibraryProvider } from '../common/context/LibraryContext';
13-
import { mockContentLibrary } from '../data/api.mocks';
14-
import { getModulestoreMigratedBlocksInfoUrl } from '../data/api';
13+
import { mockContentLibrary, mockGetModulestoreMigratedBlocksInfo } from '../data/api.mocks';
1514
import { libraryComponentsMock } from '../__mocks__';
1615

1716
mockContentLibrary.applyMock();
@@ -93,10 +92,13 @@ describe('', () => {
9392
});
9493

9594
it('should render Succeeded state', async () => {
95+
mockGetModulestoreMigratedBlocksInfo.applyMockSuccess();
9696
render(mockGetMigrationStatus.migrationId);
9797
expect(await screen.findByText(
9898
/test course has been imported to your library in a collection called test collection/i,
9999
));
100+
expect(await screen.findByText(/Total Blocks/i)).toBeInTheDocument();
101+
expect(await screen.findByText('4')).toBeInTheDocument();
100102

101103
const viewImportedContentBtn = screen.getByRole('button', {
102104
name: /view imported content/i,
@@ -107,13 +109,7 @@ describe('', () => {
107109
});
108110

109111
it('should render Partial Succeeded state', async () => {
110-
axiosMock.onGet(getModulestoreMigratedBlocksInfoUrl()).reply(200, [
111-
{
112-
sourceKey: 'block-v1:UNIX+UX2+2025_T2+type@library_content+block@test_lib_content',
113-
targetKey: null,
114-
unsupportedReason: 'The "library_content" XBlock (ID: "test_lib_content") has children, so it not supported in content libraries. It has 2 children blocks.',
115-
},
116-
]);
112+
mockGetModulestoreMigratedBlocksInfo.applyMockPartial();
117113
(useGetContentHits as jest.Mock).mockReturnValue({
118114
isPending: false,
119115
data: {
@@ -146,8 +142,13 @@ describe('', () => {
146142
render(mockGetMigrationStatus.migrationIdPartial);
147143
expect(await screen.findByText(/partial import successful/i)).toBeInTheDocument();
148144

149-
expect(screen.getByText(
150-
/85% of course test course has been imported successfully/i,
145+
expect(await screen.findByText(/Total Blocks/i)).toBeInTheDocument();
146+
expect(await screen.findByText('2/5')).toBeInTheDocument();
147+
expect(await screen.findByText(/Components/i)).toBeInTheDocument();
148+
expect(await screen.findByText('1/4')).toBeInTheDocument();
149+
150+
expect(await screen.findByText(
151+
/40% of course test course has been imported successfully/i,
151152
)).toBeInTheDocument();
152153

153154
expect(await screen.findByRole('cell', {

0 commit comments

Comments
 (0)