editor.js/test/cypress/tests/sanitisation.spec.ts
George Berezhnoy a88dc8e30b
refactoring(modules): sanitizer module is util now (#1574)
* refactoring(modules): sanitizer module is util now

* Remove Sanitizer from Editor modules signature

* Bind context to config composition method

* Make sanitizer singletone

* Make sanitizer a module instead of class

* Fix

* Add test cases for default values

* Fix inline tools default value

* Move inline tools and block tunes to BlockTool instance

* Fixes after review & some test cases for sanitisation

* Upgrade test case

Co-authored-by: Peter Savchenko <specc.dev@gmail.com>
2021-04-08 21:17:23 +03:00

66 lines
1.8 KiB
TypeScript

describe('Output sanitisation', () => {
beforeEach(() => {
if (this && this.editorInstance) {
this.editorInstance.destroy();
} else {
cy.createEditor({}).as('editorInstance');
}
});
context('Output should save inline formatting', () => {
it('should save initial formatting for paragraph', () => {
cy.createEditor({
data: {
blocks: [ {
type: 'paragraph',
data: { text: '<b>Bold text</b>' },
} ],
},
}).then(async editor => {
const output = await (editor as any).save();
const boldText = output.blocks[0].data.text;
expect(boldText).to.eq('<b>Bold text</b>');
});
});
it('should save formatting for paragraph', () => {
cy.get('[data-cy=editorjs]')
.get('div.ce-block')
.click()
.type('This text should be bold.{selectall}');
cy.get('[data-cy=editorjs]')
.get('button.ce-inline-tool--bold')
.click();
cy.get('[data-cy=editorjs]')
.get('div.ce-block')
.click();
cy.get('@editorInstance').then(async editorInstance => {
const output = await (editorInstance as any).save();
const text = output.blocks[0].data.text;
expect(text).to.eq('<b>This text should be bold.</b>');
});
});
it('should save formatting for paragraph on paste', () => {
cy.get('[data-cy=editorjs]')
.get('div.ce-block')
.paste({ 'text/html': '<p>Text</p><p><b>Bold text</b></p>' });
cy.get('@editorInstance').then(async editorInstance => {
const output = await (editorInstance as any).save();
const boldText = output.blocks[1].data.text;
expect(boldText).to.eq('<b>Bold text</b>');
});
});
});
});