Explorar o código

Tests: Update localization tests.

Maciej Gołaszewski %!s(int64=8) %!d(string=hai) anos
pai
achega
d3b891320f

+ 4 - 4
packages/ckeditor5-highlight/src/highlightediting.js

@@ -30,10 +30,10 @@ export default class HighlightEditing extends Plugin {
 		editor.config.define( 'highlight', {
 			options: [
 				{ model: 'marker', class: 'marker', title: 'Marker', color: '#ffff66', type: 'marker' },
-				{ model: 'greenMarker', class: 'marker-green', title: 'Green Marker', color: '#66ff00', type: 'marker' },
-				{ model: 'pinkMarker', class: 'marker-pink', title: 'Pink Marker', color: '#ff6fff', type: 'marker' },
-				{ model: 'redPen', class: 'pen-red', title: 'Red Pen', color: '#ff2929', type: 'pen' },
-				{ model: 'bluePen', class: 'pen-blue', title: 'Blue Pen', color: '#0091ff', type: 'pen' }
+				{ model: 'greenMarker', class: 'marker-green', title: 'Green marker', color: '#66ff00', type: 'marker' },
+				{ model: 'pinkMarker', class: 'marker-pink', title: 'Pink marker', color: '#ff6fff', type: 'marker' },
+				{ model: 'redPen', class: 'pen-red', title: 'Red pen', color: '#ff2929', type: 'pen' },
+				{ model: 'bluePen', class: 'pen-blue', title: 'Blue pen', color: '#0091ff', type: 'pen' }
 			]
 		} );
 	}

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

@@ -34,6 +34,33 @@ import './../theme/highlight.css';
  * @extends module:core/plugin~Plugin
  */
 export default class HighlightUI extends Plugin {
+	/**
+	 * Returns the localized option titles provided by the plugin.
+	 *
+	 * The following localized titles corresponding with default
+	 * {@link module:highlight/highlight~HighlightConfig#options} are available:
+	 *
+	 * * `'Marker'`,
+	 * * `'Green marker'`,
+	 * * `'Pink marker'`,
+	 * * `'Blue pen'`.
+	 * * `'Red pen'`.
+	 *
+	 * @readonly
+	 * @type {Object.<String,String>}
+	 */
+	get localizedOptionTitles() {
+		const t = this.editor.t;
+
+		return {
+			'Marker': t( 'Marker' ),
+			'Green marker': t( 'Green marker' ),
+			'Pink marker': t( 'Pink marker' ),
+			'Red pen': t( 'Red pen' ),
+			'Blue pen': t( 'Blue pen' )
+		};
+	}
+
 	/**
 	 * @inheritDoc
 	 */
@@ -113,8 +140,10 @@ export default class HighlightUI extends Plugin {
 		editor.ui.componentFactory.add( name, locale => {
 			const buttonView = new ButtonView( locale );
 
+			const localized = this.localizedOptionTitles[ label ] ? this.localizedOptionTitles[ label ] : label;
+
 			buttonView.set( {
-				label,
+				label: localized,
 				icon,
 				tooltip: true
 			} );
@@ -214,8 +243,10 @@ export default class HighlightUI extends Plugin {
 				}
 			} );
 
+			splitButtonView.delegate( 'execute' ).to( dropdownView );
+
 			// Execute current action from dropdown's split button action button.
-			dropdownView.buttonView.on( 'execute', () => {
+			dropdownView.on( 'execute', () => {
 				editor.execute( 'highlight', { value: model.commandValue } );
 				editor.editing.view.focus();
 			} );

+ 4 - 4
packages/ckeditor5-highlight/tests/highlightediting.js

@@ -86,10 +86,10 @@ describe( 'HighlightEditing', () => {
 				expect( editor.config.get( 'highlight' ) ).to.deep.equal( {
 					options: [
 						{ model: 'marker', class: 'marker', title: 'Marker', color: '#ffff66', type: 'marker' },
-						{ model: 'greenMarker', class: 'marker-green', title: 'Green Marker', color: '#66ff00', type: 'marker' },
-						{ model: 'pinkMarker', class: 'marker-pink', title: 'Pink Marker', color: '#ff6fff', type: 'marker' },
-						{ model: 'redPen', class: 'pen-red', title: 'Red Pen', color: '#ff2929', type: 'pen' },
-						{ model: 'bluePen', class: 'pen-blue', title: 'Blue Pen', color: '#0091ff', type: 'pen' }
+						{ model: 'greenMarker', class: 'marker-green', title: 'Green marker', color: '#66ff00', type: 'marker' },
+						{ model: 'pinkMarker', class: 'marker-pink', title: 'Pink marker', color: '#ff6fff', type: 'marker' },
+						{ model: 'redPen', class: 'pen-red', title: 'Red pen', color: '#ff2929', type: 'pen' },
+						{ model: 'bluePen', class: 'pen-blue', title: 'Blue pen', color: '#0091ff', type: 'pen' }
 					]
 				} );
 			} );

+ 29 - 29
packages/ckeditor5-highlight/tests/highlightui.js

@@ -23,21 +23,23 @@ describe( 'HighlightUI', () => {
 
 	before( () => {
 		addTranslations( 'en', {
-			'Font Size': 'Font Size',
-			'Normal': 'Normal',
-			'Tiny': 'Tiny',
-			'Small': 'Small',
-			'Big': 'Big',
-			'Huge': 'Huge'
+			'Highlight': 'Highlight',
+			'Marker': 'Marker',
+			'Green marker': 'Green marker',
+			'Pink marker': 'Pink marker',
+			'Red pen': 'Red pen',
+			'Blue pen': 'Blue pen',
+			'Remove highlighting': 'Remove highlighting'
 		} );
 
 		addTranslations( 'pl', {
-			'Font Size': 'Rozmiar czcionki',
-			'Normal': 'Normalny',
-			'Tiny': 'Tyci',
-			'Small': 'Mały',
-			'Big': 'Duży',
-			'Huge': 'Ogromny'
+			'Highlight': 'Zakreślacz',
+			'Marker': 'Marker',
+			'Green marker': 'Zielony marker',
+			'Pink marker': 'Różowy marker',
+			'Red pen': 'Czerwony długopis',
+			'Blue pen': 'Niebieski długopis',
+			'Remove highlighting': 'Usuń zaznaczenie'
 		} );
 	} );
 
@@ -86,7 +88,7 @@ describe( 'HighlightUI', () => {
 			expect( dropdown.element.classList.contains( 'ck-highlight-dropdown' ) ).to.be.true;
 		} );
 
-		it.skip( 'should focus view after command execution', () => {
+		it( 'should focus view after command execution', () => {
 			const focusSpy = testUtils.sinon.spy( editor.editing.view, 'focus' );
 
 			dropdown.commandName = 'highlight';
@@ -174,30 +176,31 @@ describe( 'HighlightUI', () => {
 			} );
 		} );
 
-		describe.skip( 'localization', () => {
+		describe( 'localization', () => {
 			beforeEach( () => {
-				return localizedEditor( [ 'tiny', 'small', 'normal', 'big', 'huge' ] );
+				return localizedEditor();
 			} );
 
 			it( 'works for the #buttonView', () => {
 				const buttonView = dropdown.buttonView;
 
-				expect( buttonView.tooltip ).to.equal( 'Rozmiar czcionki' );
+				expect( buttonView.tooltip ).to.equal( 'Zakreślacz' );
 			} );
 
 			it( 'works for the listView#items in the panel', () => {
-				const listView = dropdown.listView;
-
-				expect( listView.items.map( item => item.label ) ).to.deep.equal( [
-					'Tyci',
-					'Mały',
-					'Normalny',
-					'Duży',
-					'Ogromny'
+				const listView = dropdown.toolbarView;
+
+				expect( listView.items.map( item => item.label ).filter( label => !!label ) ).to.deep.equal( [
+					'Marker',
+					'Zielony marker',
+					'Różowy marker',
+					'Czerwony długopis',
+					'Niebieski długopis',
+					'Usuń zaznaczenie'
 				] );
 			} );
 
-			function localizedEditor( options ) {
+			function localizedEditor() {
 				const editorElement = document.createElement( 'div' );
 				document.body.appendChild( editorElement );
 
@@ -205,10 +208,7 @@ describe( 'HighlightUI', () => {
 					.create( editorElement, {
 						plugins: [ HighlightEditing, HighlightUI ],
 						toolbar: [ 'highlight' ],
-						language: 'pl',
-						highlight: {
-							options
-						}
+						language: 'pl'
 					} )
 					.then( newEditor => {
 						editor = newEditor;