mirror of
https://github.com/codex-team/editor.js
synced 2024-05-19 06:47:16 +02:00
b7b00fd060
* block onchange stash * improve block filtration * update tool root * chore(block): remove willSelect und willUnselect * onchange events batching * get rid of CustomEvent extension, create custom event map instead * improve types of EventsDispatcher * fix tests * custom sinon + chai matchers * improve tests, add mutex for fake cursor * add test for fake-cursor mutex * test for batch filtering * fix caret setting by enter press at the end of the block * test for detectToolRootChange * remove resolved todos * changelog added * fix tests * Update CHANGELOG.md * rename FakeCursorAboutToBeSet -> FakeCursorAboutToBeToggled * update didMutated statements * move inputs cache clearing to a separate method * rm Record inheritance from Event maps * add type alisases * rename isElementContainsFakeCursor -> isFakeCursorInsideContainer * improve code style
70 lines
1.6 KiB
TypeScript
70 lines
1.6 KiB
TypeScript
import EditorJS from '../../../../types';
|
|
import { BlockChangedMutationType } from '../../../../types/events/block/BlockChanged';
|
|
|
|
/**
|
|
* There will be described test cases of BlockAPI
|
|
*/
|
|
describe('BlockAPI', () => {
|
|
const firstBlock = {
|
|
id: 'bwnFX5LoX7',
|
|
type: 'paragraph',
|
|
data: {
|
|
text: 'The first block content mock.',
|
|
},
|
|
};
|
|
const editorDataMock = {
|
|
blocks: [
|
|
firstBlock,
|
|
],
|
|
};
|
|
|
|
/**
|
|
* EditorJS API is passed as the first parameter of the onChange callback
|
|
*/
|
|
const EditorJSApiMock = Cypress.sinon.match.any;
|
|
|
|
/**
|
|
* Creates Editor instance
|
|
*
|
|
* @param [data] - data to render
|
|
*/
|
|
function createEditor(data = undefined): void {
|
|
const config = {
|
|
onChange: (api, event): void => {
|
|
console.log('something changed', event);
|
|
},
|
|
data,
|
|
};
|
|
|
|
cy.spy(config, 'onChange').as('onChange');
|
|
|
|
cy.createEditor(config).as('editorInstance');
|
|
}
|
|
|
|
/**
|
|
* block.dispatchChange();
|
|
*/
|
|
describe('.dispatchChange()', () => {
|
|
/**
|
|
* Check that blocks.dispatchChange() triggers Editor 'onChange' callback
|
|
*/
|
|
it('should trigger onChange with corresponded block', () => {
|
|
createEditor(editorDataMock);
|
|
|
|
cy.get<EditorJS>('@editorInstance')
|
|
.then(async (editor) => {
|
|
const block = editor.blocks.getById(firstBlock.id);
|
|
|
|
block.dispatchChange();
|
|
|
|
cy.get('@onChange').should('be.calledWithMatch', EditorJSApiMock, Cypress.sinon.match({
|
|
type: BlockChangedMutationType,
|
|
detail: {
|
|
index: 0,
|
|
},
|
|
}));
|
|
});
|
|
});
|
|
});
|
|
});
|