|
|
@@ -224,6 +224,56 @@ describe( 'Selection', () => {
|
|
|
} );
|
|
|
} );
|
|
|
|
|
|
+ describe( 'isEqual', () => {
|
|
|
+ it( 'should return true if selections equal', () => {
|
|
|
+ selection.addRange( range1 );
|
|
|
+ selection.addRange( range2 );
|
|
|
+
|
|
|
+ const otherSelection = new Selection();
|
|
|
+ otherSelection.addRange( range1 );
|
|
|
+ otherSelection.addRange( range2 );
|
|
|
+
|
|
|
+ expect( selection.isEqual( otherSelection ) ).to.be.true;
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'should return true if backward selections equal', () => {
|
|
|
+ selection.addRange( range1, true );
|
|
|
+
|
|
|
+ const otherSelection = new Selection();
|
|
|
+ otherSelection.addRange( range1, true );
|
|
|
+
|
|
|
+ expect( selection.isEqual( otherSelection ) ).to.be.true;
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'should return false if ranges count does not equal', () => {
|
|
|
+ selection.addRange( range1 );
|
|
|
+ selection.addRange( range2 );
|
|
|
+
|
|
|
+ const otherSelection = new Selection();
|
|
|
+ otherSelection.addRange( range1 );
|
|
|
+
|
|
|
+ expect( selection.isEqual( otherSelection ) ).to.be.false;
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'should return false if ranges do not equal', () => {
|
|
|
+ selection.addRange( range1 );
|
|
|
+
|
|
|
+ const otherSelection = new Selection();
|
|
|
+ otherSelection.addRange( range2 );
|
|
|
+
|
|
|
+ expect( selection.isEqual( otherSelection ) ).to.be.false;
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'should return false if directions do not equal', () => {
|
|
|
+ selection.addRange( range1 );
|
|
|
+
|
|
|
+ const otherSelection = new Selection();
|
|
|
+ otherSelection.addRange( range2, true );
|
|
|
+
|
|
|
+ expect( selection.isEqual( otherSelection ) ).to.be.false;
|
|
|
+ } );
|
|
|
+ } );
|
|
|
+
|
|
|
describe( 'removeAllRanges', () => {
|
|
|
it( 'should remove all ranges and fire change event', ( done ) => {
|
|
|
selection.addRange( range1 );
|
|
|
@@ -263,6 +313,26 @@ describe( 'Selection', () => {
|
|
|
} );
|
|
|
} );
|
|
|
|
|
|
+ describe( 'setTo', () => {
|
|
|
+ it( 'should return true if selections equal', () => {
|
|
|
+ selection.addRange( range1 );
|
|
|
+
|
|
|
+ const otherSelection = new Selection();
|
|
|
+ otherSelection.addRange( range2 );
|
|
|
+ otherSelection.addRange( range3, true );
|
|
|
+
|
|
|
+ selection.setTo( otherSelection );
|
|
|
+
|
|
|
+ expect( selection.rangeCount ).to.equal( 2 );
|
|
|
+ expect( selection._ranges[ 0 ].isEqual( range2 ) ).to.be.true;
|
|
|
+ expect( selection._ranges[ 0 ] ).is.not.equal( range2 );
|
|
|
+ expect( selection._ranges[ 1 ].isEqual( range3 ) ).to.be.true;
|
|
|
+ expect( selection._ranges[ 1 ] ).is.not.equal( range3 );
|
|
|
+
|
|
|
+ expect( selection.anchor.isEqual( range3.end ) ).to.be.true;
|
|
|
+ } );
|
|
|
+ } );
|
|
|
+
|
|
|
describe( 'collapseToStart', () => {
|
|
|
it( 'should collapse to start position and fire change event', ( done ) => {
|
|
|
selection.setRanges( [ range1, range2, range3 ] );
|