Skip to content
This repository was archived by the owner on Feb 14, 2025. It is now read-only.

Commit

Permalink
test: some tests for formatblocks util
Browse files Browse the repository at this point in the history
  • Loading branch information
johnvente committed Jan 18, 2024
1 parent 15f00a8 commit 2dcc8a6
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions src/editors/sharedComponents/InsertLinkModal/utils.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
addPathToBlocks,
formatBlocks,
getSectionsList,
getChildrenFromList,
filterBlocksByText,
Expand Down Expand Up @@ -65,6 +66,69 @@ describe('utils', () => {
});
});

describe('formatBlocks', () => {
const mockBlocks = {
blockRoot: {
id: 'blockRoot',
blockId: 'edx_block-1',
lmsWebUrl: 'http://localhost/weburl',
legacyWebUrl: 'http://localhost/legacy',
studentViewUrl: 'http://localhost/studentview',
type: 'character',
displayName: 'Any display name',
children: ['block1', 'block2'],
},
block1: {
id: 'block1',
blockId: 'edx_block-1',
lmsWebUrl: 'http://localhost/weburl',
legacyWebUrl: 'http://localhost/legacy',
studentViewUrl: 'http://localhost/studentview',
displayName: 'Block children 1',
type: 'sequential',
},
block2: {
id: 'block2',
blockId: 'edx_block-2',
lmsWebUrl: 'http://localhost/weburl',
legacyWebUrl: 'http://localhost/legacy',
studentViewUrl: 'http://localhost/studentview',
type: 'sequential',
displayName: 'Block children 2',
},
};

test('correctly formats blocks with path information', () => {
const formattedBlocks = formatBlocks(mockBlocks, 'blockRoot');
expect(formattedBlocks.block1.path).toBeDefined();
expect(formattedBlocks.block2.path).toBeDefined();
});

test('correctly assigns parentId to blocks', () => {
const formattedBlocks = formatBlocks(mockBlocks, 'blockRoot');
expect(formattedBlocks.block1.parentId).toBeDefined();
expect(formattedBlocks.block2.parentId).toBeDefined();
});

test('returns an empty object when blocks are empty', () => {
const formattedBlocks = formatBlocks({}, 'blockRoot');
expect(formattedBlocks).toEqual({});
});

test('handles invalid input gracefully', () => {
const formattedBlocks = formatBlocks(mockBlocks, 'nonExistingRoot');
expect(formattedBlocks.blockRoot.parentId).toBeNull();
expect(formattedBlocks.block1.parentId).toBeNull();
expect(formattedBlocks.block2.parentId).toBeNull();
});

test('maintains the original structure of blocks', () => {
const formattedBlocks = formatBlocks(mockBlocks, 'blockRoot');
expect(formattedBlocks.block1.id).toEqual('block1');
expect(formattedBlocks.block1.displayName).toEqual('Block children 1');
});
});

describe('getSectionsList function', () => {
test('returns an empty array for an empty blocks object', () => {
const result = getSectionsList({});
Expand Down

0 comments on commit 2dcc8a6

Please sign in to comment.