浏览代码

Tests: Add tests to cover setting max-width for toolbar

panr 5 年之前
父节点
当前提交
b946cf5cda
共有 1 个文件被更改,包括 45 次插入5 次删除
  1. 45 5
      packages/ckeditor5-editor-inline/tests/inlineeditorui.js

+ 45 - 5
packages/ckeditor5-editor-inline/tests/inlineeditorui.js

@@ -83,22 +83,62 @@ describe( 'InlineEditorUI', () => {
 			} );
 
 			// https://github.com/ckeditor/ckeditor5-editor-inline/issues/4
-			it( 'pin() is called on editor.ui#update', () => {
+			it( 'pin() is called on editor.ui#update when editable element is in the DOM', () => {
+				const spy = sinon.stub( view.panel, 'pin' );
+
+				viewElement.ownerDocument.body.append( viewElement );
+				view.panel.show();
+
+				expect( viewElement.ownerDocument.body.contains( viewElement ) ).to.be.true;
+
+				editor.ui.fire( 'update' );
+				sinon.assert.calledOnce( spy );
+				sinon.assert.calledWithExactly( spy, {
+					target: view.editable.element,
+					positions: sinon.match.array
+				} );
+			} );
+
+			it( 'pin() is not called on editor.ui#update when panel is hidden', () => {
 				const spy = sinon.stub( view.panel, 'pin' );
 
 				view.panel.hide();
 
 				editor.ui.fire( 'update' );
 				sinon.assert.notCalled( spy );
+			} );
+
+			it( 'pin() is not called on editor.ui#update when panel is visible but editable element is not in the DOM', () => {
+				const spy = sinon.stub( view.panel, 'pin' );
 
 				view.panel.show();
 
+				expect( !viewElement.ownerDocument.body.contains( viewElement ) ).to.be.true;
+
 				editor.ui.fire( 'update' );
+				sinon.assert.notCalled( spy );
+			} );
+
+			it( 'toolbar max-width is set on editor.ui#update only once when editable element is in the DOM', () => {
+				const spy = sinon.spy( editor.ui, '_setToolbarMaxWidth' );
+				testUtils.sinon.stub( viewElement, 'getBoundingClientRect' ).returns( { width: 100 } );
+
+				viewElement.ownerDocument.body.append( viewElement );
+				view.panel.show();
+
+				expect( view.toolbar.element.style.maxWidth ).to.be.equal( '' );
+
+				editor.ui.fire( 'update' );
+
+				expect( view.toolbar.element.style.maxWidth ).to.be.equal( '100px' );
+
+				editor.ui.fire( 'update' );
+
 				sinon.assert.calledOnce( spy );
-				sinon.assert.calledWithExactly( spy, {
-					target: view.editable.element,
-					positions: sinon.match.array
-				} );
+			} );
+
+			it( 'toolbar should group items by default', () => {
+				expect( view.toolbar.options.shouldGroupWhenFull ).to.be.true;
 			} );
 		} );