Skip to content

Commit 0804a84

Browse files
committed
style: Nits in the code
1 parent 58acdb2 commit 0804a84

5 files changed

Lines changed: 208 additions & 225 deletions

File tree

src/generic/key-utils.test.ts

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import {
22
buildCollectionUsageKey,
33
ContainerType,
44
getBlockType,
5-
getBlockTypeBlockV1,
65
getLibraryId,
76
isLibraryKey,
87
isLibraryV1Key,
@@ -19,13 +18,19 @@ describe('component utils', () => {
1918
['lct:org:lib:unit:my-unit-9284e2', 'unit'],
2019
['lct:org:lib:section:my-section-9284e2', 'section'],
2120
['lct:org:lib:subsection:my-section-9284e2', 'subsection'],
21+
['block-v1:org+type@html+block@1', 'html'],
22+
['block-v1:OpenCraftX+type@html+block@1571fe018-f3ce-45c9-8f53-5dafcb422fdd', 'html'],
23+
['block-v1:Axim+type@problem+block@571fe018-f3ce-45c9-8f53-5dafcb422fdd', 'problem'],
24+
['block-v1:org+type@unit+block@1', 'unit'],
25+
['block-v1:org+type@section+block@1', 'section'],
26+
['block-v1:org+type@subsection+block@1', 'subsection'],
2227
]) {
2328
it(`returns '${expected}' for usage key '${input}'`, () => {
2429
expect(getBlockType(input)).toStrictEqual(expected);
2530
});
2631
}
2732

28-
for (const input of ['', undefined, null, 'not a key', 'lb:foo']) {
33+
for (const input of ['', undefined, null, 'not a key', 'lb:foo', 'block-v1:foo']) {
2934
it(`throws an exception for usage key '${input}'`, () => {
3035
expect(() => getBlockType(input as any)).toThrow(`Invalid usageKey: ${input}`);
3136
});
@@ -143,25 +148,4 @@ describe('component utils', () => {
143148
});
144149
}
145150
});
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-
});
167151
});

src/generic/key-utils.ts

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
/**
2-
* Given a usage key like `lb:org:lib:html:id`, get the type (e.g. `html`)
3-
* @param usageKey e.g. `lb:org:lib:html:id`
2+
* Given a usage key like `lb:org:lib:html:id` or `block-v1:org+type@html+block@1`, get the type (e.g. `html`)
3+
* @param usageKey e.g. `lb:org:lib:html:id`, `block-v1:org+type@html+block@1`
44
* @returns The block type as a string
55
*/
66
export function getBlockType(usageKey: string): string {
7-
if (usageKey && (usageKey.startsWith('lb:') || usageKey.startsWith('lct:'))) {
8-
const blockType = usageKey.split(':')[3];
9-
if (blockType) {
10-
return blockType;
7+
if (usageKey) {
8+
if (usageKey.startsWith('lb:') || usageKey.startsWith('lct:')) {
9+
const blockType = usageKey.split(':')[3];
10+
if (blockType) {
11+
return blockType;
12+
}
13+
} else if (usageKey.startsWith('block-v1:')) {
14+
const blockType = usageKey.match(/type@([^+]+)/);
15+
if (blockType) {
16+
return blockType[1];
17+
}
1118
}
1219
}
1320
throw new Error(`Invalid usageKey: ${usageKey}`);
@@ -126,18 +133,3 @@ export function normalizeContainerType(containerType: ContainerType | string) {
126133
return containerType;
127134
}
128135
}
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1137,7 +1137,7 @@ export async function mockGetCourseImports(libraryId: string): ReturnType<typeof
11371137
mockGetCourseImports.libraryId = mockContentLibrary.libraryId;
11381138
mockGetCourseImports.emptyLibraryId = mockContentLibrary.libraryId2;
11391139
mockGetCourseImports.succeedImport = {
1140-
taskUuid: '1',
1140+
taskUuid: '2d35e36b-1234-1234-1234-123456789000',
11411141
source: {
11421142
key: 'course-v1:edX+DemoX+2025_T1',
11431143
displayName: 'DemoX 2025 T1',

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const render = (migrationTaskId: string) => (
5656
)
5757
);
5858

59-
describe('', () => {
59+
describe('<ImportDetailsPage />', () => {
6060
beforeEach(() => {
6161
const newMocks = initializeMocks();
6262
axiosMock = newMocks.axiosMock;

0 commit comments

Comments
 (0)