Sfoglia il codice sorgente

Added tests for getLabeledColorInputCreator().

Aleksander Nowodzinski 5 anni fa
parent
commit
cb2cdf201d

+ 1 - 2
packages/ckeditor5-table/src/utils/ui/table-properties.js

@@ -370,8 +370,7 @@ export function getLabeledColorInputCreator( options ) {
 			labeledFieldView.errorText = null;
 		} );
 
-		// TODO
-		labeledFieldView.bind( 'isEmpty', 'isFocused' ).to( inputView._inputView );
+		labeledFieldView.bind( 'isEmpty', 'isFocused' ).to( inputView );
 
 		return inputView;
 	};

+ 96 - 1
packages/ckeditor5-table/tests/utils/ui/table-properties.js

@@ -11,6 +11,8 @@ import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
 import View from '@ckeditor/ckeditor5-ui/src/view';
 import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
 
+import LabeledFieldView from '@ckeditor/ckeditor5-ui/src/labeledfield/labeledfieldview';
+import ColorInputView from '../../../src/ui/colorinputview';
 import ToolbarView from '@ckeditor/ckeditor5-ui/src/toolbar/toolbarview';
 
 import {
@@ -21,7 +23,8 @@ import {
 	lengthFieldValidator,
 	lineWidthFieldValidator,
 	colorFieldValidator,
-	fillToolbar
+	fillToolbar,
+	getLabeledColorInputCreator
 } from '../../../src/utils/ui/table-properties';
 import Collection from '@ckeditor/ckeditor5-utils/src/collection';
 import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
@@ -338,5 +341,97 @@ describe( 'table utils', () => {
 				expect( view.someProperty ).to.equal( '' );
 			} );
 		} );
+
+		describe( 'getLabeledColorInputCreator()', () => {
+			let creator, labeledField;
+
+			const colorConfig = [
+				{
+					color: 'hsl(180, 75%, 60%)',
+					label: 'Turquoise'
+				},
+				{
+					color: 'hsl(210, 75%, 60%)',
+					label: 'Light blue'
+				}
+			];
+
+			beforeEach( () => {
+				creator = getLabeledColorInputCreator( {
+					colorConfig,
+					columns: 3
+				} );
+
+				labeledField = new LabeledFieldView( { t: () => {} }, creator );
+			} );
+
+			afterEach( () => {
+				labeledField.destroy();
+			} );
+
+			it( 'should return a function', () => {
+				expect( creator ).to.be.a( 'function' );
+			} );
+
+			it( 'should pass the options.colorConfig on', () => {
+				expect( labeledField.fieldView.options.colorDefinitions ).to.have.length( 2 );
+			} );
+
+			it( 'should pass the options.columns on', () => {
+				expect( labeledField.fieldView.options.columns ).to.equal( 3 );
+			} );
+
+			it( 'should return a ColorInputView instance', () => {
+				expect( labeledField.fieldView ).to.be.instanceOf( ColorInputView );
+			} );
+
+			it( 'should set ColorInputView#id', () => {
+				expect( labeledField.fieldView.id ).to.match( /^ck-labeled-field-view-.+/ );
+			} );
+
+			it( 'should set ColorInputView#ariaDescribedById', () => {
+				expect( labeledField.fieldView.ariaDescribedById ).to.match( /^ck-labeled-field-view-status-.+/ );
+			} );
+
+			it( 'should bind ColorInputView#isReadOnly to LabeledFieldView#isEnabled', () => {
+				labeledField.isEnabled = true;
+				expect( labeledField.fieldView.isReadOnly ).to.be.false;
+
+				labeledField.isEnabled = false;
+				expect( labeledField.fieldView.isReadOnly ).to.be.true;
+			} );
+
+			it( 'should bind ColorInputView#hasError to LabeledFieldView#errorText', () => {
+				labeledField.errorText = 'foo';
+				expect( labeledField.fieldView.hasError ).to.be.true;
+
+				labeledField.errorText = null;
+				expect( labeledField.fieldView.hasError ).to.be.false;
+			} );
+
+			it( 'should clear labeld field view #errorText upon #input event', () => {
+				labeledField.errorText = 'foo';
+
+				labeledField.fieldView.fire( 'input' );
+
+				expect( labeledField.errorText ).to.be.null;
+			} );
+
+			it( 'should bind LabeledFieldView#isEmpty to the ColorInputView instance', () => {
+				labeledField.fieldView.isEmpty = true;
+				expect( labeledField.isEmpty ).to.be.true;
+
+				labeledField.fieldView.isEmpty = false;
+				expect( labeledField.isEmpty ).to.be.false;
+			} );
+
+			it( 'should bind LabeledFieldView#isFocused to the ColorInputView instance', () => {
+				labeledField.fieldView.isFocused = true;
+				expect( labeledField.isFocused ).to.be.true;
+
+				labeledField.fieldView.isFocused = false;
+				expect( labeledField.isFocused ).to.be.false;
+			} );
+		} );
 	} );
 } );