Jelajahi Sumber

Changed withSelection option in view's and model's test utilities to withoutSelection.

Szymon Kupś 9 tahun lalu
induk
melakukan
aebf94aba2

+ 3 - 3
packages/ckeditor5-engine/tests/_utils-tests/model.js

@@ -33,7 +33,7 @@ describe( 'model test utils', () => {
 			const stringifySpy = sandbox.spy( getData, '_stringify' );
 			root.appendChildren( new Element( 'b', null, [ 'btext' ] ) );
 
-			expect( getData( document ) ).to.equal( '<b>btext</b>' );
+			expect( getData( document, { withoutSelection: true } ) ).to.equal( '<b>btext</b>' );
 			sinon.assert.calledOnce( stringifySpy );
 			sinon.assert.calledWithExactly( stringifySpy, root );
 		} );
@@ -57,7 +57,7 @@ describe( 'model test utils', () => {
 
 			setData( document, data, options );
 
-			expect( getData( document ) ).to.equal( data );
+			expect( getData( document, { withoutSelection: true } ) ).to.equal( data );
 			sinon.assert.calledOnce( parseSpy );
 			const args = parseSpy.firstCall.args;
 			expect( args[ 0 ] ).to.equal( data );
@@ -66,7 +66,7 @@ describe( 'model test utils', () => {
 		it( 'should use parse method with selection', () => {
 			const parseSpy = sandbox.spy( setData, '_parse' );
 			const options = {};
-			const data = '[<b>btext</b>]';
+			const data = '<selection><b>btext</b></selection>';
 
 			setData( document, data, options );
 

+ 2 - 2
packages/ckeditor5-engine/tests/_utils-tests/view.js

@@ -33,7 +33,7 @@ describe( 'view test utils', () => {
 				const element = document.createElement( 'div' );
 				const stringifySpy = sandbox.spy( getData, '_stringify' );
 				const treeView = new TreeView();
-				const options = { showType: false, showPriority: false };
+				const options = { showType: false, showPriority: false, withoutSelection: true };
 				const root = treeView.createRoot( element );
 				root.appendChildren( new Element( 'p' ) );
 
@@ -51,7 +51,7 @@ describe( 'view test utils', () => {
 				const element = document.createElement( 'div' );
 				const stringifySpy = sandbox.spy( getData, '_stringify' );
 				const treeView = new TreeView();
-				const options = { withSelection: true, showType: false, showPriority: false };
+				const options = { showType: false, showPriority: false };
 				const root = treeView.createRoot( element );
 				root.appendChildren( new Element( 'p' ) );
 

+ 4 - 3
packages/ckeditor5-engine/tests/_utils/model.js

@@ -20,17 +20,18 @@ import Document from '/ckeditor5/engine/treemodel/document.js';
  *
  * @param {engine.treeModel.Document} document
  * @param {Object} [options]
- * @param {Boolean} [options.withSelection] Whether to write the selection.
+ * @param {Boolean} [options.withoutSelection=false] Whether to write the selection. When set to `true` selection will
+ * be not included in returned string.
  * @param {Boolean} [options.rootName='main'] Name of the root from which data should be stringified. If not provided
  * default `main` name will be used.
  * @returns {String} The stringified data.
  */
 export function getData( document, options = {} ) {
-	const withSelection = !!options.withSelection;
+	const withoutSelection = !!options.withoutSelection;
 	const rootName = options.rootName || 'main';
 	const root = document.getRoot( rootName );
 
-	return withSelection ? getData._stringify( root, document.selection ) : getData._stringify( root );
+	return withoutSelection ? getData._stringify( root ) : getData._stringify( root, document.selection );
 }
 
 // Set stringify as getData private method - needed for testing/spying.

+ 6 - 5
packages/ckeditor5-engine/tests/_utils/view.js

@@ -28,7 +28,8 @@ const TEXT_RANGE_END_TOKEN = '}';
  *
  * @param {engine.treeView.TreeView} treeView
  * @param {Object} [options]
- * @param {Boolean} [options.withSelection=false] Whether to write the selection.
+ * @param {Boolean} [options.withoutSelection=false] Whether to write the selection. When set to `true` selection will
+ * be not included in returned string.
  * @param {Boolean} [options.rootName='main'] Name of the root from which data should be stringified. If not provided
  * default `main` name will be used.
  * @param {Boolean} [options.showType=false] When set to `true` type of elements will be printed (`<container:p>`
@@ -38,7 +39,7 @@ const TEXT_RANGE_END_TOKEN = '}';
  * @returns {String} The stringified data.
  */
 export function getData( treeView, options = {} ) {
-	const withSelection = !!options.withSelection;
+	const withoutSelection = !!options.withoutSelection;
 	const rootName = options.rootName || 'main';
 	const root = treeView.getRoot( rootName );
 	const stringifyOptions = {
@@ -47,9 +48,9 @@ export function getData( treeView, options = {} ) {
 		ignoreRoot: true
 	};
 
-	return withSelection ?
-		getData._stringify( root, treeView.selection, stringifyOptions ) :
-		getData._stringify( root, null, stringifyOptions );
+	return withoutSelection ?
+		getData._stringify( root, null, stringifyOptions ) :
+		getData._stringify( root, treeView.selection, stringifyOptions );
 }
 
 // Set stringify as getData private method - needed for testing/spying.

+ 2 - 2
packages/ckeditor5-engine/tests/treemodel/composer/composer.js

@@ -29,7 +29,7 @@ describe( 'Composer', () => {
 
 			composer.fire( 'deleteContents', { batch, selection: document.selection } );
 
-			expect( getData( document ) ).to.equal( '<p>f</p><p>r</p>' );
+			expect( getData( document ) ).to.equal( '<p>f<selection /></p><p>r</p>' );
 			expect( batch.deltas ).to.not.be.empty;
 		} );
 
@@ -44,7 +44,7 @@ describe( 'Composer', () => {
 				options: { merge: true }
 			} );
 
-			expect( getData( document ) ).to.equal( '<p>fr</p>' );
+			expect( getData( document ) ).to.equal( '<p>f<selection />r</p>' );
 		} );
 
 		it( 'attaches modifySelection default listener', () => {