2025-05-04 19:53:24 +03:00

57 lines
1.3 KiB
TypeScript

import { describe, expect, it, beforeEach, afterEach } from 'vitest';
import { ClassicEditor, Essentials, Paragraph, Heading } from 'ckeditor5';
import Math from '../src/math.js';
describe( 'Math', () => {
it( 'should be named', () => {
expect( Math.pluginName ).to.equal( 'Math' );
} );
describe( 'init()', () => {
let domElement: HTMLElement, editor: ClassicEditor;
beforeEach( async () => {
domElement = document.createElement( 'div' );
document.body.appendChild( domElement );
editor = await ClassicEditor.create( domElement, {
licenseKey: 'GPL',
plugins: [
Paragraph,
Heading,
Essentials,
Math
],
toolbar: [
'math'
]
} );
} );
afterEach( () => {
domElement.remove();
return editor.destroy();
} );
it( 'should load Math', () => {
const myPlugin = editor.plugins.get( 'Math' );
expect( myPlugin ).to.be.an.instanceof( Math );
} );
it( 'should add an icon to the toolbar', () => {
expect( editor.ui.componentFactory.has( 'math' ) ).to.equal( true );
} );
it( 'should add a text into the editor after clicking the icon', () => {
const icon = editor.ui.componentFactory.create( 'math' );
expect( editor.getData() ).to.equal( '' );
icon.fire( 'execute' );
expect( editor.getData() ).to.equal( '<p>Hello CKEditor 5!</p>' );
} );
} );
} );