Browse Source

Tests: Added a test to check what happens if upcasted code block has a class which is not defining (e.g. second in the config).

Aleksander Nowodzinski 6 years ago
parent
commit
68e393c809
1 changed files with 23 additions and 1 deletions
  1. 23 1
      packages/ckeditor5-code-block/tests/codeblockediting.js

+ 23 - 1
packages/ckeditor5-code-block/tests/codeblockediting.js

@@ -1043,13 +1043,14 @@ describe( 'CodeBlockEditing', () => {
 
 			// https://github.com/ckeditor/ckeditor5/issues/5924
 			it( 'should upcast using only the first class from config as a defining language class', () => {
+				// "baz" is the first class configured for the "baz" language.
 				return ClassicTestEditor.create( '<pre><code class="baz">foo</code></pre>', {
 					plugins: [ CodeBlockEditing ],
 					codeBlock: {
 						languages: [
 							{ language: 'foo', label: 'Foo', class: 'foo' },
 							{ language: 'baz', label: 'Baz', class: 'baz bar' },
-							{ language: 'bar', label: 'Bar', class: 'bar' },
+							{ language: 'qux', label: 'Qux', class: 'qux' },
 						]
 					}
 				} ).then( editor => {
@@ -1060,6 +1061,27 @@ describe( 'CodeBlockEditing', () => {
 					return editor.destroy();
 				} );
 			} );
+
+			// https://github.com/ckeditor/ckeditor5/issues/5924
+			it( 'should not upcast if the class is not the first (defining) language class', () => {
+				// "bar" is the second class configured for the "baz" language.
+				return ClassicTestEditor.create( '<pre><code class="bar">foo</code></pre>', {
+					plugins: [ CodeBlockEditing ],
+					codeBlock: {
+						languages: [
+							{ language: 'foo', label: 'Foo', class: 'foo' },
+							{ language: 'baz', label: 'Baz', class: 'baz bar' },
+							{ language: 'qux', label: 'Qux', class: 'qux' },
+						]
+					}
+				} ).then( editor => {
+					model = editor.model;
+
+					expect( getModelData( model ) ).to.equal( '<codeBlock language="foo">[]foo</codeBlock>' );
+
+					return editor.destroy();
+				} );
+			} );
 		} );
 	} );