editor.js/test/cypress/tests/modules/Ui.cy.ts
Peter Savchenko 2ab9eb13bc
feat(block-events): delete keydown handling added (#2402)
* feat(block-events): delete keydown logic added

* chore(ui-events): delete keydown will remove selected blocks

* backspace tests added

* delete keydown tests

* tests for ui added

* fix ci

* separate block events tests for several files

* Delete BlockEvents.cy.ts

* rm unused change

* add code-review fixes + corner cases handling

* Update blockEvents.ts

* allow merging only same type blocks
2023-07-06 23:45:12 +03:00

97 lines
2.4 KiB
TypeScript

import type EditorJS from '../../../../types/index';
describe('Ui module', function () {
describe('documentKeydown', function () {
describe('Backspace', function () {
it('should remove selected blocks', function () {
cy.createEditor({
data: {
blocks: [
{
id: 'block1',
type: 'paragraph',
data: {
text: 'The first block',
},
},
{
id: 'block2',
type: 'paragraph',
data: {
text: 'The second block',
},
},
],
},
}).as('editorInstance');
/**
* Select two blocks by shift+down
*/
cy.get('[data-cy=editorjs]')
.find('.ce-paragraph')
.first()
.click()
.type('{shift+downArrow}')
.type('{backspace}');
cy.get<EditorJS>('@editorInstance')
.then(async (editor) => {
const { blocks } = await editor.save();
/**
* Actually editor will contain 1 empty block, but save wont return it since it is empty
*/
expect(blocks.length).to.eq(0);
});
});
});
describe('Delete', function () {
it('should remove selected blocks', function () {
cy.createEditor({
data: {
blocks: [
{
id: 'block1',
type: 'paragraph',
data: {
text: 'The first block',
},
},
{
id: 'block2',
type: 'paragraph',
data: {
text: 'The second block',
},
},
],
},
}).as('editorInstance');
/**
* Select two blocks by shift+down
*/
cy.get('[data-cy=editorjs]')
.find('.ce-paragraph')
.first()
.click()
.type('{shift+downArrow}')
.type('{del}');
cy.get<EditorJS>('@editorInstance')
.then(async (editor) => {
const { blocks } = await editor.save();
/**
* Actually editor will contain 1 empty block, but save wont return it since it is empty
*/
expect(blocks.length).to.eq(0);
});
});
});
});
});