Skip to content

Commit

Permalink
test: Unit tests - refs #253277
Browse files Browse the repository at this point in the history
* feat: add unit tests for utils -refs #253277

* chore: clean-up code -refs #253277

* fix: fix failing test -refs #253277
  • Loading branch information
ana-oprea authored Jun 9, 2023
1 parent 7ea084c commit b5acaa9
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions src/utils.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { cloneColumnsBlockData } from './utils';
import { getBlocks } from '@plone/volto/helpers';
import config from '@plone/volto/registry';

jest.mock('@plone/volto/helpers', () => ({
getBlocks: jest.fn(),
getBlocksFieldname: jest.fn(() => 'blocks'),
getBlocksLayoutFieldname: jest.fn(() => 'blocks_layout'),
}));

describe('cloneColumnsBlockData', () => {
it('should clone the blockData without cloneData', () => {
const mockBlockData = {
data: {
'@type': 'columns',
blocks: {
block1: {
'@type': 'test',
},
},
blocks_layout: {
items: ['block1'],
},
},
};

getBlocks.mockReturnValue([['block1', mockBlockData.data.blocks.block1]]);
config.blocks.blocksConfig = {
test: {},
};
const [id, clonedBlockData] = cloneColumnsBlockData(mockBlockData);
expect(clonedBlockData.data.blocks.block1).toEqual(
mockBlockData.data.blocks.block1,
);
expect(id).not.toBeNull();
});

it('should clone the blockData with cloneData', () => {
const mockBlockData = {
data: {
'@type': 'columns',
blocks: {
block1: {
'@type': 'test',
blocks: {},
},
},
blocks_layout: {
items: ['block1'],
},
},
};

getBlocks.mockReturnValue([['block1', mockBlockData.data.blocks.block1]]);
config.blocks.blocksConfig = {
test: {
cloneData: jest.fn(() => [
'test_uuid',
mockBlockData.data.blocks.block1,
]),
},
};
const [id, clonedBlockData] = cloneColumnsBlockData(mockBlockData);
expect(id).not.toEqual('test_uuid');
expect(clonedBlockData.data.blocks.block1).toEqual(
mockBlockData.data.blocks.block1,
);
expect(clonedBlockData.data.blocks['test_uuid']).toEqual(
mockBlockData.data.blocks.block1,
);
});
});

0 comments on commit b5acaa9

Please sign in to comment.