Przeglądaj źródła

Tests: Added missing test for the message context.

Maciej Bukowski 5 lat temu
rodzic
commit
12ec3b4f20

+ 27 - 1
packages/ckeditor5-utils/tests/locale.js

@@ -136,12 +136,22 @@ describe( 'Locale', () => {
 			} );
 		} );
 
-		it( 'should translate a string to the target ui language', () => {
+		it( 'should translate a message to the target ui language', () => {
 			const t = locale.t;
 
 			expect( t( 'foo' ) ).to.equal( 'foo_pl' );
 		} );
 
+		it( 'should translate a message including the message string and the message context', () => {
+			const t = locale.t;
+
+			addTranslations( 'pl', {
+				'foo_bar': 'foo_bar_pl'
+			} );
+
+			expect( t( { string: 'foo', context: 'bar' } ) ).to.equal( 'foo_bar_pl' );
+		} );
+
 		it( 'should translate a plural form to the target ui language based on the first value and interpolate the string', () => {
 			const t = locale.t;
 
@@ -150,6 +160,22 @@ describe( 'Locale', () => {
 			expect( t( { string: 'bar', plural: '%0 bars' }, [ 5 ] ), 3 ).to.equal( '5 bar_pl_2' );
 		} );
 
+		it( 'should translate a message supporting plural form with a context', () => {
+			const t = locale.t;
+
+			addTranslations( 'pl', {
+				'%1 a space_Add/Remove a space': [ '%1 spację', '%1 %0 spacje', '%1 %0 spacji' ],
+				'Add': 'Dodaj',
+				'Remove': 'Usuń'
+			} );
+
+			const addOrRemoveSpaceMessage = { string: '%1 a space', plural: '%1 %0 spaces', context: 'Add/Remove a space' };
+
+			expect( t( addOrRemoveSpaceMessage, [ 1, t( 'Add' ) ] ), 1 ).to.equal( 'Dodaj spację' );
+			expect( t( addOrRemoveSpaceMessage, [ 2, t( 'Remove' ) ] ), 2 ).to.equal( 'Usuń 2 spacje' );
+			expect( t( addOrRemoveSpaceMessage, [ 5, t( 'Add' ) ] ), 3 ).to.equal( 'Dodaj 5 spacji' );
+		} );
+
 		it( 'should interpolate a message with provided values', () => {
 			const t = locale.t;
 

+ 1 - 1
packages/ckeditor5-utils/tests/translation-service.js

@@ -46,7 +46,7 @@ describe( 'translation-service', () => {
 		} );
 	} );
 
-	describe( 'translate()', () => {
+	describe( '_translate()', () => {
 		it( 'should return translated messages when translations are defined', () => {
 			add( 'pl', {
 				'OK': 'OK',