Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Tests: Added UI tests that check the UI destruction order and editor …
Browse files Browse the repository at this point in the history
…element attributes clean–up.
  • Loading branch information
oleq committed Feb 7, 2019
1 parent 9da1e7c commit 0728249
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions tests/decouplededitorui.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,47 @@ describe( 'DecoupledEditorUI', () => {
} );
} );

describe( 'destroy()', () => {
it( 'detaches the DOM root then destroys the UI view', () => {
return VirtualDecoupledTestEditor.create( '' )
.then( newEditor => {
const destroySpy = sinon.spy( newEditor.ui.view, 'destroy' );
const detachSpy = sinon.spy( newEditor.editing.view, 'detachDomRoot' );

return newEditor.destroy()
.then( () => {
sinon.assert.callOrder( detachSpy, destroySpy );
} );
} );
} );

it( 'restores the editor element back to its original state', () => {
const domElement = document.createElement( 'div' );

domElement.setAttribute( 'foo', 'bar' );
domElement.setAttribute( 'data-baz', 'qux' );
domElement.classList.add( 'foo-class' );

return VirtualDecoupledTestEditor.create( domElement )
.then( newEditor => {
return newEditor.destroy()
.then( () => {
const attributes = {};

for ( const attribute of domElement.attributes ) {
attributes[ attribute.name ] = attribute.value;
}

expect( attributes ).to.deep.equal( {
foo: 'bar',
'data-baz': 'qux',
class: 'foo-class'
} );
} );
} );
} );
} );

describe( 'element()', () => {
it( 'returns correct element instance', () => {
expect( ui.element ).to.equal( viewElement );
Expand Down

0 comments on commit 0728249

Please sign in to comment.