Bladeren bron

Tests: Add toolbar button behavior tests.

Maciej Gołaszewski 8 jaren geleden
bovenliggende
commit
2b07758d3c

+ 2 - 2
packages/ckeditor5-highlight/src/highlightui.js

@@ -262,11 +262,11 @@ function bindIconStyle( dropdownView, model ) {
 
 	iconView.extendTemplate( {
 		attributes: {
-			style: bind.to( 'style' )
+			style: bind.to( 'color', color => `color:${ color }` )
 		}
 	} );
 
-	iconView.bind( 'style' ).to( model, 'color', color => `color:${ color }` );
+	iconView.bind( 'color' ).to( model, 'color' );
 }
 
 // Returns icon for given highlighter type.

+ 42 - 0
packages/ckeditor5-highlight/tests/highlightui.js

@@ -121,6 +121,48 @@ describe( 'HighlightUI', () => {
 			expect( toolbar.items.map( item => item.isOn ) ).to.deep.equal( [ false, true, false, false, false, undefined, false ] );
 		} );
 
+		describe( 'toolbar button behavior', () => {
+			let button, buttons, options;
+
+			beforeEach( () => {
+				button = dropdown.buttonView;
+				buttons = dropdown.toolbarView.items.map( b => b );
+				options = editor.config.get( 'highlight.options' );
+			} );
+
+			function validateButton( which ) {
+				expect( button.icon ).to.equal( buttons[ which ].icon );
+				expect( button.buttonView.iconView.color ).to.equal( options[ which ].color );
+			}
+
+			it( 'should have properties of first defined highlighter', () => {
+				validateButton( 0 );
+			} );
+
+			it( 'should change button on selection', () => {
+				command.value = 'redPen';
+
+				validateButton( 3 );
+
+				command.value = undefined;
+
+				validateButton( 0 );
+			} );
+
+			it( 'should change button on execute option', () => {
+				command.value = 'marker';
+				validateButton( 0 );
+
+				buttons[ 4 ].fire( 'execute' );
+				command.value = 'bluePen';
+
+				// Simulate selection moved to not highlighted text.
+				command.value = undefined;
+
+				validateButton( 4 );
+			} );
+		} );
+
 		describe( 'model to command binding', () => {
 			it( 'isEnabled', () => {
 				command.isEnabled = false;