Bladeren bron

Aligned code to changes in DocumentSelection API.

Maciej Bukowski 7 jaren geleden
bovenliggende
commit
d4ef72e04c
2 gewijzigde bestanden met toevoegingen van 51 en 49 verwijderingen
  1. 30 30
      packages/ckeditor5-list/tests/indentcommand.js
  2. 21 19
      packages/ckeditor5-list/tests/listcommand.js

+ 30 - 30
packages/ckeditor5-list/tests/indentcommand.js

@@ -52,16 +52,16 @@ describe( 'IndentCommand', () => {
 
 		describe( 'isEnabled', () => {
 			it( 'should be true if selection starts in list item', () => {
-				model.change( () => {
-					doc.selection.setCollapsedAt( root.getChild( 5 ) );
+				model.change( writer => {
+					writer.setSelection( root.getChild( 5 ) );
 				} );
 
 				expect( command.isEnabled ).to.be.true;
 			} );
 
 			it( 'should be false if selection starts in first list item', () => {
-				model.change( () => {
-					doc.selection.setCollapsedAt( root.getChild( 0 ) );
+				model.change( writer => {
+					writer.setSelection( root.getChild( 0 ) );
 				} );
 
 				expect( command.isEnabled ).to.be.false;
@@ -106,8 +106,8 @@ describe( 'IndentCommand', () => {
 			} );
 
 			it( 'should be false if selection starts in a list item that has bigger indent than it\'s previous sibling', () => {
-				model.change( () => {
-					doc.selection.setCollapsedAt( root.getChild( 2 ) );
+				model.change( writer => {
+					writer.setSelection( root.getChild( 2 ) );
 				} );
 
 				expect( command.isEnabled ).to.be.false;
@@ -126,8 +126,8 @@ describe( 'IndentCommand', () => {
 
 		describe( 'execute()', () => {
 			it( 'should use parent batch', () => {
-				model.change( () => {
-					doc.selection.setCollapsedAt( root.getChild( 5 ) );
+				model.change( writer => {
+					writer.setSelection( root.getChild( 5 ) );
 				} );
 
 				model.change( writer => {
@@ -140,8 +140,8 @@ describe( 'IndentCommand', () => {
 			} );
 
 			it( 'should increment indent attribute by 1', () => {
-				model.change( () => {
-					doc.selection.setCollapsedAt( root.getChild( 5 ) );
+				model.change( writer => {
+					writer.setSelection( root.getChild( 5 ) );
 				} );
 
 				command.execute();
@@ -158,8 +158,8 @@ describe( 'IndentCommand', () => {
 			} );
 
 			it( 'should increment indent of all sub-items of indented item', () => {
-				model.change( () => {
-					doc.selection.setCollapsedAt( root.getChild( 1 ) );
+				model.change( writer => {
+					writer.setSelection( root.getChild( 1 ) );
 				} );
 
 				command.execute();
@@ -176,11 +176,11 @@ describe( 'IndentCommand', () => {
 			} );
 
 			it( 'should increment indent of all selected item when multiple items are selected', () => {
-				model.change( () => {
-					doc.selection.setRanges( [ new Range(
+				model.change( writer => {
+					writer.setSelection( new Range(
 						new Position( root.getChild( 1 ), [ 0 ] ),
 						new Position( root.getChild( 3 ), [ 1 ] )
-					) ] );
+					) );
 				} );
 
 				command.execute();
@@ -211,8 +211,8 @@ describe( 'IndentCommand', () => {
 
 		describe( 'isEnabled', () => {
 			it( 'should be true if selection starts in list item', () => {
-				model.change( () => {
-					doc.selection.setCollapsedAt( root.getChild( 5 ) );
+				model.change( writer => {
+					writer.setSelection( root.getChild( 5 ) );
 				} );
 
 				expect( command.isEnabled ).to.be.true;
@@ -220,8 +220,8 @@ describe( 'IndentCommand', () => {
 
 			it( 'should be true if selection starts in first list item', () => {
 				// This is in contrary to forward indent command.
-				model.change( () => {
-					doc.selection.setCollapsedAt( root.getChild( 0 ) );
+				model.change( writer => {
+					writer.setSelection( root.getChild( 0 ) );
 				} );
 
 				expect( command.isEnabled ).to.be.true;
@@ -229,8 +229,8 @@ describe( 'IndentCommand', () => {
 
 			it( 'should be true if selection starts in a list item that has bigger indent than it\'s previous sibling', () => {
 				// This is in contrary to forward indent command.
-				model.change( () => {
-					doc.selection.setCollapsedAt( root.getChild( 2 ) );
+				model.change( writer => {
+					writer.setSelection( root.getChild( 2 ) );
 				} );
 
 				expect( command.isEnabled ).to.be.true;
@@ -239,8 +239,8 @@ describe( 'IndentCommand', () => {
 
 		describe( 'execute()', () => {
 			it( 'should decrement indent attribute by 1 (if it is bigger than 0)', () => {
-				model.change( () => {
-					doc.selection.setCollapsedAt( root.getChild( 5 ) );
+				model.change( writer => {
+					writer.setSelection( root.getChild( 5 ) );
 				} );
 
 				command.execute();
@@ -257,8 +257,8 @@ describe( 'IndentCommand', () => {
 			} );
 
 			it( 'should rename listItem to paragraph (if indent is equal to 0)', () => {
-				model.change( () => {
-					doc.selection.setCollapsedAt( root.getChild( 0 ) );
+				model.change( writer => {
+					writer.setSelection( root.getChild( 0 ) );
 				} );
 
 				command.execute();
@@ -275,8 +275,8 @@ describe( 'IndentCommand', () => {
 			} );
 
 			it( 'should decrement indent of all sub-items of outdented item', () => {
-				model.change( () => {
-					doc.selection.setCollapsedAt( root.getChild( 1 ) );
+				model.change( writer => {
+					writer.setSelection( root.getChild( 1 ) );
 				} );
 
 				command.execute();
@@ -293,11 +293,11 @@ describe( 'IndentCommand', () => {
 			} );
 
 			it( 'should outdent all selected item when multiple items are selected', () => {
-				model.change( () => {
-					doc.selection.setRanges( [ new Range(
+				model.change( writer => {
+					writer.setSelection( new Range(
 						new Position( root.getChild( 1 ), [ 0 ] ),
 						new Position( root.getChild( 3 ), [ 1 ] )
-					) ] );
+					) );
 				} );
 
 				command.execute();

+ 21 - 19
packages/ckeditor5-list/tests/listcommand.js

@@ -50,7 +50,9 @@ describe( 'ListCommand', () => {
 			'</widget>'
 		);
 
-		doc.selection.setCollapsedAt( doc.getRoot().getChild( 0 ) );
+		model.change( writer => {
+			writer.setSelection( doc.getRoot().getChild( 0 ) );
+		} );
 	} );
 
 	afterEach( () => {
@@ -70,24 +72,24 @@ describe( 'ListCommand', () => {
 
 		describe( 'value', () => {
 			it( 'should be false if first position in selection is not in a list item', () => {
-				model.change( () => {
-					doc.selection.setCollapsedAt( doc.getRoot().getChild( 3 ) );
+				model.change( writer => {
+					writer.setSelection( doc.getRoot().getChild( 3 ) );
 				} );
 
 				expect( command.value ).to.be.false;
 			} );
 
 			it( 'should be false if first position in selection is in a list item of different type', () => {
-				model.change( () => {
-					doc.selection.setCollapsedAt( doc.getRoot().getChild( 2 ) );
+				model.change( writer => {
+					writer.setSelection( doc.getRoot().getChild( 2 ) );
 				} );
 
 				expect( command.value ).to.be.false;
 			} );
 
 			it( 'should be true if first position in selection is in a list item of same type', () => {
-				model.change( () => {
-					doc.selection.setCollapsedAt( doc.getRoot().getChild( 1 ) );
+				model.change( writer => {
+					writer.setSelection( doc.getRoot().getChild( 1 ) );
 				} );
 
 				expect( command.value ).to.be.true;
@@ -303,11 +305,11 @@ describe( 'ListCommand', () => {
 				it( 'should rename closest block to listItem and set correct attributes', () => {
 					// From first paragraph to second paragraph.
 					// Command value=false, we are turning on list items.
-					model.change( () => {
-						doc.selection.setRanges( [ new Range(
+					model.change( writer => {
+						writer.setSelection( new Range(
 							Position.createAt( root.getChild( 2 ) ),
 							Position.createAt( root.getChild( 3 ), 'end' )
-						) ] );
+						) );
 					} );
 
 					command.execute();
@@ -328,11 +330,11 @@ describe( 'ListCommand', () => {
 				it( 'should rename closest listItem to paragraph', () => {
 					// From second bullet list item to first numbered list item.
 					// Command value=true, we are turning off list items.
-					model.change( () => {
-						doc.selection.setRanges( [ new Range(
+					model.change( writer => {
+						writer.setSelection( new Range(
 							Position.createAt( root.getChild( 1 ) ),
 							Position.createAt( root.getChild( 4 ), 'end' )
-						) ] );
+						) );
 					} );
 
 					// Convert paragraphs, leave numbered list items.
@@ -353,11 +355,11 @@ describe( 'ListCommand', () => {
 
 				it( 'should change closest listItem\'s type', () => {
 					// From first numbered lsit item to third bulleted list item.
-					model.change( () => {
-						doc.selection.setRanges( [ new Range(
+					model.change( writer => {
+						writer.setSelection( new Range(
 							Position.createAt( root.getChild( 4 ) ),
 							Position.createAt( root.getChild( 6 ) )
-						) ] );
+						) );
 					} );
 
 					// Convert paragraphs, leave numbered list items.
@@ -378,11 +380,11 @@ describe( 'ListCommand', () => {
 
 				it( 'should handle outdenting sub-items when list item is turned off', () => {
 					// From first numbered list item to third bulleted list item.
-					model.change( () => {
-						doc.selection.setRanges( [ new Range(
+					model.change( writer => {
+						writer.setSelection( new Range(
 							Position.createAt( root.getChild( 1 ) ),
 							Position.createAt( root.getChild( 5 ), 'end' )
-						) ] );
+						) );
 					} );
 
 					// Convert paragraphs, leave numbered list items.