Ver código fonte

Adjusted tests to refactored model utils.

Oskar Wrobel 9 anos atrás
pai
commit
4569c53d47

+ 13 - 13
packages/ckeditor5-typing/tests/deletecommand-integration.js

@@ -38,7 +38,7 @@ function assertOutput( output ) {
 
 describe( 'DeleteCommand integration', () => {
 	it( 'deletes characters (and group changes in batches) and rollbacks', () => {
-		setData( doc, '<p>123456789<selection /></p>' );
+		setData( doc, '<p>123456789[]</p>' );
 
 		for ( let i = 0; i < 3; ++i ) {
 			editor.execute( 'delete' );
@@ -46,11 +46,11 @@ describe( 'DeleteCommand integration', () => {
 
 		editor.execute( 'undo' );
 
-		assertOutput( '<p>123456789<selection /></p>' );
+		assertOutput( '<p>123456789[]</p>' );
 	} );
 
 	it( 'deletes characters (and group changes in batches) and rollbacks - test step', () => {
-		setData( doc, '<p>123456789<selection /></p>' );
+		setData( doc, '<p>123456789[]</p>' );
 
 		for ( let i = 0; i < 6; ++i ) {
 			editor.execute( 'delete' );
@@ -58,15 +58,15 @@ describe( 'DeleteCommand integration', () => {
 
 		editor.execute( 'undo' );
 
-		assertOutput( '<p>123456<selection /></p>' );
+		assertOutput( '<p>123456[]</p>' );
 
 		editor.execute( 'undo' );
 
-		assertOutput( '<p>123456789<selection /></p>' );
+		assertOutput( '<p>123456789[]</p>' );
 	} );
 
 	it( 'deletes elements (and group changes in batches) and rollbacks', () => {
-		setData( doc, '<p><img>1</img><img>2</img><img>3</img><img>4</img><img>5</img><img>6</img><selection /></p>' );
+		setData( doc, '<p><img>1</img><img>2</img><img>3</img><img>4</img><img>5</img><img>6</img>[]</p>' );
 
 		for ( let i = 0; i < 3; ++i ) {
 			editor.execute( 'delete' );
@@ -74,11 +74,11 @@ describe( 'DeleteCommand integration', () => {
 
 		editor.execute( 'undo' );
 
-		assertOutput( '<p><img>1</img><img>2</img><img>3</img><img>4</img><img>5</img><img>6</img><selection /></p>' );
+		assertOutput( '<p><img>1</img><img>2</img><img>3</img><img>4</img><img>5</img><img>6</img>[]</p>' );
 	} );
 
 	it( 'merges elements (and group changes in batches) and rollbacks', () => {
-		setData( doc, '<p>123456</p><p><selection />78</p>' );
+		setData( doc, '<p>123456</p><p>[]78</p>' );
 
 		for ( let i = 0; i < 6; ++i ) {
 			editor.execute( 'delete' );
@@ -88,15 +88,15 @@ describe( 'DeleteCommand integration', () => {
 
 		// Deleted 6,5,4, <P> does not count.
 		// It's not the most elegant solution, but is the best if we don't want to make complicated algorithm.
-		assertOutput( '<p>123<selection />78</p>' );
+		assertOutput( '<p>123[]78</p>' );
 
 		editor.execute( 'undo' );
 
-		assertOutput( '<p>123456</p><p><selection />78</p>' );
+		assertOutput( '<p>123456</p><p>[]78</p>' );
 	} );
 
 	it( 'merges elements (and group changes in batches) and rollbacks - non-collapsed selection', () => {
-		setData( doc, '<p>12345<selection>6</p><p>7</selection>8</p>' );
+		setData( doc, '<p>12345[6</p><p>7]8</p>' );
 
 		editor.execute( 'delete' );
 		editor.execute( 'delete' );
@@ -104,10 +104,10 @@ describe( 'DeleteCommand integration', () => {
 
 		editor.execute( 'undo' );
 
-		assertOutput( '<p>1234<selection />8</p>' );
+		assertOutput( '<p>1234[]8</p>' );
 
 		editor.execute( 'undo' );
 
-		assertOutput( '<p>12345<selection>6</p><p>7</selection>8</p>' );
+		assertOutput( '<p>12345[6</p><p>7]8</p>' );
 	} );
 } );

+ 10 - 10
packages/ckeditor5-typing/tests/deletecommand.js

@@ -31,7 +31,7 @@ describe( 'DeleteCommand', () => {
 
 	describe( 'execute', () => {
 		it( 'uses enqueueChanges', () => {
-			setData( doc, '<p>foo<selection />bar</p>' );
+			setData( doc, '<p>foo[]bar</p>' );
 
 			const spy = sinon.spy( doc, 'enqueueChanges' );
 
@@ -41,38 +41,38 @@ describe( 'DeleteCommand', () => {
 		} );
 
 		it( 'deletes previous character when selection is collapsed', () => {
-			setData( doc, '<p>foo<selection />bar</p>' );
+			setData( doc, '<p>foo[]bar</p>' );
 
 			editor.execute( 'delete' );
 
-			expect( getData( doc, { selection: true } ) ).to.equal( '<p>fo<selection />bar</p>' );
+			expect( getData( doc, { selection: true } ) ).to.equal( '<p>fo[]bar</p>' );
 		} );
 
 		it( 'deletes selection contents', () => {
-			setData( doc, '<p>fo<selection>ob</selection>ar</p>' );
+			setData( doc, '<p>fo[ob]ar</p>' );
 
 			editor.execute( 'delete' );
 
-			expect( getData( doc, { selection: true } ) ).to.equal( '<p>fo<selection />ar</p>' );
+			expect( getData( doc, { selection: true } ) ).to.equal( '<p>fo[]ar</p>' );
 		} );
 
 		it( 'merges elements', () => {
-			setData( doc, '<p>foo</p><p><selection />bar</p>' );
+			setData( doc, '<p>foo</p><p>[]bar</p>' );
 
 			editor.execute( 'delete' );
 
-			expect( getData( doc, { selection: true } ) ).to.equal( '<p>foo<selection />bar</p>' );
+			expect( getData( doc, { selection: true } ) ).to.equal( '<p>foo[]bar</p>' );
 		} );
 
 		it( 'does not try to delete when selection is at the boundary', () => {
 			const spy = sinon.spy();
 
 			doc.composer.on( 'deleteContents', spy );
-			setData( doc, '<p><selection />foo</p>' );
+			setData( doc, '<p>[]foo</p>' );
 
 			editor.execute( 'delete' );
 
-			expect( getData( doc, { selection: true } ) ).to.equal( '<p><selection />foo</p>' );
+			expect( getData( doc, { selection: true } ) ).to.equal( '<p>[]foo</p>' );
 			expect( spy.callCount ).to.equal( 0 );
 		} );
 
@@ -80,7 +80,7 @@ describe( 'DeleteCommand', () => {
 			const spy = sinon.spy();
 
 			doc.composer.on( 'modifySelection', spy );
-			setData( doc, '<p>foo<selection />bar</p>' );
+			setData( doc, '<p>foo[]bar</p>' );
 
 			editor.commands.get( 'delete' ).direction = 'forward';
 

+ 15 - 15
packages/ckeditor5-typing/tests/input.js

@@ -17,7 +17,7 @@ import ViewElement from '/ckeditor5/engine/view/element.js';
 import EmitterMixin from '/ckeditor5/utils/emittermixin.js';
 import { getCode } from '/ckeditor5/utils/keyboard.js';
 
-import { getData as getModelData } from '/tests/engine/_utils/model.js';
+import { getData as getModelData, stringify as modelStringify } from '/tests/engine/_utils/model.js';
 import { getData as getViewData } from '/tests/engine/_utils/view.js';
 
 describe( 'Input feature', () => {
@@ -89,7 +89,7 @@ describe( 'Input feature', () => {
 				}
 			] );
 
-			expect( getModelData( model ) ).to.equal( '<paragraph>foox<selection />bar</paragraph>' );
+			expect( getModelData( model ) ).to.equal( '<paragraph>foox[]bar</paragraph>' );
 			expect( getViewData( view ) ).to.equal( '<p>foox{}bar</p>' );
 		} );
 
@@ -103,7 +103,7 @@ describe( 'Input feature', () => {
 				}
 			] );
 
-			expect( getModelData( model ) ).to.equal( '<paragraph>food<selection />ar</paragraph>' );
+			expect( getModelData( model ) ).to.equal( '<paragraph>food[]ar</paragraph>' );
 			expect( getViewData( view ) ).to.equal( '<p>food{}ar</p>' );
 		} );
 
@@ -119,7 +119,7 @@ describe( 'Input feature', () => {
 				}
 			] );
 
-			expect( getModelData( model ) ).to.equal( '<paragraph>x<selection /></paragraph>' );
+			expect( getModelData( model ) ).to.equal( '<paragraph>x[]</paragraph>' );
 			expect( getViewData( view ) ).to.equal( '<p>x{}</p>' );
 		} );
 
@@ -135,7 +135,7 @@ describe( 'Input feature', () => {
 				}
 			] );
 
-			expect( getModelData( model ) ).to.equal( '<paragraph></paragraph>' );
+			expect( modelStringify( modelRoot ) ).to.equal( '<paragraph></paragraph>' );
 			expect( getViewData( view ) ).to.equal( '<p></p>' );
 		} );
 
@@ -149,7 +149,7 @@ describe( 'Input feature', () => {
 				}
 			] );
 
-			expect( getModelData( model ) ).to.equal( '<paragraph>foo<selection />bar</paragraph>' );
+			expect( getModelData( model ) ).to.equal( '<paragraph>foo[]bar</paragraph>' );
 			expect( getViewData( view ) ).to.equal( '<p>foo{}bar</p>' );
 		} );
 
@@ -165,7 +165,7 @@ describe( 'Input feature', () => {
 				}
 			] );
 
-			expect( getModelData( model ) ).to.equal( '<paragraph>foo<image></image>x<selection /></paragraph>' );
+			expect( getModelData( model ) ).to.equal( '<paragraph>foo<image></image>x[]</paragraph>' );
 			expect( getViewData( view ) ).to.equal( '<p>foo<img></img>x{}</p>' );
 		} );
 
@@ -179,7 +179,7 @@ describe( 'Input feature', () => {
 				}
 			] );
 
-			expect( getModelData( model ) ).to.equal( '<paragraph>foo<selection />bar</paragraph>' );
+			expect( getModelData( model ) ).to.equal( '<paragraph>foo[]bar</paragraph>' );
 			expect( getViewData( view ) ).to.equal( '<p>foo{}bar</p>' );
 		} );
 
@@ -195,7 +195,7 @@ describe( 'Input feature', () => {
 				}
 			] );
 
-			expect( getModelData( model ) ).to.equal( '<paragraph></paragraph>' );
+			expect( modelStringify( modelRoot ) ).to.equal( '<paragraph></paragraph>' );
 			expect( getViewData( view ) ).to.equal( '<p></p>' );
 		} );
 	} );
@@ -208,7 +208,7 @@ describe( 'Input feature', () => {
 			} );
 
 			listenter.listenTo( view, 'keydown', () => {
-				expect( getModelData( model ) ).to.equal( '<paragraph>fo<selection />ar</paragraph>' );
+				expect( getModelData( model ) ).to.equal( '<paragraph>fo[]ar</paragraph>' );
 
 				view.fire( 'mutations', [
 					{
@@ -222,7 +222,7 @@ describe( 'Input feature', () => {
 
 			view.fire( 'keydown', { keyCode: getCode( 'y' ) } );
 
-			expect( getModelData( model ) ).to.equal( '<paragraph>foy<selection />ar</paragraph>' );
+			expect( getModelData( model ) ).to.equal( '<paragraph>foy[]ar</paragraph>' );
 			expect( getViewData( view ) ).to.equal( '<p>foy{}ar</p>' );
 		} );
 
@@ -234,7 +234,7 @@ describe( 'Input feature', () => {
 
 			view.fire( 'keydown', { keyCode: getCode( 'arrowright' ) } );
 
-			expect( getModelData( model ) ).to.equal( '<paragraph>fo<selection>ob</selection>ar</paragraph>' );
+			expect( getModelData( model ) ).to.equal( '<paragraph>fo[ob]ar</paragraph>' );
 		} );
 
 		it( 'should do nothing on ctrl combinations', () => {
@@ -245,7 +245,7 @@ describe( 'Input feature', () => {
 
 			view.fire( 'keydown', { ctrlKey: true, keyCode: getCode( 'c' ) } );
 
-			expect( getModelData( model ) ).to.equal( '<paragraph>fo<selection>ob</selection>ar</paragraph>' );
+			expect( getModelData( model ) ).to.equal( '<paragraph>fo[ob]ar</paragraph>' );
 		} );
 
 		it( 'should do nothing on non printable keys', () => {
@@ -258,13 +258,13 @@ describe( 'Input feature', () => {
 			view.fire( 'keydown', { keyCode: 35 } ); // Home
 			view.fire( 'keydown', { keyCode: 112 } ); // F1
 
-			expect( getModelData( model ) ).to.equal( '<paragraph>fo<selection>ob</selection>ar</paragraph>' );
+			expect( getModelData( model ) ).to.equal( '<paragraph>fo[ob]ar</paragraph>' );
 		} );
 
 		it( 'should do nothing if selection is collapsed', () => {
 			view.fire( 'keydown', { ctrlKey: true, keyCode: getCode( 'c' ) } );
 
-			expect( getModelData( model ) ).to.equal( '<paragraph>foo<selection />bar</paragraph>' );
+			expect( getModelData( model ) ).to.equal( '<paragraph>foo[]bar</paragraph>' );
 		} );
 	} );