浏览代码

Update restricted editing exception attribute toggle tests with desired behavior.

Maciej Gołaszewski 6 年之前
父节点
当前提交
12877e9dfe
共有 1 个文件被更改,包括 28 次插入2 次删除
  1. 28 2
      packages/ckeditor5-restricted-editing/tests/restrictededitingexceptioncommand.js

+ 28 - 2
packages/ckeditor5-restricted-editing/tests/restrictededitingexceptioncommand.js

@@ -135,13 +135,39 @@ describe( 'RestrictedEditingExceptionCommand', () => {
 				expect( getData( model ) ).to.equal( '<p>abc<$text restrictedEditingException="true">[]foobar</$text>baz</p>' );
 			} );
 
-			it( 'should remove exception when selection is at the end of restricted text', () => {
+			it( 'should remove selection attribute if selection does not have it (selection at the beginning)', () => {
+				setData( model, '<p>abc<$text restrictedEditingException="true">[]foobar</$text>baz</p>' );
+
+				model.change( writer => {
+					writer.setSelectionAttribute( 'restrictedEditingException', 'true' );
+				} );
+
+				command.execute();
+
+				expect( model.document.selection.hasAttribute( 'restrictedEditingException' ) ).to.be.false;
+				expect( getData( model ) ).to.equal( '<p>abc<$text restrictedEditingException="true">[]foobar</$text>baz</p>' );
+			} );
+
+			it( 'should not remove exception when selection is at the end of restricted text', () => {
 				setData( model, '<p>abc<$text restrictedEditingException="true">foobar[]</$text>baz</p>' );
 
 				command.execute();
 
 				expect( model.document.selection.hasAttribute( 'restrictedEditingException' ) ).to.be.false;
-				expect( getData( model ) ).to.equal( '<p>abcfoobar[]baz</p>' );
+				expect( getData( model ) ).to.equal( '<p>abc<$text restrictedEditingException="true">foobar[]</$text>baz</p>' );
+			} );
+
+			it( 'should set selection attribute if selection does not have it (selection at the end)', () => {
+				setData( model, '<p>abc<$text restrictedEditingException="true">foobar[]</$text>baz</p>' );
+
+				model.change( writer => {
+					writer.removeSelectionAttribute( 'restrictedEditingException' );
+				} );
+
+				command.execute();
+
+				expect( model.document.selection.hasAttribute( 'restrictedEditingException' ) ).to.be.true;
+				expect( getData( model ) ).to.equal( '<p>abc<$text restrictedEditingException="true">foobar[]</$text>baz</p>' );
 			} );
 		} );