Skip to content

Commit

Permalink
Add missing editor.destroy calls to classic-editor plugin tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Mati365 committed Sep 23, 2024
1 parent d3c9967 commit b132a52
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
6 changes: 5 additions & 1 deletion packages/ckeditor5-editor-classic/src/classiceditorui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,11 @@ export default class ClassicEditorUI extends EditorUI {
const editingView = this.editor.editing.view;

this._elementReplacer.restore();
editingView.detachDomRoot( view.editable.name! );

if ( editingView.getDomRoot( view.editable.name! ) ) {
editingView.detachDomRoot( view.editable.name! );
}

view.destroy();
}

Expand Down
34 changes: 29 additions & 5 deletions packages/ckeditor5-editor-classic/tests/classiceditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ describe( 'ClassicEditor', () => {
editor = new ClassicEditor( editorElement );
} );

afterEach( async () => {
if ( editor.state !== 'destroyed' ) {
editor.fire( 'ready' );
await editor.destroy();
}
} );

it( 'uses HTMLDataProcessor', () => {
expect( editor.data.processor ).to.be.instanceof( HtmlDataProcessor );
} );
Expand Down Expand Up @@ -102,16 +109,19 @@ describe( 'ClassicEditor', () => {
} );

describe( 'automatic toolbar items groupping', () => {
it( 'should be on by default', () => {
it( 'should be on by default', async () => {
const editorElement = document.createElement( 'div' );
const editor = new ClassicEditor( editorElement );

expect( editor.ui.view.toolbar.options.shouldGroupWhenFull ).to.be.true;

editor.fire( 'ready' );
await editor.destroy();

editorElement.remove();
} );

it( 'can be disabled using config.toolbar.shouldNotGroupWhenFull', () => {
it( 'can be disabled using config.toolbar.shouldNotGroupWhenFull', async () => {
const editorElement = document.createElement( 'div' );
const editor = new ClassicEditor( editorElement, {
toolbar: {
Expand All @@ -121,34 +131,48 @@ describe( 'ClassicEditor', () => {

expect( editor.ui.view.toolbar.options.shouldGroupWhenFull ).to.be.false;

editor.fire( 'ready' );
await editor.destroy();

editorElement.remove();
} );
} );
} );

describe( 'config.initialData', () => {
it( 'if not set, is set using DOM element data', () => {
it( 'if not set, is set using DOM element data', async () => {
const editorElement = document.createElement( 'div' );
editorElement.innerHTML = '<p>Foo</p>';

const editor = new ClassicEditor( editorElement );

expect( editor.config.get( 'initialData' ) ).to.equal( '<p>Foo</p>' );

editor.fire( 'ready' );
await editor.destroy();

editorElement.remove();
} );

it( 'if not set, is set using data passed in constructor', () => {
it( 'if not set, is set using data passed in constructor', async () => {
const editor = new ClassicEditor( '<p>Foo</p>' );

expect( editor.config.get( 'initialData' ) ).to.equal( '<p>Foo</p>' );

editor.fire( 'ready' );
await editor.destroy();
} );

it( 'if set, is not overwritten with DOM element data', () => {
it( 'if set, is not overwritten with DOM element data', async () => {
const editorElement = document.createElement( 'div' );
editorElement.innerHTML = '<p>Foo</p>';

const editor = new ClassicEditor( editorElement, { initialData: '<p>Bar</p>' } );

expect( editor.config.get( 'initialData' ) ).to.equal( '<p>Bar</p>' );

editor.fire( 'ready' );
await editor.destroy();
} );

it( 'it should throw if config.initialData is set and initial data is passed in constructor', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/ckeditor5-editor-classic/tests/classiceditorui.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ describe( 'ClassicEditorUI', () => {
} );
} );

afterEach( () => {
editor.destroy();
afterEach( async () => {
await editor.destroy();
} );

describe( 'constructor()', () => {
Expand Down

0 comments on commit b132a52

Please sign in to comment.