Преглед изворни кода

Adjusted tests to refactored model utils.

Oskar Wrobel пре 9 година
родитељ
комит
f8ec4fc217
1 измењених фајлова са 70 додато и 65 уклоњено
  1. 70 65
      packages/ckeditor5-undo/tests/undoengine-integration.js

+ 70 - 65
packages/ckeditor5-undo/tests/undoengine-integration.js

@@ -21,6 +21,7 @@ beforeEach( () => {
 		.then( newEditor => {
 		.then( newEditor => {
 			editor = newEditor;
 			editor = newEditor;
 			doc = editor.document;
 			doc = editor.document;
+			doc.schema.registerItem( 'p', '$block' );
 			root = doc.getRoot();
 			root = doc.getRoot();
 		} );
 		} );
 } );
 } );
@@ -44,118 +45,118 @@ function undoDisabled() {
 describe( 'UndoEngine integration', () => {
 describe( 'UndoEngine integration', () => {
 	describe( 'adding and removing content', () => {
 	describe( 'adding and removing content', () => {
 		it( 'add and undo', () => {
 		it( 'add and undo', () => {
-			input( '<p>fo<selection />o</p><p>bar</p>' );
+			input( '<p>fo[]o</p><p>bar</p>' );
 
 
 			doc.batch().insert( doc.selection.getFirstPosition(), 'zzz' );
 			doc.batch().insert( doc.selection.getFirstPosition(), 'zzz' );
-			output( '<p>fozzz<selection />o</p><p>bar</p>' );
+			output( '<p>fozzz[]o</p><p>bar</p>' );
 
 
 			editor.execute( 'undo' );
 			editor.execute( 'undo' );
-			output( '<p>fo<selection />o</p><p>bar</p>' );
+			output( '<p>fo[]o</p><p>bar</p>' );
 
 
 			undoDisabled();
 			undoDisabled();
 		} );
 		} );
 
 
 		it( 'multiple adding and undo', () => {
 		it( 'multiple adding and undo', () => {
-			input( '<p>fo<selection />o</p><p>bar</p>' );
+			input( '<p>fo[]o</p><p>bar</p>' );
 
 
 			doc.batch()
 			doc.batch()
 				.insert( doc.selection.getFirstPosition(), 'zzz' )
 				.insert( doc.selection.getFirstPosition(), 'zzz' )
 				.insert( new Position( root, [ 1, 0 ] ), 'xxx' );
 				.insert( new Position( root, [ 1, 0 ] ), 'xxx' );
-			output( '<p>fozzz<selection />o</p><p>xxxbar</p>' );
+			output( '<p>fozzz[]o</p><p>xxxbar</p>' );
 
 
 			setSelection( [ 1, 0 ], [ 1, 0 ] );
 			setSelection( [ 1, 0 ], [ 1, 0 ] );
 			doc.batch().insert( doc.selection.getFirstPosition(), 'yyy' );
 			doc.batch().insert( doc.selection.getFirstPosition(), 'yyy' );
-			output( '<p>fozzzo</p><p>yyy<selection />xxxbar</p>' );
+			output( '<p>fozzzo</p><p>yyy[]xxxbar</p>' );
 
 
 			editor.execute( 'undo' );
 			editor.execute( 'undo' );
-			output( '<p>fozzzo</p><p><selection />xxxbar</p>' );
+			output( '<p>fozzzo</p><p>[]xxxbar</p>' );
 
 
 			editor.execute( 'undo' );
 			editor.execute( 'undo' );
-			output( '<p>fo<selection />o</p><p>bar</p>' );
+			output( '<p>fo[]o</p><p>bar</p>' );
 
 
 			undoDisabled();
 			undoDisabled();
 		} );
 		} );
 
 
 		it( 'multiple adding mixed with undo', () => {
 		it( 'multiple adding mixed with undo', () => {
-			input( '<p>fo<selection />o</p><p>bar</p>' );
+			input( '<p>fo[]o</p><p>bar</p>' );
 
 
 			doc.batch().insert( doc.selection.getFirstPosition(), 'zzz' );
 			doc.batch().insert( doc.selection.getFirstPosition(), 'zzz' );
-			output( '<p>fozzz<selection />o</p><p>bar</p>' );
+			output( '<p>fozzz[]o</p><p>bar</p>' );
 
 
 			setSelection( [ 1, 0 ], [ 1, 0 ] );
 			setSelection( [ 1, 0 ], [ 1, 0 ] );
 			doc.batch().insert( doc.selection.getFirstPosition(), 'yyy' );
 			doc.batch().insert( doc.selection.getFirstPosition(), 'yyy' );
-			output( '<p>fozzzo</p><p>yyy<selection />bar</p>' );
+			output( '<p>fozzzo</p><p>yyy[]bar</p>' );
 
 
 			editor.execute( 'undo' );
 			editor.execute( 'undo' );
-			output( '<p>fozzzo</p><p><selection />bar</p>' );
+			output( '<p>fozzzo</p><p>[]bar</p>' );
 
 
 			setSelection( [ 0, 0 ], [ 0, 0 ] );
 			setSelection( [ 0, 0 ], [ 0, 0 ] );
 			doc.batch().insert( doc.selection.getFirstPosition(), 'xxx' );
 			doc.batch().insert( doc.selection.getFirstPosition(), 'xxx' );
-			output( '<p>xxx<selection />fozzzo</p><p>bar</p>' );
+			output( '<p>xxx[]fozzzo</p><p>bar</p>' );
 
 
 			editor.execute( 'undo' );
 			editor.execute( 'undo' );
-			output( '<p><selection />fozzzo</p><p>bar</p>' );
+			output( '<p>[]fozzzo</p><p>bar</p>' );
 
 
 			editor.execute( 'undo' );
 			editor.execute( 'undo' );
-			output( '<p>fo<selection />o</p><p>bar</p>' );
+			output( '<p>fo[]o</p><p>bar</p>' );
 
 
 			undoDisabled();
 			undoDisabled();
 		} );
 		} );
 
 
 		it( 'multiple remove and undo', () => {
 		it( 'multiple remove and undo', () => {
-			input( '<p><selection />foo</p><p>bar</p>' );
+			input( '<p>[]foo</p><p>bar</p>' );
 
 
 			doc.batch().remove( Range.createFromPositionAndShift( doc.selection.getFirstPosition(), 2 ) );
 			doc.batch().remove( Range.createFromPositionAndShift( doc.selection.getFirstPosition(), 2 ) );
-			output( '<p><selection />o</p><p>bar</p>' );
+			output( '<p>[]o</p><p>bar</p>' );
 
 
 			setSelection( [ 1, 1 ], [ 1, 1 ] );
 			setSelection( [ 1, 1 ], [ 1, 1 ] );
 			doc.batch().remove( Range.createFromPositionAndShift( doc.selection.getFirstPosition(), 2 ) );
 			doc.batch().remove( Range.createFromPositionAndShift( doc.selection.getFirstPosition(), 2 ) );
-			output( '<p>o</p><p>b<selection /></p>' );
+			output( '<p>o</p><p>b[]</p>' );
 
 
 			editor.execute( 'undo' );
 			editor.execute( 'undo' );
 			// Here is an edge case that selection could be before or after `ar`.
 			// Here is an edge case that selection could be before or after `ar`.
-			output( '<p>o</p><p>b<selection />ar</p>' );
+			output( '<p>o</p><p>b[]ar</p>' );
 
 
 			editor.execute( 'undo' );
 			editor.execute( 'undo' );
 			// As above.
 			// As above.
-			output( '<p><selection />foo</p><p>bar</p>' );
+			output( '<p>[]foo</p><p>bar</p>' );
 
 
 			undoDisabled();
 			undoDisabled();
 		} );
 		} );
 
 
 		it( 'add and remove different parts and undo', () => {
 		it( 'add and remove different parts and undo', () => {
-			input( '<p>fo<selection />o</p><p>bar</p>' );
+			input( '<p>fo[]o</p><p>bar</p>' );
 
 
 			doc.batch().insert( doc.selection.getFirstPosition(), 'zzz' );
 			doc.batch().insert( doc.selection.getFirstPosition(), 'zzz' );
-			output( '<p>fozzz<selection />o</p><p>bar</p>' );
+			output( '<p>fozzz[]o</p><p>bar</p>' );
 
 
 			setSelection( [ 1, 2 ], [ 1, 2 ] );
 			setSelection( [ 1, 2 ], [ 1, 2 ] );
 			doc.batch().remove( Range.createFromPositionAndShift( new Position( root, [ 1, 1 ] ) , 1 ) );
 			doc.batch().remove( Range.createFromPositionAndShift( new Position( root, [ 1, 1 ] ) , 1 ) );
-			output( '<p>fozzzo</p><p>b<selection />r</p>' );
+			output( '<p>fozzzo</p><p>b[]r</p>' );
 
 
 			editor.execute( 'undo' );
 			editor.execute( 'undo' );
-			output( '<p>fozzzo</p><p>ba<selection />r</p>' );
+			output( '<p>fozzzo</p><p>ba[]r</p>' );
 
 
 			editor.execute( 'undo' );
 			editor.execute( 'undo' );
-			output( '<p>fo<selection />o</p><p>bar</p>' );
+			output( '<p>fo[]o</p><p>bar</p>' );
 
 
 			undoDisabled();
 			undoDisabled();
 		} );
 		} );
 
 
 		it( 'add and remove same part and undo', () => {
 		it( 'add and remove same part and undo', () => {
-			input( '<p>fo<selection />o</p><p>bar</p>' );
+			input( '<p>fo[]o</p><p>bar</p>' );
 
 
 			doc.batch().insert( doc.selection.getFirstPosition(), 'zzz' );
 			doc.batch().insert( doc.selection.getFirstPosition(), 'zzz' );
-			output( '<p>fozzz<selection />o</p><p>bar</p>' );
+			output( '<p>fozzz[]o</p><p>bar</p>' );
 
 
 			doc.batch().remove( Range.createFromPositionAndShift( new Position( root, [ 0, 2 ] ) , 3 ) );
 			doc.batch().remove( Range.createFromPositionAndShift( new Position( root, [ 0, 2 ] ) , 3 ) );
-			output( '<p>fo<selection />o</p><p>bar</p>' );
+			output( '<p>fo[]o</p><p>bar</p>' );
 
 
 			editor.execute( 'undo' );
 			editor.execute( 'undo' );
-			output( '<p>fozzz<selection />o</p><p>bar</p>' );
+			output( '<p>fozzz[]o</p><p>bar</p>' );
 
 
 			editor.execute( 'undo' );
 			editor.execute( 'undo' );
-			output( '<p>fo<selection />o</p><p>bar</p>' );
+			output( '<p>fo[]o</p><p>bar</p>' );
 
 
 			undoDisabled();
 			undoDisabled();
 		} );
 		} );
@@ -163,38 +164,38 @@ describe( 'UndoEngine integration', () => {
 
 
 	describe( 'moving', () => {
 	describe( 'moving', () => {
 		it( 'move same content twice then undo', () => {
 		it( 'move same content twice then undo', () => {
-			input( '<p>f<selection>o</selection>z</p><p>bar</p>' );
+			input( '<p>f[o]z</p><p>bar</p>' );
 
 
 			doc.batch().move( doc.selection.getFirstRange(), new Position( root, [ 1, 0 ] ) );
 			doc.batch().move( doc.selection.getFirstRange(), new Position( root, [ 1, 0 ] ) );
-			output( '<p>fz</p><p><selection>o</selection>bar</p>' );
+			output( '<p>fz</p><p>[o]bar</p>' );
 
 
 			doc.batch().move( doc.selection.getFirstRange(), new Position( root, [ 0, 2 ] ) );
 			doc.batch().move( doc.selection.getFirstRange(), new Position( root, [ 0, 2 ] ) );
-			output( '<p>fz<selection>o</selection></p><p>bar</p>' );
+			output( '<p>fz[o]</p><p>bar</p>' );
 
 
 			editor.execute( 'undo' );
 			editor.execute( 'undo' );
-			output( '<p>fz</p><p><selection>o</selection>bar</p>' );
+			output( '<p>fz</p><p>[o]bar</p>' );
 
 
 			editor.execute( 'undo' );
 			editor.execute( 'undo' );
-			output( '<p>f<selection>o</selection>z</p><p>bar</p>' );
+			output( '<p>f[o]z</p><p>bar</p>' );
 
 
 			undoDisabled();
 			undoDisabled();
 		} );
 		} );
 
 
 		it( 'move content and new parent then undo', () => {
 		it( 'move content and new parent then undo', () => {
-			input( '<p>f<selection>o</selection>z</p><p>bar</p>' );
+			input( '<p>f[o]z</p><p>bar</p>' );
 
 
 			doc.batch().move( doc.selection.getFirstRange(), new Position( root, [ 1, 0 ] ) );
 			doc.batch().move( doc.selection.getFirstRange(), new Position( root, [ 1, 0 ] ) );
-			output( '<p>fz</p><p><selection>o</selection>bar</p>' );
+			output( '<p>fz</p><p>[o]bar</p>' );
 
 
 			setSelection( [ 1 ], [ 2 ] );
 			setSelection( [ 1 ], [ 2 ] );
 			doc.batch().move( doc.selection.getFirstRange(), new Position( root, [ 0 ] ) );
 			doc.batch().move( doc.selection.getFirstRange(), new Position( root, [ 0 ] ) );
-			output( '<selection><p>obar</p></selection><p>fz</p>' );
+			output( '[<p>obar</p>]<p>fz</p>' );
 
 
 			editor.execute( 'undo' );
 			editor.execute( 'undo' );
-			output( '<p>fz</p><selection><p>obar</p></selection>' );
+			output( '<p>fz</p>[<p>obar</p>]' );
 
 
 			editor.execute( 'undo' );
 			editor.execute( 'undo' );
-			output( '<p>f<selection>o</selection>z</p><p>bar</p>' );
+			output( '<p>f[o]z</p><p>bar</p>' );
 
 
 			undoDisabled();
 			undoDisabled();
 		} );
 		} );
@@ -202,20 +203,22 @@ describe( 'UndoEngine integration', () => {
 
 
 	describe( 'attributes with other', () => {
 	describe( 'attributes with other', () => {
 		it( 'attributes then insert inside then undo', () => {
 		it( 'attributes then insert inside then undo', () => {
-			input( '<p>fo<selection>ob</selection>ar</p>' );
+			input( '<p>fo[ob]ar</p>' );
 
 
 			doc.batch().setAttribute( doc.selection.getFirstRange(), 'bold', true );
 			doc.batch().setAttribute( doc.selection.getFirstRange(), 'bold', true );
-			output( '<p>fo<selection><$text bold=true>ob</$text></selection>ar</p>' );
+			output( '<p>fo[<$text bold="true">ob</$text>]ar</p>' );
 
 
 			setSelection( [ 0, 3 ], [ 0, 3 ] );
 			setSelection( [ 0, 3 ], [ 0, 3 ] );
 			doc.batch().insert( doc.selection.getFirstPosition(), 'zzz' );
 			doc.batch().insert( doc.selection.getFirstPosition(), 'zzz' );
-			output( '<p>fo<$text bold=true>o</$text>zzz<selection bold=true /><$text bold=true>b</$text>ar</p>' );
+			output( '<p>fo<$text bold="true">o</$text>zzz<$text bold="true">[]b</$text>ar</p>' );
+			expect( doc.selection.getAttribute( 'bold' ) ).to.true;
 
 
 			editor.execute( 'undo' );
 			editor.execute( 'undo' );
-			output( '<p>fo<$text bold=true>o<selection bold=true />b</$text>ar</p>' );
+			output( '<p>fo<$text bold="true">o[]b</$text>ar</p>' );
+			expect( doc.selection.getAttribute( 'bold' ) ).to.true;
 
 
 			editor.execute( 'undo' );
 			editor.execute( 'undo' );
-			output( '<p>fo<selection>ob</selection>ar</p>' );
+			output( '<p>fo[ob]ar</p>' );
 
 
 			undoDisabled();
 			undoDisabled();
 		} );
 		} );
@@ -223,73 +226,75 @@ describe( 'UndoEngine integration', () => {
 
 
 	describe( 'wrapping, unwrapping, merging, splitting', () => {
 	describe( 'wrapping, unwrapping, merging, splitting', () => {
 		it( 'wrap and undo', () => {
 		it( 'wrap and undo', () => {
-			input( 'fo<selection>zb</selection>ar' );
+			doc.schema.allow( { name: '$text', inside: '$root' } );
+			input( 'fo[zb]ar' );
 
 
 			doc.batch().wrap( doc.selection.getFirstRange(), 'p' );
 			doc.batch().wrap( doc.selection.getFirstRange(), 'p' );
-			output( 'fo<selection><p>zb</p></selection>ar' );
+			output( 'fo[<p>zb</p>]ar' );
 
 
 			editor.execute( 'undo' );
 			editor.execute( 'undo' );
-			output( 'fo<selection>zb</selection>ar' );
+			output( 'fo[zb]ar' );
 
 
 			undoDisabled();
 			undoDisabled();
 		} );
 		} );
 
 
 		it( 'wrap, move and undo', () => {
 		it( 'wrap, move and undo', () => {
-			input( 'fo<selection>zb</selection>ar' );
+			doc.schema.allow( { name: '$text', inside: '$root' } );
+			input( 'fo[zb]ar' );
 
 
 			doc.batch().wrap( doc.selection.getFirstRange(), 'p' );
 			doc.batch().wrap( doc.selection.getFirstRange(), 'p' );
 			// Would be better if selection was inside P.
 			// Would be better if selection was inside P.
-			output( 'fo<selection><p>zb</p></selection>ar' );
+			output( 'fo[<p>zb</p>]ar' );
 
 
 			setSelection( [ 2, 0 ], [ 2, 1 ] );
 			setSelection( [ 2, 0 ], [ 2, 1 ] );
 			doc.batch().move( doc.selection.getFirstRange(), new Position( root, [ 0 ] ) );
 			doc.batch().move( doc.selection.getFirstRange(), new Position( root, [ 0 ] ) );
-			output( '<selection>z</selection>fo<p>b</p>ar' );
+			output( '[z]fo<p>b</p>ar' );
 
 
 			editor.execute( 'undo' );
 			editor.execute( 'undo' );
-			output( 'fo<p><selection>z</selection>b</p>ar' );
+			output( 'fo<p>[z]b</p>ar' );
 
 
 			editor.execute( 'undo' );
 			editor.execute( 'undo' );
-			output( 'fo<selection>zb</selection>ar' );
+			output( 'fo[zb]ar' );
 
 
 			undoDisabled();
 			undoDisabled();
 		} );
 		} );
 
 
 		it( 'unwrap and undo', () => {
 		it( 'unwrap and undo', () => {
-			input( '<p>foo<selection />bar</p>' );
+			input( '<p>foo[]bar</p>' );
 
 
 			doc.batch().unwrap( doc.selection.getFirstPosition().parent );
 			doc.batch().unwrap( doc.selection.getFirstPosition().parent );
-			output( 'foo<selection />bar' );
+			output( 'foo[]bar' );
 
 
 			editor.execute( 'undo' );
 			editor.execute( 'undo' );
-			output( '<p>foo<selection />bar</p>' );
+			output( '<p>foo[]bar</p>' );
 
 
 			undoDisabled();
 			undoDisabled();
 		} );
 		} );
 
 
 		it( 'merge and undo', () => {
 		it( 'merge and undo', () => {
-			input( '<p>foo</p><p><selection />bar</p>' );
+			input( '<p>foo</p><p>[]bar</p>' );
 
 
 			doc.batch().merge( new Position( root, [ 1 ] ) );
 			doc.batch().merge( new Position( root, [ 1 ] ) );
 			// Because selection is stuck with <p> it ends up in graveyard. We have to manually move it to correct node.
 			// Because selection is stuck with <p> it ends up in graveyard. We have to manually move it to correct node.
 			setSelection( [ 0, 3 ], [ 0, 3 ] );
 			setSelection( [ 0, 3 ], [ 0, 3 ] );
-			output( '<p>foo<selection />bar</p>' );
+			output( '<p>foo[]bar</p>' );
 
 
 			editor.execute( 'undo' );
 			editor.execute( 'undo' );
-			output( '<p>foo</p><p><selection />bar</p>' );
+			output( '<p>foo</p><p>[]bar</p>' );
 
 
 			undoDisabled();
 			undoDisabled();
 		} );
 		} );
 
 
 		it( 'split and undo', () => {
 		it( 'split and undo', () => {
-			input( '<p>foo<selection />bar</p>' );
+			input( '<p>foo[]bar</p>' );
 
 
 			doc.batch().split( doc.selection.getFirstPosition() );
 			doc.batch().split( doc.selection.getFirstPosition() );
 			// Because selection is stuck with <p> it ends up in wrong node. We have to manually move it to correct node.
 			// Because selection is stuck with <p> it ends up in wrong node. We have to manually move it to correct node.
 			setSelection( [ 1, 0 ], [ 1, 0 ] );
 			setSelection( [ 1, 0 ], [ 1, 0 ] );
-			output( '<p>foo</p><p><selection />bar</p>' );
+			output( '<p>foo</p><p>[]bar</p>' );
 
 
 			editor.execute( 'undo' );
 			editor.execute( 'undo' );
-			output( '<p>foo<selection />bar</p>' );
+			output( '<p>foo[]bar</p>' );
 
 
 			undoDisabled();
 			undoDisabled();
 		} );
 		} );
@@ -297,13 +302,13 @@ describe( 'UndoEngine integration', () => {
 
 
 	describe( 'other edge cases', () => {
 	describe( 'other edge cases', () => {
 		it( 'deleteContents between two nodes', () => {
 		it( 'deleteContents between two nodes', () => {
-			input( '<p>fo<selection>o</p><p>b</selection>ar</p>' );
+			input( '<p>fo[o</p><p>b]ar</p>' );
 
 
 			deleteContents( doc.batch(), doc.selection, { merge: true } );
 			deleteContents( doc.batch(), doc.selection, { merge: true } );
-			output( '<p>fo<selection />ar</p>' );
+			output( '<p>fo[]ar</p>' );
 
 
 			editor.execute( 'undo' );
 			editor.execute( 'undo' );
-			output( '<p>fo<selection>o</p><p>b</selection>ar</p>' );
+			output( '<p>fo[o</p><p>b]ar</p>' );
 		} );
 		} );
 	} );
 	} );
 } );
 } );