| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- /**
- * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
- import Model from '../../../src/model/model';
- 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( () => {
- const model = new Model();
- doc = model.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' );
- } );
- } );
|