浏览代码

Tests: Refactoring. Additional tests to check the localization of initial config.heading.formats value.

Aleksander Nowodzinski 8 年之前
父节点
当前提交
7329bb642d
共有 2 个文件被更改,包括 40 次插入13 次删除
  1. 8 6
      packages/ckeditor5-heading/tests/heading.js
  2. 32 7
      packages/ckeditor5-heading/tests/headingengine.js

+ 8 - 6
packages/ckeditor5-heading/tests/heading.js

@@ -9,9 +9,15 @@ import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictest
 import Heading from '../src/heading';
 import HeadingEngine from '../src/headingengine';
 import DropdownView from '@ckeditor/ckeditor5-ui/src/dropdown/dropdownview';
-import Locale from '@ckeditor/ckeditor5-utils/src/locale';
+import { add } from '@ckeditor/ckeditor5-utils/src/translation-service';
 import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
 
+add( 'pl', {
+	'Paragraph': 'Akapit',
+	'Heading 1': 'Nagłówek 1',
+	'Heading 2': 'Nagłówek 2',
+} );
+
 testUtils.createSinonSandbox();
 
 describe( 'Heading', () => {
@@ -98,15 +104,11 @@ describe( 'Heading', () => {
 
 			beforeEach( () => {
 				const editorElement = document.createElement( 'div' );
-				const spy = testUtils.sinon.stub( Locale.prototype, '_t' ).returns( 'foo' );
-
-				spy.withArgs( 'Paragraph' ).returns( 'Akapit' );
-				spy.withArgs( 'Heading 1' ).returns( 'Nagłówek 1' );
-				spy.withArgs( 'Heading 2' ).returns( 'Nagłówek 2' );
 
 				return ClassicTestEditor.create( editorElement, {
 					plugins: [ Heading ],
 					toolbar: [ 'heading' ],
+					lang: 'pl',
 					heading: {
 						formats: [
 							{ id: 'paragraph', element: 'p', label: 'Paragraph' },

+ 32 - 7
packages/ckeditor5-heading/tests/headingengine.js

@@ -8,8 +8,16 @@ import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
 import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
 import HeadingCommand from '../src/headingcommand';
 import Enter from '@ckeditor/ckeditor5-enter/src/enter';
+import { add } from '@ckeditor/ckeditor5-utils/src/translation-service';
 import { getData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
 
+add( 'pl', {
+	'Paragraph': 'Akapit',
+	'Heading 1': 'Nagłówek 1',
+	'Heading 2': 'Nagłówek 2',
+	'Heading 3': 'Nagłówek 3',
+} );
+
 describe( 'HeadingEngine', () => {
 	let editor, document;
 
@@ -95,13 +103,30 @@ describe( 'HeadingEngine', () => {
 
 	describe( 'config', () => {
 		describe( 'formats', () => {
-			it( 'should have default value', () => {
-				expect( editor.config.get( 'heading.formats' ) ).to.deep.equal( [
-					{ id: 'paragraph', element: 'p', label: 'Paragraph' },
-					{ id: 'heading1', element: 'h2', label: 'Heading 1' },
-					{ id: 'heading2', element: 'h3', label: 'Heading 2' },
-					{ id: 'heading3', element: 'h4', label: 'Heading 3' }
-				] );
+			describe( 'default value', () => {
+				it( 'should be set', () => {
+					expect( editor.config.get( 'heading.formats' ) ).to.deep.equal( [
+						{ id: 'paragraph', element: 'p', label: 'Paragraph' },
+						{ id: 'heading1', element: 'h2', label: 'Heading 1' },
+						{ id: 'heading2', element: 'h3', label: 'Heading 2' },
+						{ id: 'heading3', element: 'h4', label: 'Heading 3' }
+					] );
+				} );
+
+				it( 'should be localized', () => {
+					return VirtualTestEditor.create( {
+						plugins: [ Enter, HeadingEngine ],
+						lang: 'pl',
+					} )
+					.then( editor => {
+						expect( editor.config.get( 'heading.formats' ) ).to.deep.equal( [
+							{ id: 'paragraph', element: 'p', label: 'Akapit' },
+							{ id: 'heading1', element: 'h2', label: 'Nagłówek 1' },
+							{ id: 'heading2', element: 'h3', label: 'Nagłówek 2' },
+							{ id: 'heading3', element: 'h4', label: 'Nagłówek 3' }
+						] );
+					} );
+				} );
 			} );
 
 			it( 'should customize formats', () => {