Skip to content

Commit 6111ded

Browse files
committed
test: Tests added for getBlockTypeBlockV1
1 parent 1b5c85c commit 6111ded

3 files changed

Lines changed: 23 additions & 32 deletions

File tree

src/data/api.mocks.ts

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ export async function mockGetMigrationStatus(migrationId: string): Promise<api.M
1414
return new Promise(() => {});
1515
case mockGetMigrationStatus.migrationIdInProgress:
1616
return mockGetMigrationStatus.migrationStatusInProgressData;
17-
case mockGetMigrationStatus.migrationIdPartial:
18-
return mockGetMigrationStatus.migrationStatusPartialData;
1917
default:
2018
/* istanbul ignore next */
2119
throw new Error(`mockGetMigrationStatus: unknown migration ID "${migrationId}"`);
@@ -180,33 +178,4 @@ mockGetMigrationStatus.migrationStatusInProgressData = {
180178
},
181179
],
182180
} as api.MigrateTaskStatusData;
183-
mockGetMigrationStatus.migrationIdPartial = '7';
184-
mockGetMigrationStatus.migrationStatusPartialData = {
185-
uuid: mockGetMigrationStatus.migrationIdPartial,
186-
state: 'Succeeded',
187-
stateText: 'Succeeded',
188-
completedSteps: 9,
189-
totalSteps: 9,
190-
attempts: 1,
191-
created: '',
192-
modified: '',
193-
artifacts: [],
194-
parameters: [
195-
{
196-
id: 1,
197-
source: 'legacy-lib-1',
198-
target: 'lib',
199-
compositionLevel: 'component',
200-
repeatHandlingStrategy: 'update',
201-
preserveUrlSlugs: false,
202-
targetCollectionSlug: 'coll-1',
203-
forwardSourceToTarget: true,
204-
isFailed: false,
205-
targetCollection: {
206-
key: 'coll',
207-
title: 'Test Collection',
208-
},
209-
},
210-
],
211-
} as api.MigrateTaskStatusData;
212181
mockGetMigrationStatus.applyMock = () => jest.spyOn(api, 'getModulestoreMigrationStatus').mockImplementation(mockGetMigrationStatus);

src/generic/key-utils.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
buildCollectionUsageKey,
33
ContainerType,
44
getBlockType,
5+
getBlockTypeBlockV1,
56
getLibraryId,
67
isLibraryKey,
78
isLibraryV1Key,
@@ -142,4 +143,25 @@ describe('component utils', () => {
142143
});
143144
}
144145
});
146+
147+
describe('getBlockTypeBlockV1', () => {
148+
for (const [input, expected] of [
149+
['block-v1:org+type@html+block@1', 'html'],
150+
['block-v1:OpenCraftX+type@html+block@1571fe018-f3ce-45c9-8f53-5dafcb422fdd', 'html'],
151+
['block-v1:Axim+type@problem+block@571fe018-f3ce-45c9-8f53-5dafcb422fdd', 'problem'],
152+
['block-v1:org+type@unit+block@1', 'unit'],
153+
['block-v1:org+type@section+block@1', 'section'],
154+
['block-v1:org+type@subsection+block@1', 'subsection'],
155+
]) {
156+
it(`returns '${expected}' for usage key '${input}'`, () => {
157+
expect(getBlockTypeBlockV1(input)).toStrictEqual(expected);
158+
});
159+
}
160+
161+
for (const input of ['', undefined, null, 'not a key', 'block-v1:foo']) {
162+
it(`throws an exception for usage key '${input}'`, () => {
163+
expect(() => getBlockTypeBlockV1(input as any)).toThrow(`Invalid usageKey: ${input}`);
164+
});
165+
}
166+
});
145167
});

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ describe('', () => {
139139
hits: libraryComponentsMock,
140140
});
141141

142-
render(mockGetMigrationStatus.migrationIdPartial);
142+
render(mockGetMigrationStatus.migrationId);
143143
expect(await screen.findByText(/partial import successful/i)).toBeInTheDocument();
144144

145145
expect(await screen.findByText(/Total Blocks/i)).toBeInTheDocument();

0 commit comments

Comments
 (0)