Skip to content

Commit

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

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

view.destroy();
}

Expand Down
20 changes: 17 additions & 3 deletions packages/ckeditor5-editor-balloon/tests/ballooneditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ describe( 'BalloonEditor', () => {
} );
} );

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

it( 'pushes BalloonToolbar to the list of plugins', () => {
expect( editor.config.get( 'plugins' ) ).to.include( BalloonToolbar );
} );
Expand Down Expand Up @@ -102,28 +107,37 @@ describe( 'BalloonEditor', () => {
} );

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 BalloonEditor( editorElement );

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

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

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 BalloonEditor( '<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 BalloonEditor( 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-balloon/tests/ballooneditorui.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ describe( 'BalloonEditorUI', () => {
} );
} );

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

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

0 comments on commit d3c9967

Please sign in to comment.