mirror of
https://github.com/codex-team/editor.js
synced 2024-06-04 06:52:42 +02:00
a88dc8e30b
* 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>
65 lines
1.8 KiB
TypeScript
65 lines
1.8 KiB
TypeScript
/**
|
|
* This file contains custom commands for Cypress.
|
|
* Also it can override the existing commands.
|
|
*
|
|
* --------------------------------------------------
|
|
*/
|
|
|
|
import type { EditorConfig } from './../../../types/index';
|
|
import type EditorJS from '../../../types/index';
|
|
import Chainable = Cypress.Chainable;
|
|
|
|
/**
|
|
* Create a wrapper and initialize the new instance of editor.js
|
|
* Then return the instance
|
|
*
|
|
* @param editorConfig - config to pass to the editor
|
|
* @returns EditorJS - created instance
|
|
*/
|
|
Cypress.Commands.add('createEditor', (editorConfig: EditorConfig = {}): Chainable<EditorJS> => {
|
|
return cy.window()
|
|
.then((window) => {
|
|
return new Promise((resolve: (instance: EditorJS) => void) => {
|
|
const editorContainer = window.document.createElement('div');
|
|
|
|
editorContainer.setAttribute('id', 'editorjs');
|
|
editorContainer.dataset.cy = 'editorjs';
|
|
editorContainer.style.border = '1px dotted #388AE5';
|
|
|
|
window.document.body.appendChild(editorContainer);
|
|
|
|
const editorInstance: EditorJS = new window.EditorJS(editorConfig);
|
|
|
|
editorInstance.isReady.then(() => {
|
|
resolve(editorInstance);
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|
|
/**
|
|
* Paste command to dispatch paste event
|
|
*
|
|
* @usage
|
|
* cy.get('div').paste({'text/plain': 'Text', 'text/html': '<b>Text</b>'})
|
|
*
|
|
* @param data - map with MIME type as a key and data as value
|
|
*/
|
|
Cypress.Commands.add('paste', {
|
|
prevSubject: true,
|
|
}, (subject, data: {[type: string]: string}) => {
|
|
const pasteEvent = Object.assign(new Event('paste', {
|
|
bubbles: true,
|
|
cancelable: true,
|
|
}), {
|
|
clipboardData: {
|
|
getData: (type): string => data[type],
|
|
types: Object.keys(data),
|
|
},
|
|
});
|
|
|
|
subject[0].dispatchEvent(pasteEvent);
|
|
|
|
return subject;
|
|
});
|