8
0
فهرست منبع

Tests: Added the Locale class tests for the new API it offers.

Aleksander Nowodzinski 6 سال پیش
والد
کامیت
e53a382db7
2فایلهای تغییر یافته به همراه40 افزوده شده و 3 حذف شده
  1. 1 1
      packages/ckeditor5-utils/src/locale.js
  2. 39 2
      packages/ckeditor5-utils/tests/locale.js

+ 1 - 1
packages/ckeditor5-utils/src/locale.js

@@ -112,5 +112,5 @@ export default class Locale {
 // @param {String} language The ISO 639-1 language code.
 // @returns {String} 'ltr' or 'rtl
 function getLanguageDirection( languageCode ) {
-	return RTL_LANGUAGE_CODES.includes( languageCode );
+	return RTL_LANGUAGE_CODES.includes( languageCode ) ? 'rtl' : 'ltr';
 }

+ 39 - 2
packages/ckeditor5-utils/tests/locale.js

@@ -13,17 +13,54 @@ describe( 'Locale', () => {
 	} );
 
 	describe( 'constructor', () => {
-		it( 'sets the language', () => {
+		it( 'sets the #language', () => {
 			const locale = new Locale( 'pl' );
 
 			expect( locale ).to.have.property( 'language', 'pl' );
 		} );
 
-		it( 'defaults language to en', () => {
+		it( 'sets the #contentLanguage', () => {
+			const locale = new Locale( 'pl', 'en' );
+
+			expect( locale ).to.have.property( 'language', 'pl' );
+			expect( locale ).to.have.property( 'contentLanguage', 'en' );
+		} );
+
+		it( 'defaults #language to en', () => {
 			const locale = new Locale();
 
 			expect( locale ).to.have.property( 'language', 'en' );
 		} );
+
+		it( 'inherits the #contentLanguage from the #language (if not passed)', () => {
+			const locale = new Locale( 'pl' );
+
+			expect( locale ).to.have.property( 'language', 'pl' );
+			expect( locale ).to.have.property( 'contentLanguage', 'pl' );
+		} );
+
+		it( 'determines the #languageDirection', () => {
+			expect( new Locale( 'pl' ) ).to.have.property( 'languageDirection', 'ltr' );
+			expect( new Locale( 'en' ) ).to.have.property( 'languageDirection', 'ltr' );
+
+			expect( new Locale( 'ar' ) ).to.have.property( 'languageDirection', 'rtl' );
+			expect( new Locale( 'fa' ) ).to.have.property( 'languageDirection', 'rtl' );
+			expect( new Locale( 'he' ) ).to.have.property( 'languageDirection', 'rtl' );
+			expect( new Locale( 'ku' ) ).to.have.property( 'languageDirection', 'rtl' );
+			expect( new Locale( 'ug' ) ).to.have.property( 'languageDirection', 'rtl' );
+		} );
+
+		it( 'determines the #contentLanguageDirection (not passed)', () => {
+			expect( new Locale( 'pl' ) ).to.have.property( 'contentLanguageDirection', 'auto' );
+			expect( new Locale( 'en' ) ).to.have.property( 'contentLanguageDirection', 'auto' );
+			expect( new Locale( 'ar' ) ).to.have.property( 'contentLanguageDirection', 'auto' );
+		} );
+
+		it( 'determines the #contentLanguageDirection (passed)', () => {
+			expect( new Locale( 'pl', 'pl' ) ).to.have.property( 'contentLanguageDirection', 'ltr' );
+			expect( new Locale( 'en', 'ar' ) ).to.have.property( 'contentLanguageDirection', 'rtl' );
+			expect( new Locale( 'ar', 'pl' ) ).to.have.property( 'contentLanguageDirection', 'ltr' );
+		} );
 	} );
 
 	describe( 't', () => {