mirror of
https://github.com/codex-team/editor.js
synced 2024-05-19 06:47:16 +02:00
1320b047a2
* feature: possibilities to merge blocks of different types * fix: remove scope change * feat: use convert config instead of defined property * chore:: use built-in function for type check * fix: remove console.log * chore: remove styling added by mistakes * test: add testing for different blocks types merging * fix: remove unused import * fix: remove type argument * fix: use existing functions for data export * chore: update changelog * fix: re put await * fix: remove unnecessary check * fix: typo in test name * fix: re-add condition for merge * test: add caret position test * fix caret issues, add sanitize * make if-else statement more clear * upgrade cypress * Update cypress.yml * upd cypress to 13 * make sanitize test simpler * patch rc version --------- Co-authored-by: GuillaumeOnepilot <guillaume@onepilot.co> Co-authored-by: Guillaume Leon <97881811+GuillaumeOnepilot@users.noreply.github.com>
119 lines
3.2 KiB
TypeScript
119 lines
3.2 KiB
TypeScript
import type EditorJS from '../../../types/index';
|
|
import { OutputData } from '../../../types/index';
|
|
|
|
|
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
describe('Sanitizing', () => {
|
|
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 => {
|
|
cy.wrap<OutputData>(await editor.save())
|
|
.then((output) => {
|
|
const boldText = output.blocks[0].data.text;
|
|
|
|
expect(boldText).to.eq('<b>Bold text</b>');
|
|
});
|
|
});
|
|
});
|
|
|
|
it('should save formatting for paragraph', () => {
|
|
cy.createEditor({})
|
|
.as('editorInstance');
|
|
|
|
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<EditorJS>('@editorInstance')
|
|
.then(async editorInstance => {
|
|
cy.wrap(await editorInstance.save())
|
|
.then((output) => {
|
|
const text = output.blocks[0].data.text;
|
|
|
|
expect(text).to.match(/<b>This text should be bold\.(<br>)?<\/b>/);
|
|
});
|
|
});
|
|
});
|
|
|
|
it('should save formatting for paragraph on paste', () => {
|
|
cy.createEditor({})
|
|
.as('editorInstance');
|
|
|
|
cy.get('[data-cy=editorjs]')
|
|
.get('div.ce-block')
|
|
.paste({
|
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
'text/html': '<p>Text</p><p><b>Bold text</b></p>',
|
|
});
|
|
|
|
cy.get<EditorJS>('@editorInstance')
|
|
.then(async editorInstance => {
|
|
cy.wrap<OutputData>(await editorInstance.save())
|
|
.then((output) => {
|
|
const boldText = output.blocks[1].data.text;
|
|
|
|
expect(boldText).to.eq('<b>Bold text</b>');
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|
|
it('should sanitize unwanted html on blocks merging', function () {
|
|
cy.createEditor({
|
|
data: {
|
|
blocks: [
|
|
{
|
|
id: 'block1',
|
|
type: 'paragraph',
|
|
data: {
|
|
text: 'First block',
|
|
},
|
|
},
|
|
{
|
|
id: 'paragraph',
|
|
type: 'paragraph',
|
|
data: {
|
|
/**
|
|
* Tool does not support spans in its sanitization config
|
|
*/
|
|
text: 'Second <span id="taint-html">XSS<span> block',
|
|
},
|
|
},
|
|
],
|
|
},
|
|
}).as('editorInstance');
|
|
|
|
cy.get('[data-cy=editorjs]')
|
|
.find('.ce-paragraph')
|
|
.last()
|
|
.click()
|
|
.type('{home}')
|
|
.type('{backspace}');
|
|
|
|
cy.get<EditorJS>('@editorInstance')
|
|
.then(async (editor) => {
|
|
const { blocks } = await editor.save();
|
|
|
|
expect(blocks[0].data.text).to.eq('First blockSecond XSS block'); // text has been merged, span has been removed
|
|
});
|
|
});
|
|
});
|
|
|