8
0
Просмотр исходного кода

Tests: Added UI tests that check the UI destruction order and editor element attributes clean–up.

Aleksander Nowodzinski 6 лет назад
Родитель
Сommit
1e9d963e64
1 измененных файлов с 41 добавлено и 0 удалено
  1. 41 0
      packages/ckeditor5-editor-inline/tests/inlineeditorui.js

+ 41 - 0
packages/ckeditor5-editor-inline/tests/inlineeditorui.js

@@ -245,6 +245,47 @@ describe( 'InlineEditorUI', () => {
 		} );
 	} );
 
+	describe( 'destroy()', () => {
+		it( 'detaches the DOM root then destroys the UI view', () => {
+			return VirtualInlineTestEditor.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 VirtualInlineTestEditor.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 );