8
0
Quellcode durchsuchen

Add tests for errors thrown by mention command.

Maciej Gołaszewski vor 6 Jahren
Ursprung
Commit
b2fbc22d76
1 geänderte Dateien mit 29 neuen und 1 gelöschten Zeilen
  1. 29 1
      packages/ckeditor5-mention/tests/mentioncommand.js

+ 29 - 1
packages/ckeditor5-mention/tests/mentioncommand.js

@@ -7,6 +7,7 @@ import ModelTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/modeltestedit
 import { setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
 import { setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
 
 
 import MentionCommand from '../src/mentioncommand';
 import MentionCommand from '../src/mentioncommand';
+import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
 
 
 describe( 'MentionCommand', () => {
 describe( 'MentionCommand', () => {
 	let editor, command, model, doc, selection;
 	let editor, command, model, doc, selection;
@@ -53,7 +54,7 @@ describe( 'MentionCommand', () => {
 		} );
 		} );
 	} );
 	} );
 
 
-	describe( 'execute()', () => {
+	describe.only( 'execute()', () => {
 		it( 'inserts mention object if mention was passed as string', () => {
 		it( 'inserts mention object if mention was passed as string', () => {
 			setData( model, '<paragraph>foo @Jo[]bar</paragraph>' );
 			setData( model, '<paragraph>foo @Jo[]bar</paragraph>' );
 
 
@@ -134,6 +135,33 @@ describe( 'MentionCommand', () => {
 			assertMention( textNode, '@John' );
 			assertMention( textNode, '@John' );
 			expect( textNode.hasAttribute( 'bold' ) ).to.be.true;
 			expect( textNode.hasAttribute( 'bold' ) ).to.be.true;
 		} );
 		} );
+
+		it( 'should throw if marker is not one character', () => {
+			setData( model, '<paragraph>foo @Jo[]bar</paragraph>' );
+
+			const testCases = [
+				{ marker: '##', mention: '##foo' },
+				{ marker: '', mention: '@foo' },
+			];
+
+			for ( const options of testCases ) {
+				expect( () => command.execute( options ) ).to.throw( CKEditorError, /markercommand-incorrect-marker/ );
+			}
+		} );
+
+		it( 'should throw if marker does not match mention id', () => {
+			setData( model, '<paragraph>foo @Jo[]bar</paragraph>' );
+
+			const testCases = [
+				{ marker: '@', mention: 'foo' },
+				{ marker: '@', mention: { id: 'foo' } },
+				{ marker: '@', mention: { id: '#foo' } }
+			];
+
+			for ( const options of testCases ) {
+				expect( () => command.execute( options ) ).to.throw( CKEditorError, /markercommand-incorrect-id/ );
+			}
+		} );
 	} );
 	} );
 
 
 	function assertMention( textNode, id ) {
 	function assertMention( textNode, id ) {