mirror of
https://github.com/codex-team/editor.js
synced 2024-05-07 08:56:48 +02:00
2d89105670
* Add internal wrappers for tools classes * FIx lint * Change tools collections to map * Apply some more refactoring * Make tool instance private field * Add some docs * Fix eslint * Basic implementation for Block Tunes * Small fix for demo * Review changes * Fix * Add common tunes and ToolsCollection class * Fixes after review * Rename tools collections * Readonly fix * Some fixes after review * Apply suggestions from code review Co-authored-by: Peter Savchenko <specc.dev@gmail.com> * Fixes after review * Add docs and changelog * Update docs/block-tunes.md Co-authored-by: Peter Savchenko <specc.dev@gmail.com> * Apply suggestions from code review Co-authored-by: Peter Savchenko <specc.dev@gmail.com> * Update src/components/block/index.ts Co-authored-by: Murod Khaydarov <murod.haydarov@gmail.com> * [Dev] Tools utils tests (#1602) * Add tests for tools utils and coverage report * Fix eslint * Adjust test * Add more tests * Update after code review * Fix test & bump version Co-authored-by: Peter Savchenko <specc.dev@gmail.com> Co-authored-by: Murod Khaydarov <murod.haydarov@gmail.com>
186 lines
4.5 KiB
TypeScript
186 lines
4.5 KiB
TypeScript
import ToolsCollection from '../../../../src/components/tools/collection';
|
|
import BlockTool from '../../../../src/components/tools/block';
|
|
import InlineTool from '../../../../src/components/tools/inline';
|
|
import BlockTune from '../../../../src/components/tools/tune';
|
|
import BaseTool from '../../../../src/components/tools/base';
|
|
|
|
const FakeTool = {
|
|
isBlock(): boolean {
|
|
return false;
|
|
},
|
|
isInline(): boolean {
|
|
return false;
|
|
},
|
|
isTune(): boolean {
|
|
return false;
|
|
},
|
|
isInternal: false,
|
|
};
|
|
|
|
const FakeBlockTool = {
|
|
...FakeTool,
|
|
isBlock(): boolean {
|
|
return true;
|
|
},
|
|
};
|
|
|
|
const FakeInlineTool = {
|
|
...FakeTool,
|
|
isInline(): boolean {
|
|
return true;
|
|
},
|
|
};
|
|
|
|
const FakeBlockTune = {
|
|
...FakeTool,
|
|
isTune(): boolean {
|
|
return true;
|
|
},
|
|
};
|
|
|
|
/**
|
|
* Unit tests for ToolsCollection class
|
|
*/
|
|
describe('ToolsCollection', (): void => {
|
|
let collection;
|
|
|
|
/**
|
|
* Mock for Tools in collection
|
|
*/
|
|
const fakeTools = [
|
|
['block1', FakeBlockTool],
|
|
['inline1', FakeInlineTool],
|
|
['block2', {
|
|
...FakeBlockTool,
|
|
isInternal: true,
|
|
} ],
|
|
['tune1', FakeBlockTune],
|
|
['block3', FakeBlockTool],
|
|
['inline2', {
|
|
...FakeInlineTool,
|
|
isInternal: true,
|
|
} ],
|
|
['tune2', FakeBlockTune],
|
|
['tune3', {
|
|
...FakeBlockTune,
|
|
isInternal: true,
|
|
} ],
|
|
['block3', FakeInlineTool],
|
|
['block4', FakeBlockTool],
|
|
];
|
|
|
|
beforeEach((): void => {
|
|
collection = new ToolsCollection(fakeTools as any);
|
|
});
|
|
|
|
it('should be instance of Map', (): void => {
|
|
expect(collection instanceof Map).to.be.true;
|
|
});
|
|
|
|
context('.blockTools', (): void => {
|
|
it('should return new instance of ToolsCollection', (): void => {
|
|
expect(collection.blockTools instanceof ToolsCollection).to.be.true;
|
|
});
|
|
|
|
it('result should contain only block tools', (): void => {
|
|
expect(
|
|
Array
|
|
.from(
|
|
collection.blockTools.values()
|
|
)
|
|
.every((tool: BlockTool) => tool.isBlock())
|
|
).to.be.true;
|
|
});
|
|
});
|
|
|
|
context('.inlineTools', (): void => {
|
|
it('should return new instance of ToolsCollection', (): void => {
|
|
expect(collection.inlineTools instanceof ToolsCollection).to.be.true;
|
|
});
|
|
|
|
it('result should contain only inline tools', (): void => {
|
|
expect(
|
|
Array
|
|
.from(
|
|
collection.inlineTools.values()
|
|
)
|
|
.every((tool: InlineTool) => tool.isInline())
|
|
).to.be.true;
|
|
});
|
|
});
|
|
|
|
context('.blockTunes', (): void => {
|
|
it('should return new instance of ToolsCollection', (): void => {
|
|
expect(collection.blockTunes instanceof ToolsCollection).to.be.true;
|
|
});
|
|
|
|
it('result should contain only block tools', (): void => {
|
|
expect(
|
|
Array
|
|
.from(
|
|
collection.blockTunes.values()
|
|
)
|
|
.every((tool: BlockTune) => tool.isTune())
|
|
).to.be.true;
|
|
});
|
|
});
|
|
|
|
context('.internalTools', (): void => {
|
|
it('should return new instance of ToolsCollection', (): void => {
|
|
expect(collection.internalTools instanceof ToolsCollection).to.be.true;
|
|
});
|
|
|
|
it('result should contain only internal tools', (): void => {
|
|
expect(
|
|
Array
|
|
.from(
|
|
collection.internalTools.values()
|
|
)
|
|
.every((tool: BaseTool) => tool.isInternal)
|
|
).to.be.true;
|
|
});
|
|
});
|
|
|
|
context('.externalTools', (): void => {
|
|
it('should return new instance of ToolsCollection', (): void => {
|
|
expect(collection.externalTools instanceof ToolsCollection).to.be.true;
|
|
});
|
|
|
|
it('result should contain only external tools', (): void => {
|
|
expect(
|
|
Array
|
|
.from(
|
|
collection.externalTools.values()
|
|
)
|
|
.every((tool: BaseTool) => !tool.isInternal)
|
|
).to.be.true;
|
|
});
|
|
});
|
|
|
|
context('mixed access', (): void => {
|
|
context('.blockTunes.internalTools', (): void => {
|
|
it('should return only internal tunes', (): void => {
|
|
expect(
|
|
Array
|
|
.from(
|
|
collection.blockTunes.internalTools.values()
|
|
)
|
|
.every((tool: BlockTune) => tool.isTune() && tool.isInternal)
|
|
).to.be.true;
|
|
});
|
|
});
|
|
|
|
context('.externalTools.blockTools', (): void => {
|
|
it('should return only external block tools', (): void => {
|
|
expect(
|
|
Array
|
|
.from(
|
|
collection.externalTools.blockTools.values()
|
|
)
|
|
.every((tool: BlockTool) => tool.isBlock() && !tool.isInternal)
|
|
).to.be.true;
|
|
});
|
|
});
|
|
});
|
|
});
|