Browse Source

Fix some selection post fixer tests.

Maciej Gołaszewski 5 years ago
parent
commit
c1dd1fd6e8
1 changed files with 82 additions and 84 deletions
  1. 82 84
      packages/ckeditor5-engine/tests/model/utils/selection-post-fixer.js

+ 82 - 84
packages/ckeditor5-engine/tests/model/utils/selection-post-fixer.js

@@ -8,8 +8,9 @@ import Model from '../../../src/model/model';
 import { injectSelectionPostFixer } from '../../../src/model/utils/selection-post-fixer';
 
 import { getData as getModelData, setData as setModelData } from '../../../src/dev-utils/model';
+import { assertEqualMarkup } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
 
-describe( 'Selection post-fixer', () => {
+describe.only( 'Selection post-fixer', () => {
 	describe( 'injectSelectionPostFixer()', () => {
 		it( 'is a function', () => {
 			expect( injectSelectionPostFixer ).to.be.a( 'function' );
@@ -40,7 +41,7 @@ describe( 'Selection post-fixer', () => {
 			model.schema.register( 'tableCell', {
 				allowIn: 'tableRow',
 				allowAttributes: [ 'colspan', 'rowspan' ],
-				isLimit: true
+				isObject: true
 			} );
 
 			model.schema.extend( '$block', { allowIn: 'tableCell' } );
@@ -197,43 +198,6 @@ describe( 'Selection post-fixer', () => {
 				);
 			} );
 
-			it( 'should fix #5', () => {
-				setModelData( model,
-					'<paragraph>foo</paragraph>' +
-					'<table>' +
-						'<tableRow>' +
-							'<tableCell><paragraph>aaa</paragraph></tableCell>' +
-							'<tableCell><paragraph>bbb</paragraph></tableCell>' +
-						'</tableRow>' +
-					'</table>' +
-					'[]' +
-					'<table>' +
-						'<tableRow>' +
-							'<tableCell><paragraph>xxx</paragraph></tableCell>' +
-							'<tableCell><paragraph>yyy</paragraph></tableCell>' +
-						'</tableRow>' +
-					'</table>' +
-					'<paragraph>baz</paragraph>'
-				);
-
-				expect( getModelData( model ) ).to.equal(
-					'<paragraph>foo</paragraph>' +
-					'[<table>' +
-						'<tableRow>' +
-							'<tableCell><paragraph>aaa</paragraph></tableCell>' +
-							'<tableCell><paragraph>bbb</paragraph></tableCell>' +
-						'</tableRow>' +
-					'</table>]' +
-					'<table>' +
-						'<tableRow>' +
-							'<tableCell><paragraph>xxx</paragraph></tableCell>' +
-							'<tableCell><paragraph>yyy</paragraph></tableCell>' +
-						'</tableRow>' +
-					'</table>' +
-					'<paragraph>baz</paragraph>'
-				);
-			} );
-
 			// There's a chance that this and the following test will not be up to date with
 			// how the table feature is really implemented once we'll introduce row/cells/columns selection
 			// in which case all these elements will need to be marked as objects.
@@ -596,48 +560,38 @@ describe( 'Selection post-fixer', () => {
 				expect( getModelData( model ) ).to.equal(
 					'<paragraph>f[oo</paragraph>' +
 					'<table>' +
-						'<tableRow>' +
-							'<tableCell><paragraph>aaa</paragraph></tableCell>' +
-							'<tableCell><paragraph>bbb</paragraph></tableCell>' +
-						'</tableRow>' +
+					'<tableRow>' +
+					'<tableCell><paragraph>aaa</paragraph></tableCell>' +
+					'<tableCell><paragraph>bbb</paragraph></tableCell>' +
+					'</tableRow>' +
 					'</table>' +
 					'<paragraph>b]a[r]</paragraph>'
 				);
 			} );
 
-			it( 'should not fix multiple ranges #1 - table selection', () => {
+			it( 'should not fix multiple ranges on objects - table selection', () => {
 				setModelData( model,
 					'<table>' +
-					'<tableRow>' +
-					'[<tableCell><paragraph>a</paragraph></tableCell>]' +
-					'[<tableCell><paragraph>b</paragraph></tableCell>]' +
-					'</tableRow>' +
-					'<tableRow>' +
-					'[<tableCell><paragraph>c</paragraph></tableCell>]' +
-					'<tableCell><paragraph>d</paragraph></tableCell>' +
-					'</tableRow>' +
+						'<tableRow>' +
+							'[<tableCell><paragraph>a</paragraph></tableCell>]' +
+							'[<tableCell><paragraph>b</paragraph></tableCell>]' +
+						'</tableRow>' +
+						'<tableRow>' +
+							'[<tableCell><paragraph>c</paragraph></tableCell>]' +
+							'<tableCell><paragraph>d</paragraph></tableCell>' +
+						'</tableRow>' +
 					'</table>'
 				);
 
-				// model.change( writer => {
-				// 	const ranges = [
-				// 		new ModelRange( new ModelPosition( modelRoot, [ 0, 1 ] ), new ModelPosition( modelRoot, [ 1, 0 ] ) ),
-				// 		new ModelRange( new ModelPosition( modelRoot, [ 1, 0, 0, 0 ] ), new ModelPosition( modelRoot, [ 2, 1 ] ) ),
-				// 		new ModelRange( new ModelPosition( modelRoot, [ 2, 2 ] ), new ModelPosition( modelRoot, [ 2, 3 ] ) )
-				// 	];
-				//
-				// 	writer.setSelection( ranges );
-				// } );
-
-				expect( getModelData( model ) ).to.equal(
+				assertEqualMarkup( getModelData( model ),
 					'<table>' +
 					'<tableRow>' +
-					'[<tableCell><paragraph>a</paragraph></tableCell>]' +
-					'[<tableCell><paragraph>b</paragraph></tableCell>]' +
-					'</tableRow>' +
-					'<tableRow>' +
-					'[<tableCell><paragraph>c</paragraph></tableCell>]' +
-					'<tableCell><paragraph>d</paragraph></tableCell>' +
+							'[<tableCell><paragraph>a</paragraph></tableCell>]' +
+							'[<tableCell><paragraph>b</paragraph></tableCell>]' +
+						'</tableRow>' +
+						'<tableRow>' +
+							'[<tableCell><paragraph>c</paragraph></tableCell>]' +
+							'<tableCell><paragraph>d</paragraph></tableCell>' +
 					'</tableRow>' +
 					'</table>'
 				);
@@ -1054,9 +1008,7 @@ describe( 'Selection post-fixer', () => {
 					'</table>' +
 					'<paragraph>bar</paragraph>'
 				);
-			} );
 
-			it( 'should fix #1', () => {
 				// <table>[]<tableRow>...
 				model.change( writer => {
 					writer.setSelection(
@@ -1077,6 +1029,16 @@ describe( 'Selection post-fixer', () => {
 			} );
 
 			it( 'should fix #2 - selection in limit element & before limit+object element', () => {
+				setModelData( model,
+					'<paragraph>foo</paragraph>' +
+					'<table>' +
+						'<tableRow>' +
+							'<tableCell><paragraph>aaa</paragraph></tableCell>' +
+							'<tableCell><paragraph>bbb</paragraph></tableCell>' +
+						'</tableRow>' +
+					'</table>' +
+					'<paragraph>bar</paragraph>'
+				);
 				// <table><tableRow>[]<tableCell>...
 				model.change( writer => {
 					const row = modelRoot.getChild( 1 ).getChild( 0 );
@@ -1102,46 +1064,82 @@ describe( 'Selection post-fixer', () => {
 				setModelData( model,
 					'<paragraph>foo</paragraph>' +
 					'<table>' +
-					'<tableRow>' +
-					'<tableCell>[]<paragraph>aaa</paragraph></tableCell>' +
-					'</tableRow>' +
+						'<tableRow>' +
+							'<tableCell>[]<paragraph>aaa</paragraph></tableCell>' +
+						'</tableRow>' +
 					'</table>' +
 					'<paragraph>bar</paragraph>'
 				);
 
-				expect( getModelData( model ) ).to.equal(
+				assertEqualMarkup( getModelData( model ),
 					'<paragraph>foo</paragraph>' +
 					'<table>' +
-					'<tableRow>' +
-					'<tableCell><paragraph>[]aaa</paragraph></tableCell>' +
-					'</tableRow>' +
+						'<tableRow>' +
+							'<tableCell><paragraph>[]aaa</paragraph></tableCell>' +
+						'</tableRow>' +
 					'</table>' +
 					'<paragraph>bar</paragraph>'
 				);
 			} );
 
-			it( 'should not fix multiple ranges #1', () => {
+			it( 'should fix multiple ranges outside block element (but not merge them)', () => {
 				setModelData( model,
 					'[]<paragraph>foo</paragraph>[]' +
 					'<table>' +
-					'<tableRow>' +
-					'<tableCell><paragraph>aaa</paragraph></tableCell>' +
-					'</tableRow>' +
+						'<tableRow>' +
+							'<tableCell><paragraph>aaa</paragraph></tableCell>' +
+						'</tableRow>' +
 					'</table>' +
 					'<paragraph>bar</paragraph>'
 				);
 
-				expect( getModelData( model ) ).to.equal(
+				assertEqualMarkup( getModelData( model ),
 					'<paragraph>[]foo[]</paragraph>' +
 					'<table>' +
 						'<tableRow>' +
 							'<tableCell><paragraph>aaa</paragraph></tableCell>' +
-							'<tableCell><paragraph>bbb</paragraph></tableCell>' +
 						'</tableRow>' +
 					'</table>' +
 					'<paragraph>bar</paragraph>'
 				);
 			} );
+
+			it( 'should fix selection between tables', () => {
+				setModelData( model,
+					'<paragraph>foo</paragraph>' +
+					'<table>' +
+						'<tableRow>' +
+							'<tableCell><paragraph>aaa</paragraph></tableCell>' +
+							'<tableCell><paragraph>bbb</paragraph></tableCell>' +
+						'</tableRow>' +
+					'</table>' +
+					'[]' +
+					'<table>' +
+						'<tableRow>' +
+							'<tableCell><paragraph>xxx</paragraph></tableCell>' +
+							'<tableCell><paragraph>yyy</paragraph></tableCell>' +
+						'</tableRow>' +
+					'</table>' +
+					'<paragraph>baz</paragraph>'
+				);
+
+				assertEqualMarkup( getModelData( model ),
+					'<paragraph>foo</paragraph>' +
+					'[<table>' +
+						'<tableRow>' +
+							'<tableCell><paragraph>aaa</paragraph></tableCell>' +
+							'<tableCell><paragraph>bbb</paragraph></tableCell>' +
+						'</tableRow>' +
+					'</table>]' +
+					'<table>' +
+						'<tableRow>' +
+							'<tableCell><paragraph>xxx</paragraph></tableCell>' +
+							'<tableCell><paragraph>yyy</paragraph></tableCell>' +
+						'</tableRow>' +
+					'</table>' +
+					'<paragraph>baz</paragraph>'
+				);
+			} );
 		} );
 	} );
 } );