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

Commit

Permalink
Fixed view tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
ma2ciek committed Jul 1, 2019
1 parent 237f478 commit b9d8c32
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 41 deletions.
2 changes: 1 addition & 1 deletion src/view/emptyelement.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export default class EmptyElement extends Element {
*
* @error view-emptyelement-cannot-add
*/
throw new CKEditorError( 'view-emptyelement-cannot-add: Cannot add child nodes to EmptyElement instance.' );
throw new CKEditorError( 'view-emptyelement-cannot-add: Cannot add child nodes to EmptyElement instance.', null );
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/view/treewalker.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,16 @@ export default class TreeWalker {
*
* @error view-tree-walker-no-start-position
*/
throw new CKEditorError( 'view-tree-walker-no-start-position: Neither boundaries nor starting position have been defined.' );
throw new CKEditorError(
'view-tree-walker-no-start-position: Neither boundaries nor starting position have been defined.',
null
);
}

if ( options.direction && options.direction != 'forward' && options.direction != 'backward' ) {
throw new CKEditorError(
'view-tree-walker-unknown-direction: Only `backward` and `forward` direction allowed.',
null,
{ direction: options.direction }
);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/view/attributeelement.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ describe( 'AttributeElement', () => {

expectToThrowCKEditorError( () => {
attribute.getElementsWithSameId();
}, /attribute-element-get-elements-with-same-id-no-id/, null );
}, /attribute-element-get-elements-with-same-id-no-id/ );
} );
} );

Expand Down
18 changes: 9 additions & 9 deletions tests/view/documentselection.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ describe( 'DocumentSelection', () => {
expectToThrowCKEditorError( () => {
// eslint-disable-next-line no-new
new DocumentSelection( [ { invalid: 'range' } ] );
}, /view-selection-add-range-not-range/, view );
}, /view-selection-add-range-not-range/ );
} );

it( 'should throw an error when ranges intersects', () => {
Expand All @@ -126,14 +126,14 @@ describe( 'DocumentSelection', () => {
expectToThrowCKEditorError( () => {
// eslint-disable-next-line no-new
new DocumentSelection( [ range1, range2 ] );
}, 'view-selection-range-intersects', view );
}, 'view-selection-range-intersects' );
} );

it( 'should throw an error when trying to set to not selectable', () => {
expectToThrowCKEditorError( () => {
// eslint-disable-next-line no-new
new DocumentSelection( {} );
} ).to.throw( /view-selection-setTo-not-selectable/ );
}, /view-selection-setTo-not-selectable/ );
} );
} );

Expand Down Expand Up @@ -205,7 +205,7 @@ describe( 'DocumentSelection', () => {

expectToThrowCKEditorError( () => {
documentSelection._setFocus( endPos );
}, /view-selection-setFocus-no-ranges/, view );
}, /view-selection-setFocus-no-ranges/, documentSelection );
} );

it( 'modifies existing collapsed selection', () => {
Expand Down Expand Up @@ -810,15 +810,15 @@ describe( 'DocumentSelection', () => {

expectToThrowCKEditorError( () => {
otherSelection._setTo( {} );
} ).to.throw( /view-selection-setTo-not-selectable/ );
}, /view-selection-setTo-not-selectable/ );
} );

it( 'should throw an error when trying to set to not selectable #2', () => {
const otherSelection = new DocumentSelection();

expectToThrowCKEditorError( () => {
otherSelection._setTo();
} ).to.throw( /view-selection-setTo-not-selectable/ );
}, /view-selection-setTo-not-selectable/ );
} );
} );

Expand Down Expand Up @@ -862,7 +862,7 @@ describe( 'DocumentSelection', () => {

expectToThrowCKEditorError( () => {
documentSelection._setTo( foo );
}, /view-selection-setTo-required-second-parameter/, view );
}, /view-selection-setTo-required-second-parameter/, documentSelection );
} );

it( 'should collapse selection at node and flag', () => {
Expand Down Expand Up @@ -1009,7 +1009,7 @@ describe( 'DocumentSelection', () => {
it( 'should throw an error when range is invalid', () => {
expectToThrowCKEditorError( () => {
documentSelection._setTo( [ { invalid: 'range' } ] );
}, /view-selection-add-range-not-range/, view );
}, /view-selection-add-range-not-range/, documentSelection );
} );

it( 'should throw when range is intersecting with already added range', () => {
Expand All @@ -1018,7 +1018,7 @@ describe( 'DocumentSelection', () => {

expectToThrowCKEditorError( () => {
documentSelection._setTo( [ range1, range2 ] );
}, 'view-selection-range-intersects', view );
}, 'view-selection-range-intersects', documentSelection );
} );
} );

Expand Down
12 changes: 6 additions & 6 deletions tests/view/downcastwriter/breakattributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,15 @@ describe( 'DowncastWriter', () => {

expectToThrowCKEditorError( () => {
writer.breakAttributes( Range._createFromParentsAndOffsets( p1, 0, p2, 0 ) );
}, 'view-writer-invalid-range-container', view );
}, 'view-writer-invalid-range-container', writer );
} );

it( 'should throw when range has no parent container', () => {
const el = new AttributeElement( 'b' );

expectToThrowCKEditorError( () => {
writer.breakAttributes( Range._createFromParentsAndOffsets( el, 0, el, 0 ) );
}, 'view-writer-invalid-range-container', view );
}, 'view-writer-invalid-range-container', writer );
} );

it( 'should not break text nodes if they are not in attribute elements', () => {
Expand Down Expand Up @@ -246,7 +246,7 @@ describe( 'DowncastWriter', () => {

expectToThrowCKEditorError( () => {
writer.breakAttributes( position );
}, 'view-writer-cannot-break-empty-element', view );
}, 'view-writer-cannot-break-empty-element', writer );
} );

it( 'should throw if breaking inside EmptyElement #2', () => {
Expand All @@ -257,7 +257,7 @@ describe( 'DowncastWriter', () => {

expectToThrowCKEditorError( () => {
writer.breakAttributes( range );
}, 'view-writer-cannot-break-empty-element', view );
}, 'view-writer-cannot-break-empty-element', writer );
} );

it( 'should throw if breaking inside UIElement #1', () => {
Expand All @@ -267,7 +267,7 @@ describe( 'DowncastWriter', () => {

expectToThrowCKEditorError( () => {
writer.breakAttributes( position );
}, 'view-writer-cannot-break-ui-element', view );
}, 'view-writer-cannot-break-ui-element', writer );
} );

it( 'should throw if breaking inside UIElement #2', () => {
Expand All @@ -278,7 +278,7 @@ describe( 'DowncastWriter', () => {

expectToThrowCKEditorError( () => {
writer.breakAttributes( range );
}, 'view-writer-cannot-break-ui-element', view );
}, 'view-writer-cannot-break-ui-element', writer );
} );
} );
} );
Expand Down
4 changes: 2 additions & 2 deletions tests/view/downcastwriter/breakcontainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe( 'DowncastWriter', () => {

expectToThrowCKEditorError( () => {
writer.breakContainer( selection.getFirstPosition() );
}, /view-writer-break-non-container-element/, view );
}, /view-writer-break-non-container-element/, writer );
} );

it( 'should throw if position parent is root', () => {
Expand All @@ -78,7 +78,7 @@ describe( 'DowncastWriter', () => {

expectToThrowCKEditorError( () => {
writer.breakContainer( position );
}, /view-writer-break-root/, view );
}, /view-writer-break-root/, writer );
} );
} );
} );
4 changes: 2 additions & 2 deletions tests/view/downcastwriter/clear.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ describe( 'DowncastWriter', () => {

expectToThrowCKEditorError( () => {
writer.clear( Range._createFromParentsAndOffsets( p1, 0, p2, 0 ) );
}, 'view-writer-invalid-range-container', view );
}, 'view-writer-invalid-range-container', writer );
} );

it( 'should throw when range has no parent container', () => {
const el = new AttributeElement( 'b' );

expectToThrowCKEditorError( () => {
writer.clear( Range._createFromParentsAndOffsets( el, 0, el, 0 ) );
}, 'view-writer-invalid-range-container', view );
}, 'view-writer-invalid-range-container', writer );
} );

it( 'should remove matched element from range', () => {
Expand Down
11 changes: 6 additions & 5 deletions tests/view/downcastwriter/insert.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,10 @@ describe( 'DowncastWriter', () => {
const element = new Element( 'b' );
const container = new ContainerElement( 'p' );
const position = new Position( container, 0 );

expectToThrowCKEditorError( () => {
writer.insert( position, element );
}, 'view-writer-insert-invalid-node', view );
}, 'view-writer-insert-invalid-node', writer );
} );

it( 'should throw when Element is inserted as child node', () => {
Expand All @@ -169,7 +170,7 @@ describe( 'DowncastWriter', () => {

expectToThrowCKEditorError( () => {
writer.insert( position, root );
}, 'view-writer-insert-invalid-node', view );
}, 'view-writer-insert-invalid-node', writer );
} );

it( 'should throw when position is not placed inside container', () => {
Expand All @@ -179,7 +180,7 @@ describe( 'DowncastWriter', () => {

expectToThrowCKEditorError( () => {
writer.insert( position, attributeElement );
}, 'view-writer-invalid-position-container', view );
}, 'view-writer-invalid-position-container', writer );
} );

it( 'should allow to insert EmptyElement into container', () => {
Expand All @@ -198,7 +199,7 @@ describe( 'DowncastWriter', () => {

expectToThrowCKEditorError( () => {
writer.insert( position, attributeElement );
}, 'view-writer-cannot-break-empty-element', view );
}, 'view-writer-cannot-break-empty-element', writer );
} );

it( 'should throw if trying to insert inside UIElement', () => {
Expand All @@ -209,7 +210,7 @@ describe( 'DowncastWriter', () => {

expectToThrowCKEditorError( () => {
writer.insert( position, attributeElement );
}, 'view-writer-cannot-break-ui-element', view );
}, 'view-writer-cannot-break-ui-element', writer );
} );
} );
} );
1 change: 1 addition & 0 deletions tests/view/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import createViewRoot from './_utils/createroot';
import createElement from '@ckeditor/ckeditor5-utils/src/dom/createelement';
import normalizeHtml from '@ckeditor/ckeditor5-utils/tests/_utils/normalizehtml';
import env from '@ckeditor/ckeditor5-utils/src/env';
import { expectToThrowCKEditorError } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';

describe( 'Renderer', () => {
let selection, domConverter, renderer;
Expand Down
18 changes: 9 additions & 9 deletions tests/view/selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ describe( 'Selection', () => {
expectToThrowCKEditorError( () => {
// eslint-disable-next-line no-new
new Selection( [ { invalid: 'range' } ] );
}, /view-selection-add-range-not-range/, null );
}, /view-selection-add-range-not-range/ );
} );

it( 'should throw an error when ranges intersects', () => {
Expand All @@ -127,14 +127,14 @@ describe( 'Selection', () => {
expectToThrowCKEditorError( () => {
// eslint-disable-next-line no-new
new Selection( [ range1, range2 ] );
}, 'view-selection-range-intersects', selection );
}, 'view-selection-range-intersects' );
} );

it( 'should throw an error when trying to set to not selectable', () => {
expectToThrowCKEditorError( () => {
// eslint-disable-next-line no-new
new Selection( {} );
} ).to.throw( /view-selection-setTo-not-selectable/ );
}, /view-selection-setTo-not-selectable/ );
} );
} );

Expand Down Expand Up @@ -206,7 +206,7 @@ describe( 'Selection', () => {

expectToThrowCKEditorError( () => {
selection.setFocus( endPos );
}, /view-selection-setFocus-no-ranges/, selection );
}, /view-selection-setFocus-no-ranges/ );
} );

it( 'modifies existing collapsed selection', () => {
Expand Down Expand Up @@ -682,15 +682,15 @@ describe( 'Selection', () => {

expectToThrowCKEditorError( () => {
otherSelection.setTo( {} );
} ).to.throw( /view-selection-setTo-not-selectable/ );
}, /view-selection-setTo-not-selectable/ );
} );

it( 'should throw an error when trying to set to not selectable #2', () => {
const otherSelection = new Selection();

expectToThrowCKEditorError( () => {
otherSelection.setTo();
} ).to.throw( /view-selection-setTo-not-selectable/ );
}, /view-selection-setTo-not-selectable/ );
} );
} );

Expand Down Expand Up @@ -734,7 +734,7 @@ describe( 'Selection', () => {

expectToThrowCKEditorError( () => {
selection.setTo( foo );
}, /view-selection-setTo-required-second-parameter/, selection );
}, /view-selection-setTo-required-second-parameter/ );
} );

it( 'should collapse selection at node and flag', () => {
Expand Down Expand Up @@ -881,7 +881,7 @@ describe( 'Selection', () => {
it( 'should throw an error when range is invalid', () => {
expectToThrowCKEditorError( () => {
selection.setTo( [ { invalid: 'range' } ] );
}, /view-selection-add-range-not-range/, selection );
}, /view-selection-add-range-not-range/ );
} );

it( 'should throw when range is intersecting with already added range', () => {
Expand All @@ -890,7 +890,7 @@ describe( 'Selection', () => {

expectToThrowCKEditorError( () => {
selection.setTo( [ range1, range2 ] );
}, 'view-selection-range-intersects', selection );
}, 'view-selection-range-intersects' );
} );
} );

Expand Down
9 changes: 4 additions & 5 deletions tests/view/textproxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import ContainerElement from '../../src/view/containerelement';
import DocumentFragment from '../../src/view/documentfragment';
import RootEditableElement from '../../src/view/rooteditableelement';


import createDocumentMock from '../../tests/view/_utils/createdocumentmock';
import { expectToThrowCKEditorError } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';

Expand Down Expand Up @@ -44,21 +43,21 @@ describe( 'TextProxy', () => {
it( 'should throw if wrong offsetInText is passed', () => {
expectToThrowCKEditorError( () => {
new TextProxy( text, -1, 2 ); // eslint-disable-line no-new
}, /view-textproxy-wrong-offsetintext/, null );
}, /view-textproxy-wrong-offsetintext/ );

expectToThrowCKEditorError( () => {
new TextProxy( text, 9, 1 ); // eslint-disable-line no-new
}, /view-textproxy-wrong-offsetintext/, null );
}, /view-textproxy-wrong-offsetintext/ );
} );

it( 'should throw if wrong length is passed', () => {
expectToThrowCKEditorError( () => {
new TextProxy( text, 2, -1 ); // eslint-disable-line no-new
}, /view-textproxy-wrong-length/, null );
}, /view-textproxy-wrong-length/ );

expectToThrowCKEditorError( () => {
new TextProxy( text, 2, 9 ); // eslint-disable-line no-new
}, /view-textproxy-wrong-length/, null );
}, /view-textproxy-wrong-length/ );
} );
} );

Expand Down

0 comments on commit b9d8c32

Please sign in to comment.