Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Tests: Added tests for MarkerDelta transformations.
Browse files Browse the repository at this point in the history
  • Loading branch information
scofalik committed Mar 6, 2017
1 parent 0be43c2 commit d6bcde4
Showing 1 changed file with 145 additions and 8 deletions.
153 changes: 145 additions & 8 deletions tests/model/delta/transform/markerdelta.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ import {
expectDelta,
getFilledDocument,
getMarkerDelta,
getSplitDelta
getSplitDelta,
getMergeDelta,
getWrapDelta,
getUnwrapDelta
} from '../../../model/delta/transform/_utils/utils';

describe( 'transform', () => {
Expand All @@ -33,16 +36,16 @@ describe( 'transform', () => {
} );

describe( 'MarkerDelta by', () => {
let markerDelta;
describe( 'SplitDelta', () => {
let markerDelta;

beforeEach( () => {
const oldRange = new Range( new Position( root, [ 3, 0 ] ), new Position( root, [ 3, 3 ] ) );
const newRange = new Range( new Position( root, [ 3, 3, 3, 2 ] ), new Position( root, [ 3, 3, 3, 6 ] ) );
beforeEach( () => {
const oldRange = new Range( new Position( root, [ 3, 0 ] ), new Position( root, [ 3, 3 ] ) );
const newRange = new Range( new Position( root, [ 3, 3, 3, 2 ] ), new Position( root, [ 3, 3, 3, 6 ] ) );

markerDelta = getMarkerDelta( 'name', oldRange, newRange, baseVersion );
} );
markerDelta = getMarkerDelta( 'name', oldRange, newRange, baseVersion );
} );

describe( 'SplitDelta', () => {
it( 'split inside oldRange', () => {
let splitDelta = getSplitDelta( new Position( root, [ 3, 1 ] ), new Element( 'div' ), 3, baseVersion );
let transformed = transform( markerDelta, splitDelta );
Expand Down Expand Up @@ -93,5 +96,139 @@ describe( 'transform', () => {
} );
} );
} );

describe( 'MergeDelta', () => {
it( 'collapsed marker in merged element', () => {
// MarkerDelta with collapsed range, which changes from the beginning of merged element to the end.
const oldRange = new Range( new Position( root, [ 3, 3, 3, 0 ] ) );
const newRange = new Range( new Position( root, [ 3, 3, 3, 12 ] ) );

const markerDelta = getMarkerDelta( 'name', oldRange, newRange, baseVersion );

// MergeDelta merges the element in which is collapsed marker range with the previous element.
const mergeDelta = getMergeDelta( new Position( root, [ 3, 3, 3 ] ), 4, 12, baseVersion );

const transformed = transform( markerDelta, mergeDelta );

// It is expected, that ranges in MarkerDelta got correctly transformed:
// from start of merged element to the place where merged nodes where moved in the previous element,
// from end of merged element to the end of previous element.
const expectedOldRange = new Range( new Position( root, [ 3, 3, 2, 4 ] ), new Position( root, [ 3, 3, 2, 4 ] ) );
const expectedNewRange = new Range( new Position( root, [ 3, 3, 2, 16 ] ), new Position( root, [ 3, 3, 2, 16 ] ) );

expectDelta( transformed[ 0 ], {
type: MarkerDelta,
operations: [
{
type: MarkerOperation,
name: 'name',
oldRange: expectedOldRange,
newRange: expectedNewRange,
baseVersion: baseVersion + 2
}
]
} );
} );
} );

describe( 'WrapDelta', () => {
it( 'ranges intersecting with wrapped range', () => {
// MarkerDelta with ranges that intersects with wrapped range.
const oldRange = new Range( new Position( root, [ 0, 2 ] ), new Position( root, [ 1, 2 ] ) );
const newRange = new Range( new Position( root, [ 1, 2 ] ), new Position( root, [ 2, 2 ] ) );

const markerDelta = getMarkerDelta( 'name', oldRange, newRange, baseVersion );

// Wrap delta wraps element on position ( root [ 1 ] ), which intersects with both `oldRange` and `newRange`.
const wrapElement = new Element( 'w' );
const wrapRange = new Range( new Position( root, [ 1 ] ), new Position( root, [ 2 ] ) );
const wrapDelta = getWrapDelta( wrapRange, wrapElement, baseVersion );

const transformed = transform( markerDelta, wrapDelta );

// It is expected, that ranges in MarkerDelta got correctly transformed:
// `oldRange` end is in wrapped element,
// `newRange` start is in wrapped element.
const expectedOldRange = new Range( new Position( root, [ 0, 2 ] ), new Position( root, [ 1, 0, 2 ] ) );
const expectedNewRange = new Range( new Position( root, [ 1, 0, 2 ] ), new Position( root, [ 2, 2 ] ) );

expectDelta( transformed[ 0 ], {
type: MarkerDelta,
operations: [
{
type: MarkerOperation,
name: 'name',
oldRange: expectedOldRange,
newRange: expectedNewRange,
baseVersion: baseVersion + 2
}
]
} );
} );
} );

describe( 'UnwrapDelta', () => {
it( 'ranges intersecting with unwrapped element', () => {
// MarkerDelta with ranges that intersects with unwrapped element.
const oldRange = new Range( new Position( root, [ 0, 2 ] ), new Position( root, [ 1, 0, 2 ] ) );
const newRange = new Range( new Position( root, [ 1, 0, 2 ] ), new Position( root, [ 2, 2 ] ) );

const markerDelta = getMarkerDelta( 'name', oldRange, newRange, baseVersion );

// Unwrap delta unwraps element on position ( root [ 1, 0 ] ), which intersects with both `oldRange` and `newRange`.
const unwrapPosition = new Position( root, [ 1, 0 ] );
const unwrapDelta = getUnwrapDelta( unwrapPosition, 4, baseVersion );

const transformed = transform( markerDelta, unwrapDelta );

// It is expected, that ranges in MarkerDelta got correctly transformed.
const expectedOldRange = new Range( new Position( root, [ 0, 2 ] ), new Position( root, [ 1, 2 ] ) );
const expectedNewRange = new Range( new Position( root, [ 1, 2 ] ), new Position( root, [ 2, 2 ] ) );

expectDelta( transformed[ 0 ], {
type: MarkerDelta,
operations: [
{
type: MarkerOperation,
name: 'name',
oldRange: expectedOldRange,
newRange: expectedNewRange,
baseVersion: baseVersion + 2
}
]
} );
} );

it( 'ranges intersecting with unwrapped element #2', () => {
// MarkerDelta with ranges that intersects with unwrapped element.
const oldRange = new Range( new Position( root, [ 0, 2 ] ), new Position( root, [ 1, 2 ] ) );
const newRange = new Range( new Position( root, [ 1, 2 ] ), new Position( root, [ 2, 2 ] ) );

const markerDelta = getMarkerDelta( 'name', oldRange, newRange, baseVersion );

// Unwrap delta unwraps element on position ( root [ 1 ] ), which intersects with both `oldRange` and `newRange`.
const unwrapPosition = new Position( root, [ 1 ] );
const unwrapDelta = getUnwrapDelta( unwrapPosition, 4, baseVersion );

const transformed = transform( markerDelta, unwrapDelta );

// It is expected, that ranges in MarkerDelta got correctly transformed.
const expectedOldRange = new Range( new Position( root, [ 0, 2 ] ), new Position( root, [ 3 ] ) );
const expectedNewRange = new Range( new Position( root, [ 3 ] ), new Position( root, [ 5, 2 ] ) );

expectDelta( transformed[ 0 ], {
type: MarkerDelta,
operations: [
{
type: MarkerOperation,
name: 'name',
oldRange: expectedOldRange,
newRange: expectedNewRange,
baseVersion: baseVersion + 2
}
]
} );
} );
} );
} );
} );

0 comments on commit d6bcde4

Please sign in to comment.