| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- /**
- * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
- import Document from '../../../src/model/document';
- import Position from '../../../src/model/position';
- import MoveDelta from '../../../src/model/delta/movedelta';
- import MoveOperation from '../../../src/model/operation/moveoperation';
- describe( 'MoveDelta', () => {
- let moveDelta, doc, root;
- beforeEach( () => {
- doc = new Document();
- root = doc.createRoot();
- moveDelta = new MoveDelta();
- } );
- describe( 'constructor()', () => {
- it( 'should create move delta with no operations added', () => {
- expect( moveDelta.operations.length ).to.equal( 0 );
- } );
- } );
- describe( 'type', () => {
- it( 'should be equal to move', () => {
- expect( moveDelta.type ).to.equal( 'move' );
- } );
- } );
- describe( 'sourcePosition', () => {
- it( 'should be null if there are no operations in delta', () => {
- expect( moveDelta.sourcePosition ).to.be.null;
- } );
- it( 'should be equal to the position where node is inserted', () => {
- moveDelta.operations.push( new MoveOperation( new Position( root, [ 1, 1 ] ), 2, new Position( root, [ 2, 2 ] ), 0 ) );
- expect( moveDelta.sourcePosition.root ).to.equal( root );
- expect( moveDelta.sourcePosition.path ).to.deep.equal( [ 1, 1 ] );
- } );
- } );
- describe( 'howMany', () => {
- it( 'should be null if there are no operations in delta', () => {
- expect( moveDelta.howMany ).to.be.null;
- } );
- it( 'should be equal to the position where node is inserted', () => {
- moveDelta.operations.push( new MoveOperation( new Position( root, [ 1, 1 ] ), 2, new Position( root, [ 2, 2 ] ), 0 ) );
- expect( moveDelta.howMany ).to.equal( 2 );
- } );
- } );
- describe( 'targetPosition', () => {
- it( 'should be null if there are no operations in delta', () => {
- expect( moveDelta.targetPosition ).to.be.null;
- } );
- it( 'should be equal to the move operation\'s target position', () => {
- moveDelta.operations.push( new MoveOperation( new Position( root, [ 1, 1 ] ), 2, new Position( root, [ 2, 2 ] ), 0 ) );
- expect( moveDelta.targetPosition.root ).to.equal( root );
- expect( moveDelta.targetPosition.path ).to.deep.equal( [ 2, 2 ] );
- } );
- } );
- describe( 'getReversed', () => {
- it( 'should return empty MoveDelta if there are no operations in delta', () => {
- const reversed = moveDelta.getReversed();
- expect( reversed ).to.be.instanceof( MoveDelta );
- expect( reversed.operations.length ).to.equal( 0 );
- } );
- it( 'should return correct MoveDelta', () => {
- moveDelta.operations.push( new MoveOperation( new Position( root, [ 1, 1 ] ), 2, new Position( root, [ 2, 2 ] ), 0 ) );
- const reversed = moveDelta.getReversed();
- expect( reversed ).to.be.instanceof( MoveDelta );
- expect( reversed.operations.length ).to.equal( 1 );
- expect( reversed.operations[ 0 ] ).to.be.instanceof( MoveOperation );
- expect( reversed.operations[ 0 ].sourcePosition.path ).to.deep.equal( [ 2, 2 ] );
- expect( reversed.operations[ 0 ].howMany ).to.equal( 2 );
- expect( reversed.operations[ 0 ].targetPosition.path ).to.deep.equal( [ 1, 1 ] );
- } );
- } );
- it( 'should provide proper className', () => {
- expect( MoveDelta.className ).to.equal( 'engine.model.delta.MoveDelta' );
- } );
- } );
|