diff --git a/src/model/documentfragment.js b/src/model/documentfragment.js index f6eff72d2..bf9c5ce2a 100644 --- a/src/model/documentfragment.js +++ b/src/model/documentfragment.js @@ -116,15 +116,22 @@ export default class DocumentFragment { } /** - * Checks whether given model tree object is of given type. + * Checks whether this object is of the given type. * - * Read more in {@link module:engine/model/node~Node#is}. + * docFrag.is( 'documentFragment' ); // -> true + * docFrag.is( 'model:documentFragment' ); // -> true + * + * docFrag.is( 'view:documentFragment' ); // -> false + * docFrag.is( 'element' ); // -> false + * docFrag.is( 'node' ); // -> false + * + * {@link module:engine/model/node~Node#is Check the entire list of model objects} which implement the `is()` method. * * @param {String} type * @returns {Boolean} */ is( type ) { - return type == 'documentFragment'; + return type == 'documentFragment' || type == 'model:documentFragment'; } /** diff --git a/src/model/documentselection.js b/src/model/documentselection.js index 6cd82e7dd..c40412b16 100644 --- a/src/model/documentselection.js +++ b/src/model/documentselection.js @@ -367,21 +367,27 @@ export default class DocumentSelection { } /** - * Checks whether object is of given type following the convention set by - * {@link module:engine/model/node~Node#is `Node#is()`}. + * Checks whether this object is of the given type. * - * const selection = new DocumentSelection( ... ); + * selection.is( 'selection' ); // -> true + * selection.is( 'documentSelection' ); // -> true + * selection.is( 'model:selection' ); // -> true + * selection.is( 'model:documentSelection' ); // -> true * - * selection.is( 'selection' ); // true - * selection.is( 'documentSelection' ); // true - * selection.is( 'node' ); // false - * selection.is( 'element' ); // false + * selection.is( 'view:selection' ); // -> false + * selection.is( 'element' ); // -> false + * selection.is( 'node' ); // -> false + * + * {@link module:engine/model/node~Node#is Check the entire list of model objects} which implement the `is()` method. * * @param {String} type * @returns {Boolean} */ is( type ) { - return type == 'selection' || type == 'documentSelection'; + return type == 'selection' || + type == 'model:selection' || + type == 'documentSelection' || + type == 'model:documentSelection'; } /** diff --git a/src/model/element.js b/src/model/element.js index 472c88110..6058a8d05 100644 --- a/src/model/element.js +++ b/src/model/element.js @@ -89,18 +89,24 @@ export default class Element extends Node { } /** - * Checks whether this model object is of the given type. + * Checks whether this object is of the given. * - * obj.name; // 'listItem' - * obj instanceof Element; // true + * element.is( 'element' ); // -> true + * element.is( 'node' ); // -> true + * element.is( 'model:element' ); // -> true + * element.is( 'model:node' ); // -> true * - * obj.is( 'element' ); // true - * obj.is( 'listItem' ); // true - * obj.is( 'element', 'listItem' ); // true - * obj.is( 'text' ); // false - * obj.is( 'element', 'image' ); // false + * element.is( 'view:element' ); // -> false + * element.is( 'documentSelection' ); // -> false * - * Read more in {@link module:engine/model/node~Node#is `Node#is()`}. + * Assuming that the object being checked is an element, you can also check its + * {@link module:engine/model/element~Element#name name}: + * + * element.is( 'image' ); // -> true if this is an element + * element.is( 'element', 'image' ); // -> same as above + * text.is( 'image' ); -> false + * + * {@link module:engine/model/node~Node#is Check the entire list of model objects} which implement the `is()` method. * * @param {String} type Type to check when `name` parameter is present. * Otherwise, it acts like the `name` parameter. @@ -108,10 +114,12 @@ export default class Element extends Node { * @returns {Boolean} */ is( type, name = null ) { + const cutType = type.replace( /^model:/, '' ); + if ( !name ) { - return type == 'element' || type == this.name || super.is( type ); + return cutType == 'element' || cutType == this.name || super.is( type ); } else { - return type == 'element' && name == this.name; + return cutType == 'element' && name == this.name; } } diff --git a/src/model/liveposition.js b/src/model/liveposition.js index fba8d41c1..7a03cfe9d 100644 --- a/src/model/liveposition.js +++ b/src/model/liveposition.js @@ -63,6 +63,26 @@ export default class LivePosition extends Position { this.stopListening(); } + /** + * Checks whether this object is of the given. + * + * livePosition.is( 'position' ); // -> true + * livePosition.is( 'model:position' ); // -> true + * livePosition.is( 'liveposition' ); // -> true + * livePosition.is( 'model:livePosition' ); // -> true + * + * livePosition.is( 'view:position' ); // -> false + * livePosition.is( 'documentSelection' ); // -> false + * + * {@link module:engine/model/node~Node#is Check the entire list of model objects} which implement the `is()` method. + * + * @param {String} type + * @returns {Boolean} + */ + is( type ) { + return type == 'livePosition' || type == 'model:livePosition' || super.is( type ); + } + /** * Creates a {@link module:engine/model/position~Position position instance}, which is equal to this live position. * diff --git a/src/model/liverange.js b/src/model/liverange.js index 62385ea0b..034a716e5 100644 --- a/src/model/liverange.js +++ b/src/model/liverange.js @@ -40,6 +40,26 @@ export default class LiveRange extends Range { this.stopListening(); } + /** + * Checks whether this object is of the given. + * + * liveRange.is( 'range' ); // -> true + * liveRange.is( 'model:range' ); // -> true + * liveRange.is( 'liveRange' ); // -> true + * liveRange.is( 'model:liveRange' ); // -> true + * + * liveRange.is( 'view:range' ); // -> false + * liveRange.is( 'documentSelection' ); // -> false + * + * {@link module:engine/model/node~Node#is Check the entire list of model objects} which implement the `is()` method. + * + * @param {String} type + * @returns {Boolean} + */ + is( type ) { + return type == 'liveRange' || type == 'model:liveRange' || super.is( type ); + } + /** * Creates a {@link module:engine/model/range~Range range instance} that is equal to this live range. * diff --git a/src/model/markercollection.js b/src/model/markercollection.js index 8909026b4..488021640 100644 --- a/src/model/markercollection.js +++ b/src/model/markercollection.js @@ -448,6 +448,24 @@ class Marker { return this._liveRange.toRange(); } + /** + * Checks whether this object is of the given. + * + * marker.is( 'marker' ); // -> true + * marker.is( 'model:marker' ); // -> true + * + * marker.is( 'view:element' ); // -> false + * marker.is( 'documentSelection' ); // -> false + * + * {@link module:engine/model/node~Node#is Check the entire list of model objects} which implement the `is()` method. + * + * @param {String} type + * @returns {Boolean} + */ + is( type ) { + return type == 'marker' || type == 'model:marker'; + } + /** * Binds new live range to the marker and detach the old one if is attached. * diff --git a/src/model/node.js b/src/model/node.js index feb9cba38..df30fa8eb 100644 --- a/src/model/node.js +++ b/src/model/node.js @@ -396,6 +396,53 @@ export default class Node { return json; } + /** + * Checks whether this object is of the given type. + * + * This method is useful when processing model objects that are of unknown type. For example, a function + * may return a {@link module:engine/model/documentfragment~DocumentFragment} or a {@link module:engine/model/node~Node} + * that can be either a text node or an element. This method can be used to check what kind of object is returned. + * + * someObject.is( 'element' ); // -> true if this is an element + * someObject.is( 'node' ); // -> true if this is a node (a text node or an element) + * someObject.is( 'documentFragment' ); // -> true if this is a document fragment + * + * Since this method is also available on a range of view objects, you can prefix the type of the object with + * `model:` or `view:` to check, for example, if this is the model's or view's element: + * + * modelElement.is( 'model:element' ); // -> true + * modelElement.is( 'view:element' ); // -> false + * + * By using this method it is also possible to check a name of an element: + * + * imageElement.is( 'image' ); // -> true + * imageElement.is( 'element', 'image' ); // -> same as above + * imageElement.is( 'model:element', 'image' ); // -> same as above, but more precise + * + * The list of model objects which implement the `is()` method: + * + * * {@link module:engine/model/node~Node#is `Node#is()`} + * * {@link module:engine/model/text~Text#is `Text#is()`} + * * {@link module:engine/model/element~Element#is `Element#is()`} + * * {@link module:engine/model/rootelement~RootElement#is `RootElement#is()`} + * * {@link module:engine/model/position~Position#is `Position#is()`} + * * {@link module:engine/model/liveposition~LivePosition#is `LivePosition#is()`} + * * {@link module:engine/model/range~Range#is `Range#is()`} + * * {@link module:engine/model/liverange~LiveRange#is `LiveRange#is()`} + * * {@link module:engine/model/documentfragment~DocumentFragment#is `DocumentFragment#is()`} + * * {@link module:engine/model/selection~Selection#is `Selection#is()`} + * * {@link module:engine/model/documentselection~DocumentSelection#is `DocumentSelection#is()`} + * * {@link module:engine/model/markercollection~Marker#is `Marker#is()`} + * * {@link module:engine/model/textproxy~TextProxy#is `TextProxy#is()`} + * + * @method #is + * @param {String} type + * @returns {Boolean} + */ + is( type ) { + return type == 'node' || type == 'model:node'; + } + /** * Creates a copy of this node, that is a node with exactly same attributes, and returns it. * @@ -460,29 +507,6 @@ export default class Node { _clearAttributes() { this._attrs.clear(); } - - /** - * Checks whether given model tree object is of given type. - * - * This method is useful when processing model tree objects that are of unknown type. For example, a function - * may return {@link module:engine/model/documentfragment~DocumentFragment} or {@link module:engine/model/node~Node} - * that can be either text node or element. This method can be used to check what kind of object is returned. - * - * obj.is( 'node' ); // true for any node, false for document fragment and text fragment - * obj.is( 'documentFragment' ); // true for document fragment, false for any node - * obj.is( 'element' ); // true for any element, false for text node or document fragment - * obj.is( 'element', 'paragraph' ); // true only for element which name is 'paragraph' - * obj.is( 'paragraph' ); // shortcut for obj.is( 'element', 'paragraph' ) - * obj.is( 'text' ); // true for text node, false for element and document fragment - * obj.is( 'textProxy' ); // true for text proxy object - * - * @method #is - * @param {'element'|'rootElement'|'text'|'textProxy'|'documentFragment'} type - * @returns {Boolean} - */ - is( type ) { - return type == 'node'; - } } /** diff --git a/src/model/position.js b/src/model/position.js index c81fbf406..89ca090e9 100644 --- a/src/model/position.js +++ b/src/model/position.js @@ -525,6 +525,24 @@ export default class Position { } } + /** + * Checks whether this object is of the given. + * + * position.is( 'position' ); // -> true + * position.is( 'model:position' ); // -> true + * + * position.is( 'view:position' ); // -> false + * position.is( 'documentSelection' ); // -> false + * + * {@link module:engine/model/node~Node#is Check the entire list of model objects} which implement the `is()` method. + * + * @param {String} type + * @returns {Boolean} + */ + is( type ) { + return type == 'position' || type == 'model:position'; + } + /** * Checks if two positions are in the same parent. * diff --git a/src/model/range.js b/src/model/range.js index 2e7af53da..bd4390743 100644 --- a/src/model/range.js +++ b/src/model/range.js @@ -143,6 +143,24 @@ export default class Range { return this.containsPosition( pos ) || this.start.isEqual( pos ); } + /** + * Checks whether this object is of the given. + * + * range.is( 'range' ); // -> true + * range.is( 'model:range' ); // -> true + * + * range.is( 'view:range' ); // -> false + * range.is( 'documentSelection' ); // -> false + * + * {@link module:engine/model/node~Node#is Check the entire list of model objects} which implement the `is()` method. + * + * @param {String} type + * @returns {Boolean} + */ + is( type ) { + return type == 'range' || type == 'model:range'; + } + /** * Two ranges are equal if their {@link #start} and {@link #end} positions are equal. * diff --git a/src/model/rootelement.js b/src/model/rootelement.js index 72e002d3e..5d97fe006 100644 --- a/src/model/rootelement.js +++ b/src/model/rootelement.js @@ -55,13 +55,38 @@ export default class RootElement extends Element { } /** - * @inheritDoc + * Checks whether this object is of the given. + * + * rootElement.is( 'rootElement' ); // -> true + * rootElement.is( 'element' ); // -> true + * rootElement.is( 'node' ); // -> true + * rootElement.is( 'model:rootElement' ); // -> true + * rootElement.is( 'model:element' ); // -> true + * rootElement.is( 'model:node' ); // -> true + * + * rootElement.is( 'view:element' ); // -> false + * rootElement.is( 'documentFragment' ); // -> false + * + * Assuming that the object being checked is an element, you can also check its + * {@link module:engine/model/element~Element#name name}: + * + * rootElement.is( '$root' ); // -> true if this is a $root element + * rootElement.is( 'rootElement', '$root' ); // -> same as above + * text.is( '$root' ); -> false + * + * {@link module:engine/model/node~Node#is Check the entire list of model objects} which implement the `is()` method. + * + * @param {String} type Type to check when `name` parameter is present. + * Otherwise, it acts like the `name` parameter. + * @param {String} [name] Element name. + * @returns {Boolean} */ is( type, name ) { + const cutType = type.replace( 'model:', '' ); if ( !name ) { - return type == 'rootElement' || super.is( type ); + return cutType == 'rootElement' || super.is( type ); } else { - return ( type == 'rootElement' && name == this.name ) || super.is( type, name ); + return ( cutType == 'rootElement' && name == this.name ) || super.is( type, name ); } } diff --git a/src/model/selection.js b/src/model/selection.js index 83ee0bc44..2b14b49a5 100644 --- a/src/model/selection.js +++ b/src/model/selection.js @@ -623,20 +623,21 @@ export default class Selection { } /** - * Checks whether object is of given type following the convention set by - * {@link module:engine/model/node~Node#is `Node#is()`}. + * Checks whether this object is of the given. * - * const selection = new Selection( ... ); + * selection.is( 'selection' ); // -> true + * selection.is( 'model:selection' ); // -> true * - * selection.is( 'selection' ); // true - * selection.is( 'node' ); // false - * selection.is( 'element' ); // false + * selection.is( 'view:selection' ); // -> false + * selection.is( 'range' ); // -> false + * + * {@link module:engine/model/node~Node#is Check the entire list of model objects} which implement the `is()` method. * * @param {String} type * @returns {Boolean} */ is( type ) { - return type == 'selection'; + return type == 'selection' || type == 'model:selection'; } /** diff --git a/src/model/text.js b/src/model/text.js index 8bffa75e7..1af57c3de 100644 --- a/src/model/text.js +++ b/src/model/text.js @@ -63,10 +63,24 @@ export default class Text extends Node { } /** - * @inheritDoc + * Checks whether this object is of the given. + * + * text.is( 'text' ); // -> true + * text.is( 'node' ); // -> true + * text.is( 'model:text' ); // -> true + * text.is( 'model:node' ); // -> true + * + * text.is( 'view:text' ); // -> false + * text.is( 'documentSelection' ); // -> false + * + * {@link module:engine/model/node~Node#is Check the entire list of model objects} which implement the `is()` method. + * + * @param {String} type Type to check when `name` parameter is present. + * Otherwise, it acts like the `name` parameter. + * @returns {Boolean} */ is( type ) { - return type == 'text' || super.is( type ); + return type == 'text' || type == 'model:text' || super.is( type ); } /** diff --git a/src/model/textproxy.js b/src/model/textproxy.js index a59e99df4..f52051f35 100644 --- a/src/model/textproxy.js +++ b/src/model/textproxy.js @@ -173,15 +173,21 @@ export default class TextProxy { } /** - * Checks whether given model tree object is of given type. + * Checks whether this object is of the given. * - * Read more in {@link module:engine/model/node~Node#is}. + * textProxy.is( 'textProxy' ); // -> true + * textProxy.is( 'model:textProxy' ); // -> true + * + * textProxy.is( 'view:textProxy' ); // -> false + * textProxy.is( 'range' ); // -> false + * + * {@link module:engine/model/node~Node#is Check the entire list of model objects} which implement the `is()` method. * * @param {String} type * @returns {Boolean} */ is( type ) { - return type == 'textProxy'; + return type == 'textProxy' || type == 'model:textProxy'; } /** diff --git a/src/view/attributeelement.js b/src/view/attributeelement.js index 01e63195d..b6f7f95b4 100644 --- a/src/view/attributeelement.js +++ b/src/view/attributeelement.js @@ -125,13 +125,39 @@ export default class AttributeElement extends Element { } /** - * @inheritDoc + * Checks whether this object is of the given. + * + * attributeElement.is( 'attributeElement' ); // -> true + * attributeElement.is( 'element' ); // -> true + * attributeElement.is( 'node' ); // -> true + * attributeElement.is( 'view:attributeElement' ); // -> true + * attributeElement.is( 'view:element' ); // -> true + * attributeElement.is( 'view:node' ); // -> true + * + * attributeElement.is( 'model:element' ); // -> false + * attributeElement.is( 'documentFragment' ); // -> false + * + * Assuming that the object being checked is an attribute element, you can also check its + * {@link module:engine/view/attributeelement~AttributeElement#name name}: + * + * attributeElement.is( 'b' ); // -> true if this is a bold element + * attributeElement.is( 'attributeElement', 'b' ); // -> same as above + * text.is( 'b' ); -> false + * + * {@link module:engine/view/node~Node#is Check the entire list of view objects} which implement the `is()` method. + * + * @param {String} type Type to check when `name` parameter is present. + * Otherwise, it acts like the `name` parameter. + * @param {String} [name] Element name. + * @returns {Boolean} */ is( type, name = null ) { + const cutType = type && type.replace( /^view:/, '' ); + if ( !name ) { - return type == 'attributeElement' || super.is( type ); + return cutType == 'attributeElement' || super.is( type ); } else { - return ( type == 'attributeElement' && name == this.name ) || super.is( type, name ); + return ( cutType == 'attributeElement' && name == this.name ) || super.is( type, name ); } } diff --git a/src/view/containerelement.js b/src/view/containerelement.js index 8333b9362..cf929fa2c 100644 --- a/src/view/containerelement.js +++ b/src/view/containerelement.js @@ -51,13 +51,38 @@ export default class ContainerElement extends Element { } /** - * @inheritDoc + * Checks whether this object is of the given. + * + * containerElement.is( 'containerElement' ); // -> true + * containerElement.is( 'element' ); // -> true + * containerElement.is( 'node' ); // -> true + * containerElement.is( 'view:containerElement' ); // -> true + * containerElement.is( 'view:element' ); // -> true + * containerElement.is( 'view:node' ); // -> true + * + * containerElement.is( 'model:element' ); // -> false + * containerElement.is( 'documentFragment' ); // -> false + * + * Assuming that the object being checked is a container element, you can also check its + * {@link module:engine/view/containerelement~ContainerElement#name name}: + * + * containerElement.is( 'div' ); // -> true if this is a div container element + * containerElement.is( 'contaienrElement', 'div' ); // -> same as above + * text.is( 'div' ); -> false + * + * {@link module:engine/view/node~Node#is Check the entire list of view objects} which implement the `is()` method. + * + * @param {String} type Type to check when `name` parameter is present. + * Otherwise, it acts like the `name` parameter. + * @param {String} [name] Element name. + * @returns {Boolean} */ is( type, name = null ) { + const cutType = type && type.replace( /^view:/, '' ); if ( !name ) { - return type == 'containerElement' || super.is( type ); + return cutType == 'containerElement' || super.is( type ); } else { - return ( type == 'containerElement' && name == this.name ) || super.is( type, name ); + return ( cutType == 'containerElement' && name == this.name ) || super.is( type, name ); } } } diff --git a/src/view/documentfragment.js b/src/view/documentfragment.js index 447086b64..bbb7044a3 100644 --- a/src/view/documentfragment.js +++ b/src/view/documentfragment.js @@ -94,15 +94,22 @@ export default class DocumentFragment { } /** - * Checks whether given view tree object is of given type. + * Checks whether this object is of the given type. * - * Read more in {@link module:engine/view/node~Node#is}. + * docFrag.is( 'documentFragment' ); // -> true + * docFrag.is( 'view:documentFragment' ); // -> true + * + * docFrag.is( 'model:documentFragment' ); // -> false + * docFrag.is( 'element' ); // -> false + * docFrag.is( 'node' ); // -> false + * + * {@link module:engine/view/node~Node#is Check the entire list of view objects} which implement the `is()` method. * * @param {String} type * @returns {Boolean} */ is( type ) { - return type == 'documentFragment'; + return type == 'documentFragment' || type == 'view:documentFragment'; } /** diff --git a/src/view/documentselection.js b/src/view/documentselection.js index f287f4d66..c0d1d29fd 100644 --- a/src/view/documentselection.js +++ b/src/view/documentselection.js @@ -275,21 +275,27 @@ export default class DocumentSelection { } /** - * Checks whether object is of given type following the convention set by - * {@link module:engine/view/node~Node#is `Node#is()`}. + * Checks whether this object is of the given type. * - * const selection = new DocumentSelection( ... ); + * docSelection.is( 'selection' ); // -> true + * docSelection.is( 'documentSelection' ); // -> true + * docSelection.is( 'view:selection' ); // -> true + * docSelection.is( 'view:documentSelection' ); // -> true * - * selection.is( 'selection' ); // true - * selection.is( 'documentSelection' ); // true - * selection.is( 'node' ); // false - * selection.is( 'element' ); // false + * docSelection.is( 'model:documentSelection' ); // -> false + * docSelection.is( 'element' ); // -> false + * docSelection.is( 'node' ); // -> false + * + * {@link module:engine/view/node~Node#is Check the entire list of view objects} which implement the `is()` method. * * @param {String} type * @returns {Boolean} */ is( type ) { - return type == 'selection' || type == 'documentSelection'; + return type == 'selection' || + type == 'documentSelection' || + type == 'view:selection' || + type == 'view:documentSelection'; } /** diff --git a/src/view/editableelement.js b/src/view/editableelement.js index c1ce04409..5d31754d3 100644 --- a/src/view/editableelement.js +++ b/src/view/editableelement.js @@ -67,13 +67,38 @@ export default class EditableElement extends ContainerElement { } /** - * @inheritDoc + * Checks whether this object is of the given. + * + * editableElement.is( 'editableElement' ); // -> true + * editableElement.is( 'element' ); // -> true + * editableElement.is( 'node' ); // -> true + * editableElement.is( 'view:editableElement' ); // -> true + * editableElement.is( 'view:element' ); // -> true + * editableElement.is( 'view:node' ); // -> true + * + * editableElement.is( 'model:element' ); // -> false + * editableElement.is( 'documentFragment' ); // -> false + * + * Assuming that the object being checked is an editbale element, you can also check its + * {@link module:engine/view/editableelement~EditableElement#name name}: + * + * editableElement.is( 'div' ); // -> true if this is a div element + * editableElement.is( 'editableElement', 'div' ); // -> same as above + * text.is( 'div' ); -> false + * + * {@link module:engine/view/node~Node#is Check the entire list of view objects} which implement the `is()` method. + * + * @param {String} type Type to check when `name` parameter is present. + * Otherwise, it acts like the `name` parameter. + * @param {String} [name] Element name. + * @returns {Boolean} */ is( type, name = null ) { + const cutType = type && type.replace( /^view:/, '' ); if ( !name ) { - return type == 'editableElement' || super.is( type ); + return cutType == 'editableElement' || super.is( type ); } else { - return ( type == 'editableElement' && name == this.name ) || super.is( type, name ); + return ( cutType == 'editableElement' && name == this.name ) || super.is( type, name ); } } diff --git a/src/view/element.js b/src/view/element.js index 2965bfe0b..d31d70ff7 100644 --- a/src/view/element.js +++ b/src/view/element.js @@ -147,25 +147,36 @@ export default class Element extends Node { } /** - * Checks whether this view object is of the given type. + * Checks whether this object is of the given. * - * obj.is( 'element' ); // true - * obj.is( 'li' ); // true - * obj.is( 'element', 'li' ); // true - * obj.is( 'text' ); // false - * obj.is( 'element', 'img' ); // false + * element.is( 'element' ); // -> true + * element.is( 'node' ); // -> true + * element.is( 'view:element' ); // -> true + * element.is( 'view:node' ); // -> true * - * Read more in {@link module:engine/view/node~Node#is `Node#is()`}. + * element.is( 'model:element' ); // -> false + * element.is( 'documentSelection' ); // -> false * - * @param {String} type + * Assuming that the object being checked is an element, you can also check its + * {@link module:engine/view/element~Element#name name}: + * + * element.is( 'img' ); // -> true if this is an element + * element.is( 'element', 'img' ); // -> same as above + * text.is( 'img' ); -> false + * + * {@link module:engine/view/node~Node#is Check the entire list of view objects} which implement the `is()` method. + * + * @param {String} type Type to check when `name` parameter is present. + * Otherwise, it acts like the `name` parameter. * @param {String} [name] Element name. * @returns {Boolean} */ is( type, name = null ) { + const cutType = type.replace( /^view:/, '' ); if ( !name ) { - return type == 'element' || type == this.name || super.is( type ); + return cutType == 'element' || cutType == this.name || super.is( type ); } else { - return type == 'element' && name == this.name; + return cutType == 'element' && name == this.name; } } diff --git a/src/view/emptyelement.js b/src/view/emptyelement.js index 8973cb1c9..812e028e4 100644 --- a/src/view/emptyelement.js +++ b/src/view/emptyelement.js @@ -44,13 +44,38 @@ export default class EmptyElement extends Element { } /** - * @inheritDoc + * Checks whether this object is of the given. + * + * emptyElement.is( 'emptyElement' ); // -> true + * emptyElement.is( 'element' ); // -> true + * emptyElement.is( 'node' ); // -> true + * emptyElement.is( 'view:emptyElement' ); // -> true + * emptyElement.is( 'view:element' ); // -> true + * emptyElement.is( 'view:node' ); // -> true + * + * emptyElement.is( 'model:element' ); // -> false + * emptyElement.is( 'documentFragment' ); // -> false + * + * Assuming that the object being checked is an empty element, you can also check its + * {@link module:engine/view/emptyelement~EmptyElement#name name}: + * + * emptyElement.is( 'img' ); // -> true if this is a img element + * emptyElement.is( 'emptyElement', 'img' ); // -> same as above + * text.is( 'img' ); -> false + * + * {@link module:engine/view/node~Node#is Check the entire list of view objects} which implement the `is()` method. + * + * @param {String} type Type to check when `name` parameter is present. + * Otherwise, it acts like the `name` parameter. + * @param {String} [name] Element name. + * @returns {Boolean} */ is( type, name = null ) { + const cutType = type.replace( /^view:/, '' ); if ( !name ) { - return type == 'emptyElement' || super.is( type ); + return cutType == 'emptyElement' || super.is( type ); } else { - return ( type == 'emptyElement' && name == this.name ) || super.is( type, name ); + return ( cutType == 'emptyElement' && name == this.name ) || super.is( type, name ); } } diff --git a/src/view/node.js b/src/view/node.js index 6b9361d86..9458d4e07 100644 --- a/src/view/node.js +++ b/src/view/node.js @@ -290,25 +290,52 @@ export default class Node { } /** - * Checks whether this view object is of the given type. + * Checks whether this object is of the given type. * - * This method is useful when processing view tree objects that are of unknown type. For example, a function - * may return {@link module:engine/view/documentfragment~DocumentFragment} or {@link module:engine/view/node~Node} - * that can be either text node or element. This method can be used to check what kind of object is returned. + * This method is useful when processing view objects that are of unknown type. For example, a function + * may return a {@link module:engine/view/documentfragment~DocumentFragment} or a {@link module:engine/view/node~Node} + * that can be either a text node or an element. This method can be used to check what kind of object is returned. * - * obj.is( 'node' ); // true for any node, false for document fragment and text fragment - * obj.is( 'documentFragment' ); // true for document fragment, false for any node - * obj.is( 'element' ); // true for any element, false for text node or document fragment - * obj.is( 'element', 'p' ); // true only for element which name is 'p' - * obj.is( 'p' ); // shortcut for obj.is( 'element', 'p' ) - * obj.is( 'text' ); // true for text node, false for element and document fragment + * someObject.is( 'element' ); // -> true if this is an element + * someObject.is( 'node' ); // -> true if this is a node (a text node or an element) + * someObject.is( 'documentFragment' ); // -> true if this is a document fragment * - * @param {'element'|'containerElement'|'attributeElement'|'emptyElement'|'uiElement'| - * 'rootElement'|'documentFragment'|'text'|'textProxy'} type + * Since this method is also available on a range of model objects, you can prefix the type of the object with + * `model:` or `view:` to check, for example, if this is the model's or view's element: + * + * viewElement.is( 'view:element' ); // -> true + * viewElement.is( 'model:element' ); // -> false + * + * By using this method it is also possible to check a name of an element: + * + * imgElement.is( 'img' ); // -> true + * imgElement.is( 'element', 'img' ); // -> same as above + * imgElement.is( 'view:element', 'img' ); // -> same as above, but more precise + * + * The list of view objects which implement the `is()` method: + * + * * {@link module:engine/view/attributeelement~AttributeElement#is `AttributeElement#is()`} + * * {@link module:engine/view/containerelement~ContainerElement#is `ContainerElement#is()`} + * * {@link module:engine/view/documentfragment~DocumentFragment#is `DocumentFragment#is()`} + * * {@link module:engine/view/documentselection~DocumentSelection#is `DocumentSelection#is()`} + * * {@link module:engine/view/editableelement~EditableElement#is `EditableElement#is()`} + * * {@link module:engine/view/element~Element#is `Element#is()`} + * * {@link module:engine/view/emptyelement~EmptyElement#is `EmptyElement#is()`} + * * {@link module:engine/view/node~Node#is `Node#is()`} + * * {@link module:engine/view/position~Position#is `Position#is()`} + * * {@link module:engine/view/range~Range#is `Range#is()`} + * * {@link module:engine/view/rooteditableelement~RootEditableElement#is `RootEditableElement#is()`} + * * {@link module:engine/view/selection~Selection#is `Selection#is()`} + * * {@link module:engine/view/text~Text#is `Text#is()`} + * * {@link module:engine/view/textproxy~TextProxy#is `TextProxy#is()`} + * * {@link module:engine/view/uielement~UIElement#is `UIElement#is()`} + * + * @method #is + * @param {String} type * @returns {Boolean} */ is( type ) { - return type == 'node'; + return type == 'node' || type == 'view:node'; } /** diff --git a/src/view/position.js b/src/view/position.js index d44ddc8f7..f9f5ebba4 100644 --- a/src/view/position.js +++ b/src/view/position.js @@ -206,6 +206,25 @@ export default class Position { return i === 0 ? null : ancestorsA[ i - 1 ]; } + /** + * Checks whether this object is of the given type. + * + * position.is( 'position' ); // -> true + * position.is( 'view:position' ); // -> true + * + * position.is( 'model:position' ); // -> false + * position.is( 'element' ); // -> false + * position.is( 'range' ); // -> false + * + * {@link module:engine/view/node~Node#is Check the entire list of view objects} which implement the `is()` method. + * + * @param {String} type + * @returns {Boolean} + */ + is( type ) { + return type == 'position' || type == 'view:position'; + } + /** * Checks whether this position equals given position. * diff --git a/src/view/range.js b/src/view/range.js index e392ab307..f84919f6a 100644 --- a/src/view/range.js +++ b/src/view/range.js @@ -394,6 +394,25 @@ export default class Range { } } + /** + * Checks whether this object is of the given type. + * + * range.is( 'range' ); // -> true + * range.is( 'view:range' ); // -> true + * + * range.is( 'model:range' ); // -> false + * range.is( 'element' ); // -> false + * range.is( 'selection' ); // -> false + * + * {@link module:engine/view/node~Node#is Check the entire list of view objects} which implement the `is()` method. + * + * @param {String} type + * @returns {Boolean} + */ + is( type ) { + return type == 'range' || type == 'view:range'; + } + /** * Checks and returns whether this range intersects with the given range. * diff --git a/src/view/rooteditableelement.js b/src/view/rooteditableelement.js index 78d9e2f63..ad410e0cc 100644 --- a/src/view/rooteditableelement.js +++ b/src/view/rooteditableelement.js @@ -38,13 +38,40 @@ export default class RootEditableElement extends EditableElement { } /** - * @inheritDoc + * Checks whether this object is of the given. + * + * rootEditableElement.is( 'rootEditableElement' ); // -> true + * rootEditableElement.is( 'editableElement' ); // -> true + * rootEditableElement.is( 'element' ); // -> true + * rootEditableElement.is( 'node' ); // -> true + * rootEditableElement.is( 'view:rootEditableElement' ); // -> true + * rootEditableElement.is( 'view:editableElement' ); // -> true + * rootEditableElement.is( 'view:element' ); // -> true + * rootEditableElement.is( 'view:node' ); // -> true + * + * rootEditableElement.is( 'model:element' ); // -> false + * rootEditableElement.is( 'documentFragment' ); // -> false + * + * Assuming that the object being checked is a root editbale element, you can also check its + * {@link module:engine/view/rooteditableelement~RootEditableElement#name name}: + * + * rootEditableElement.is( 'div' ); // -> true if this is a div root editable element + * rootEditableElement.is( 'rootEditableElement', 'div' ); // -> same as above + * text.is( 'div' ); -> false + * + * {@link module:engine/view/node~Node#is Check the entire list of view objects} which implement the `is()` method. + * + * @param {String} type Type to check when `name` parameter is present. + * Otherwise, it acts like the `name` parameter. + * @param {String} [name] Element name. + * @returns {Boolean} */ is( type, name = null ) { + const cutType = type.replace( /^view:/, '' ); if ( !name ) { - return type == 'rootElement' || super.is( type ); + return cutType == 'rootElement' || super.is( type ); } else { - return ( type == 'rootElement' && name == this.name ) || super.is( type, name ); + return ( cutType == 'rootElement' && name == this.name ) || super.is( type, name ); } } diff --git a/src/view/selection.js b/src/view/selection.js index 0d23cd90d..4d79a3ed1 100644 --- a/src/view/selection.js +++ b/src/view/selection.js @@ -598,20 +598,22 @@ export default class Selection { } /** - * Checks whether object is of given type following the convention set by - * {@link module:engine/view/node~Node#is `Node#is()`}. + * Checks whether this object is of the given type. * - * const selection = new Selection( ... ); + * selection.is( 'selection' ); // -> true + * selection.is( 'view:selection' ); // -> true * - * selection.is( 'selection' ); // true - * selection.is( 'node' ); // false - * selection.is( 'element' ); // false + * selection.is( 'model:selection' ); // -> false + * selection.is( 'element' ); // -> false + * selection.is( 'range' ); // -> false + * + * {@link module:engine/view/node~Node#is Check the entire list of view objects} which implement the `is()` method. * * @param {String} type * @returns {Boolean} */ is( type ) { - return type == 'selection'; + return type == 'selection' || type == 'view:selection'; } /** diff --git a/src/view/text.js b/src/view/text.js index 1d044bf62..615641d45 100644 --- a/src/view/text.js +++ b/src/view/text.js @@ -42,10 +42,24 @@ export default class Text extends Node { } /** - * @inheritDoc + * Checks whether this object is of the given type. + * + * text.is( 'text' ); // -> true + * text.is( 'node' ); // -> true + * text.is( 'view:text' ); // -> true + * text.is( 'view:node' ); // -> true + * + * text.is( 'model:text' ); // -> false + * text.is( 'element' ); // -> false + * text.is( 'range' ); // -> false + * + * {@link module:engine/view/node~Node#is Check the entire list of view objects} which implement the `is()` method. + * + * @param {String} type + * @returns {Boolean} */ is( type ) { - return type == 'text' || super.is( type ); + return type == 'text' || type == 'view:text' || super.is( type ); } /** diff --git a/src/view/textproxy.js b/src/view/textproxy.js index 8c463bc5c..b8aef619d 100644 --- a/src/view/textproxy.js +++ b/src/view/textproxy.js @@ -141,15 +141,22 @@ export default class TextProxy { } /** - * Checks whether given view tree object is of given type. + * Checks whether this object is of the given type. * - * Read more in {@link module:engine/view/node~Node#is}. + * textProxy.is( 'textProxy' ); // -> true + * textProxy.is( 'view:textProxy' ); // -> true + * + * textProxy.is( 'model:textProxy' ); // -> false + * textProxy.is( 'element' ); // -> false + * textProxy.is( 'range' ); // -> false + * + * {@link module:engine/view/node~Node#is Check the entire list of view objects} which implement the `is()` method. * * @param {String} type * @returns {Boolean} */ is( type ) { - return type == 'textProxy'; + return type == 'textProxy' || type == 'view:textProxy'; } /** diff --git a/src/view/uielement.js b/src/view/uielement.js index 663d63c23..b85d441c5 100644 --- a/src/view/uielement.js +++ b/src/view/uielement.js @@ -57,13 +57,38 @@ export default class UIElement extends Element { } /** - * @inheritDoc + * Checks whether this object is of the given. + * + * uiElement.is( 'uiElement' ); // -> true + * uiElement.is( 'element' ); // -> true + * uiElement.is( 'node' ); // -> true + * uiElement.is( 'view:uiElement' ); // -> true + * uiElement.is( 'view:element' ); // -> true + * uiElement.is( 'view:node' ); // -> true + * + * uiElement.is( 'model:element' ); // -> false + * uiElement.is( 'documentFragment' ); // -> false + * + * Assuming that the object being checked is an ui element, you can also check its + * {@link module:engine/view/uielement~UIElement#name name}: + * + * uiElement.is( 'span' ); // -> true if this is a span ui element + * uiElement.is( 'uiElement', 'span' ); // -> same as above + * text.is( 'span' ); -> false + * + * {@link module:engine/view/node~Node#is Check the entire list of view objects} which implement the `is()` method. + * + * @param {String} type Type to check when `name` parameter is present. + * Otherwise, it acts like the `name` parameter. + * @param {String} [name] Element name. + * @returns {Boolean} */ is( type, name = null ) { + const cutType = type.replace( /^view:/, '' ); if ( !name ) { - return type == 'uiElement' || super.is( type ); + return cutType == 'uiElement' || super.is( type ); } else { - return ( type == 'uiElement' && name == this.name ) || super.is( type, name ); + return ( cutType == 'uiElement' && name == this.name ) || super.is( type, name ); } } diff --git a/tests/model/documentfragment.js b/tests/model/documentfragment.js index e9c07e797..a2eb870e8 100644 --- a/tests/model/documentfragment.js +++ b/tests/model/documentfragment.js @@ -61,7 +61,7 @@ describe( 'DocumentFragment', () => { } ); } ); - describe( 'is', () => { + describe( 'is()', () => { let frag; before( () => { @@ -70,14 +70,16 @@ describe( 'DocumentFragment', () => { it( 'should return true for documentFragment', () => { expect( frag.is( 'documentFragment' ) ).to.be.true; + expect( frag.is( 'model:documentFragment' ) ).to.be.true; } ); - it( 'should return false for other accept values', () => { + it( 'should return false for other values', () => { expect( frag.is( 'node' ) ).to.be.false; expect( frag.is( 'text' ) ).to.be.false; expect( frag.is( 'textProxy' ) ).to.be.false; expect( frag.is( 'element' ) ).to.be.false; expect( frag.is( 'rootElement' ) ).to.be.false; + expect( frag.is( 'view:documentFragment' ) ).to.be.false; } ); } ); diff --git a/tests/model/documentselection.js b/tests/model/documentselection.js index b73cb4912..fd7a70627 100644 --- a/tests/model/documentselection.js +++ b/tests/model/documentselection.js @@ -485,21 +485,27 @@ describe( 'DocumentSelection', () => { } ); } ); - describe( 'is', () => { + describe( 'is()', () => { it( 'should return true for selection', () => { expect( selection.is( 'selection' ) ).to.be.true; + expect( selection.is( 'model:selection' ) ).to.be.true; } ); it( 'should return true for documentSelection', () => { expect( selection.is( 'documentSelection' ) ).to.be.true; + expect( selection.is( 'model:documentSelection' ) ).to.be.true; } ); it( 'should return false for other values', () => { expect( selection.is( 'node' ) ).to.be.false; + expect( selection.is( 'model:node' ) ).to.be.false; expect( selection.is( 'text' ) ).to.be.false; expect( selection.is( 'textProxy' ) ).to.be.false; expect( selection.is( 'element' ) ).to.be.false; + expect( selection.is( 'element', 'paragraph' ) ).to.be.false; expect( selection.is( 'rootElement' ) ).to.be.false; + expect( selection.is( 'view:selection' ) ).to.be.false; + expect( selection.is( 'view:documentSelection' ) ).to.be.false; } ); } ); diff --git a/tests/model/element.js b/tests/model/element.js index cac079910..8e448303d 100644 --- a/tests/model/element.js +++ b/tests/model/element.js @@ -38,7 +38,7 @@ describe( 'Element', () => { } ); } ); - describe( 'is', () => { + describe( 'is()', () => { let element; before( () => { @@ -47,18 +47,29 @@ describe( 'Element', () => { it( 'should return true for node, element, element with same name and element name', () => { expect( element.is( 'node' ) ).to.be.true; + expect( element.is( 'model:node' ) ).to.be.true; expect( element.is( 'element' ) ).to.be.true; + expect( element.is( 'model:element' ) ).to.be.true; expect( element.is( 'element', 'paragraph' ) ).to.be.true; + expect( element.is( 'model:element', 'paragraph' ) ).to.be.true; expect( element.is( 'paragraph' ) ).to.be.true; + expect( element.is( 'model:paragraph' ) ).to.be.true; } ); it( 'should return false for other accept values', () => { expect( element.is( 'element', 'image' ) ).to.be.false; + expect( element.is( 'model:element', 'image' ) ).to.be.false; expect( element.is( 'image' ) ).to.be.false; + expect( element.is( 'model:image' ) ).to.be.false; expect( element.is( 'text' ) ).to.be.false; + expect( element.is( 'model:text' ) ).to.be.false; expect( element.is( 'textProxy' ) ).to.be.false; expect( element.is( 'documentFragment' ) ).to.be.false; expect( element.is( 'rootElement' ) ).to.be.false; + expect( element.is( 'model:rootElement' ) ).to.be.false; + expect( element.is( 'view:node' ) ).to.be.false; + expect( element.is( 'view:element' ) ).to.be.false; + expect( element.is( 'view:element' ) ).to.be.false; } ); } ); diff --git a/tests/model/liveposition.js b/tests/model/liveposition.js index e2115d904..bb10dae63 100644 --- a/tests/model/liveposition.js +++ b/tests/model/liveposition.js @@ -41,6 +41,29 @@ describe( 'LivePosition', () => expect( live ).to.be.instanceof( Position ); } ); + describe( 'is()', () => { + let live; + + beforeEach( () => { + live = new LivePosition( root, [ 0 ] ); + live.detach(); + } ); + + it( 'should return true for "livePosition" and "position"', () => { + expect( live.is( 'livePosition' ) ).to.be.true; + expect( live.is( 'model:livePosition' ) ).to.be.true; + expect( live.is( 'position' ) ).to.be.true; + expect( live.is( 'model:position' ) ).to.be.true; + } ); + + it( 'should return false for incorrect values', () => { + expect( live.is( 'model' ) ).to.be.false; + expect( live.is( 'model:node' ) ).to.be.false; + expect( live.is( 'text' ) ).to.be.false; + expect( live.is( 'element', 'paragraph' ) ).to.be.false; + } ); + } ); + it( 'should throw if given root is not a RootElement', () => { const docFrag = new DocumentFragment(); diff --git a/tests/model/liverange.js b/tests/model/liverange.js index 67e8a53cf..e5ade9da0 100644 --- a/tests/model/liverange.js +++ b/tests/model/liverange.js @@ -183,6 +183,29 @@ describe( 'LiveRange', () => { expect( spy.args[ 1 ][ 2 ].deletionPosition.isEqual( new Position( root, [ 0 ] ) ) ).to.be.true; } ); + describe( 'is()', () => { + let live; + + beforeEach( () => { + live = new LiveRange( new Position( root, [ 0 ] ), new Position( root, [ 1 ] ) ); + live.detach(); + } ); + + it( 'should return true for "liveRange" and "range"', () => { + expect( live.is( 'liveRange' ) ).to.be.true; + expect( live.is( 'model:liveRange' ) ).to.be.true; + expect( live.is( 'range' ) ).to.be.true; + expect( live.is( 'model:range' ) ).to.be.true; + } ); + + it( 'should return false for incorrect values', () => { + expect( live.is( 'model' ) ).to.be.false; + expect( live.is( 'model:node' ) ).to.be.false; + expect( live.is( 'text' ) ).to.be.false; + expect( live.is( 'element', 'paragraph' ) ).to.be.false; + } ); + } ); + describe( 'should get transformed and fire change:range if', () => { let live, spy; diff --git a/tests/model/markercollection.js b/tests/model/markercollection.js index a5e730677..bec4dd670 100644 --- a/tests/model/markercollection.js +++ b/tests/model/markercollection.js @@ -410,4 +410,25 @@ describe( 'Marker', () => { expect( marker.affectsData ).to.be.false; } ); + + describe( 'is()', () => { + let marker; + + beforeEach( () => { + const range = new Range( Position._createAt( root, 1 ), Position._createAt( root, 2 ) ); + marker = model.markers._set( 'name', range ); + } ); + + it( 'should return true for "marker"', () => { + expect( marker.is( 'marker' ) ).to.be.true; + expect( marker.is( 'model:marker' ) ).to.be.true; + } ); + + it( 'should return false for incorrect values', () => { + expect( marker.is( 'model' ) ).to.be.false; + expect( marker.is( 'model:node' ) ).to.be.false; + expect( marker.is( 'text' ) ).to.be.false; + expect( marker.is( 'element', 'paragraph' ) ).to.be.false; + } ); + } ); } ); diff --git a/tests/model/node.js b/tests/model/node.js index 54bd6f545..a0d9baf82 100644 --- a/tests/model/node.js +++ b/tests/model/node.js @@ -165,6 +165,14 @@ describe( 'Node', () => { describe( 'is()', () => { it( 'should return true for node', () => { expect( node.is( 'node' ) ).to.be.true; + expect( node.is( 'model:node' ) ).to.be.true; + } ); + + it( 'should return false for incorrect values', () => { + expect( node.is( 'model' ) ).to.be.false; + expect( node.is( 'model:text' ) ).to.be.false; + expect( node.is( 'text' ) ).to.be.false; + expect( node.is( 'element', 'paragraph' ) ).to.be.false; } ); } ); diff --git a/tests/model/position.js b/tests/model/position.js index 415f23818..74b455bca 100644 --- a/tests/model/position.js +++ b/tests/model/position.js @@ -128,6 +128,26 @@ describe( 'Position', () => { } ); } ); + describe( 'is()', () => { + let position; + + beforeEach( () => { + position = new Position( root, [ 0 ] ); + } ); + + it( 'should return true for "position"', () => { + expect( position.is( 'position' ) ).to.be.true; + expect( position.is( 'model:position' ) ).to.be.true; + } ); + + it( 'should return false for incorrect values', () => { + expect( position.is( 'model' ) ).to.be.false; + expect( position.is( 'model:node' ) ).to.be.false; + expect( position.is( 'text' ) ).to.be.false; + expect( position.is( 'element', 'paragraph' ) ).to.be.false; + } ); + } ); + describe( 'static creators', () => { describe( '_createAt()', () => { it( 'should throw if no offset is passed', () => { diff --git a/tests/model/range.js b/tests/model/range.js index 7409c0617..a15deeafd 100644 --- a/tests/model/range.js +++ b/tests/model/range.js @@ -50,6 +50,20 @@ describe( 'Range', () => { } ); } ); + describe( 'is()', () => { + it( 'should return true for "range"', () => { + expect( range.is( 'range' ) ).to.be.true; + expect( range.is( 'model:range' ) ).to.be.true; + } ); + + it( 'should return false for incorrect values', () => { + expect( range.is( 'model' ) ).to.be.false; + expect( range.is( 'model:node' ) ).to.be.false; + expect( range.is( 'text' ) ).to.be.false; + expect( range.is( 'element', 'paragraph' ) ).to.be.false; + } ); + } ); + describe( 'root', () => { it( 'should be equal to start position root', () => { expect( range.root ).to.equal( start.root ); diff --git a/tests/model/rootelement.js b/tests/model/rootelement.js index 2bed59cac..6d90626aa 100644 --- a/tests/model/rootelement.js +++ b/tests/model/rootelement.js @@ -22,7 +22,7 @@ describe( 'RootElement', () => { } ); } ); - describe( 'is', () => { + describe( 'is()', () => { let root; before( () => { @@ -34,19 +34,29 @@ describe( 'RootElement', () => { it( 'should return true for rootElement, element, element with same name and element name', () => { expect( root.is( 'element', '$root' ) ).to.be.true; + expect( root.is( 'model:element', '$root' ) ).to.be.true; expect( root.is( 'element' ) ).to.be.true; + expect( root.is( 'model:element' ) ).to.be.true; expect( root.is( '$root' ) ).to.be.true; + expect( root.is( 'model:$root' ) ).to.be.true; expect( root.is( 'rootElement', '$root' ) ).to.be.true; + expect( root.is( 'model:rootElement', '$root' ) ).to.be.true; expect( root.is( 'rootElement' ) ).to.be.true; + expect( root.is( 'model:rootElement' ) ).to.be.true; + expect( root.is( 'node' ) ).to.be.true; + expect( root.is( 'model:node' ) ).to.be.true; } ); it( 'should return false for other accept values', () => { expect( root.is( 'element', '$graveyard' ) ).to.be.false; + expect( root.is( 'model:element', '$graveyard' ) ).to.be.false; expect( root.is( 'rootElement', '$graveyard' ) ).to.be.false; + expect( root.is( 'model:rootElement', '$graveyard' ) ).to.be.false; expect( root.is( '$graveyard' ) ).to.be.false; expect( root.is( 'text' ) ).to.be.false; expect( root.is( 'textProxy' ) ).to.be.false; expect( root.is( 'documentFragment' ) ).to.be.false; + expect( root.is( 'view:element' ) ).to.be.false; } ); } ); } ); diff --git a/tests/model/selection.js b/tests/model/selection.js index 4586001fc..5897da938 100644 --- a/tests/model/selection.js +++ b/tests/model/selection.js @@ -127,6 +127,26 @@ describe( 'Selection', () => { } ); } ); + describe( 'is()', () => { + let selection; + + beforeEach( () => { + selection = new Selection(); + } ); + + it( 'should return true for "selection"', () => { + expect( selection.is( 'selection' ) ).to.be.true; + expect( selection.is( 'model:selection' ) ).to.be.true; + } ); + + it( 'should return false for incorrect values', () => { + expect( selection.is( 'model' ) ).to.be.false; + expect( selection.is( 'model:node' ) ).to.be.false; + expect( selection.is( 'text' ) ).to.be.false; + expect( selection.is( 'element', 'paragraph' ) ).to.be.false; + } ); + } ); + describe( 'isCollapsed', () => { it( 'should return false for empty selection', () => { expect( selection.isCollapsed ).to.be.false; @@ -806,7 +826,7 @@ describe( 'Selection', () => { } ); } ); - describe( 'is', () => { + describe( 'is()', () => { it( 'should return true for selection', () => { expect( selection.is( 'selection' ) ).to.be.true; } ); diff --git a/tests/model/text.js b/tests/model/text.js index 16973c119..86c93b748 100644 --- a/tests/model/text.js +++ b/tests/model/text.js @@ -32,7 +32,7 @@ describe( 'Text', () => { } ); } ); - describe( 'is', () => { + describe( 'is()', () => { let text; before( () => { @@ -41,12 +41,15 @@ describe( 'Text', () => { it( 'should return true for node, text', () => { expect( text.is( 'node' ) ).to.be.true; + expect( text.is( 'model:node' ) ).to.be.true; expect( text.is( 'text' ) ).to.be.true; + expect( text.is( 'model:text' ) ).to.be.true; } ); it( 'should return false for other accept values', () => { expect( text.is( 'textProxy' ) ).to.be.false; expect( text.is( 'element' ) ).to.be.false; + expect( text.is( 'model:element' ) ).to.be.false; expect( text.is( 'rootElement' ) ).to.be.false; expect( text.is( 'documentFragment' ) ).to.be.false; } ); diff --git a/tests/model/textproxy.js b/tests/model/textproxy.js index 3602f7b72..a6cff835f 100644 --- a/tests/model/textproxy.js +++ b/tests/model/textproxy.js @@ -102,15 +102,18 @@ describe( 'TextProxy', () => { }, /model-textproxy-wrong-length/, model ); } ); - describe( 'is', () => { + describe( 'is()', () => { it( 'should return true for textProxy', () => { expect( textProxy.is( 'textProxy' ) ).to.be.true; + expect( textProxy.is( 'model:textProxy' ) ).to.be.true; } ); it( 'should return false for other accept values', () => { expect( textProxy.is( 'node' ) ).to.be.false; + expect( textProxy.is( 'model:node' ) ).to.be.false; expect( textProxy.is( 'text' ) ).to.be.false; expect( textProxy.is( 'element' ) ).to.be.false; + expect( textProxy.is( 'model:element', 'image' ) ).to.be.false; expect( textProxy.is( 'documentFragment' ) ).to.be.false; expect( textProxy.is( 'rootElement' ) ).to.be.false; } ); diff --git a/tests/view/attributeelement.js b/tests/view/attributeelement.js index 3ae6870de..224325ff6 100644 --- a/tests/view/attributeelement.js +++ b/tests/view/attributeelement.js @@ -21,7 +21,7 @@ describe( 'AttributeElement', () => { } ); } ); - describe( 'is', () => { + describe( 'is()', () => { let el; before( () => { @@ -30,16 +30,24 @@ describe( 'AttributeElement', () => { it( 'should return true for attributeElement/element, also with correct name and element name', () => { expect( el.is( 'attributeElement' ) ).to.be.true; + expect( el.is( 'view:attributeElement' ) ).to.be.true; expect( el.is( 'attributeElement', 'span' ) ).to.be.true; + expect( el.is( 'view:attributeElement', 'span' ) ).to.be.true; expect( el.is( 'element' ) ).to.be.true; + expect( el.is( 'view:element' ) ).to.be.true; expect( el.is( 'element', 'span' ) ).to.be.true; + expect( el.is( 'view:element', 'span' ) ).to.be.true; expect( el.is( 'span' ) ).to.be.true; + expect( el.is( 'view:span' ) ).to.be.true; } ); it( 'should return false for other accept values', () => { expect( el.is( 'attributeElement', 'p' ) ).to.be.false; + expect( el.is( 'view:attributeElement', 'p' ) ).to.be.false; expect( el.is( 'element', 'p' ) ).to.be.false; + expect( el.is( 'view:element', 'p' ) ).to.be.false; expect( el.is( 'p' ) ).to.be.false; + expect( el.is( 'view:p' ) ).to.be.false; expect( el.is( 'text' ) ).to.be.false; expect( el.is( 'textProxy' ) ).to.be.false; expect( el.is( 'containerElement' ) ).to.be.false; diff --git a/tests/view/containerelement.js b/tests/view/containerelement.js index b7fa31152..7a8cd2302 100644 --- a/tests/view/containerelement.js +++ b/tests/view/containerelement.js @@ -18,7 +18,7 @@ describe( 'ContainerElement', () => { } ); } ); - describe( 'is', () => { + describe( 'is()', () => { let el; before( () => { @@ -27,16 +27,24 @@ describe( 'ContainerElement', () => { it( 'should return true for containerElement/element, also with correct name and element name', () => { expect( el.is( 'containerElement' ) ).to.be.true; + expect( el.is( 'view:containerElement' ) ).to.be.true; expect( el.is( 'containerElement', 'p' ) ).to.be.true; + expect( el.is( 'view:containerElement', 'p' ) ).to.be.true; expect( el.is( 'element' ) ).to.be.true; + expect( el.is( 'view:element' ) ).to.be.true; expect( el.is( 'element', 'p' ) ).to.be.true; + expect( el.is( 'view:element', 'p' ) ).to.be.true; expect( el.is( 'p' ) ).to.be.true; + expect( el.is( 'view:p' ) ).to.be.true; } ); it( 'should return false for other accept values', () => { expect( el.is( 'containerElement', 'span' ) ).to.be.false; + expect( el.is( 'view:containerElement', 'span' ) ).to.be.false; expect( el.is( 'element', 'span' ) ).to.be.false; + expect( el.is( 'view:element', 'span' ) ).to.be.false; expect( el.is( 'span' ) ).to.be.false; + expect( el.is( 'view:span' ) ).to.be.false; expect( el.is( 'text' ) ).to.be.false; expect( el.is( 'textProxy' ) ).to.be.false; expect( el.is( 'attributeElement' ) ).to.be.false; diff --git a/tests/view/documentfragment.js b/tests/view/documentfragment.js index 9d88f5a0d..0dc35368f 100644 --- a/tests/view/documentfragment.js +++ b/tests/view/documentfragment.js @@ -71,7 +71,7 @@ describe( 'DocumentFragment', () => { } ); } ); - describe( 'is', () => { + describe( 'is()', () => { let frag; before( () => { @@ -80,13 +80,16 @@ describe( 'DocumentFragment', () => { it( 'should return true for documentFragment', () => { expect( frag.is( 'documentFragment' ) ).to.be.true; + expect( frag.is( 'view:documentFragment' ) ).to.be.true; } ); it( 'should return false for other accept values', () => { expect( frag.is( 'node' ) ).to.be.false; + expect( frag.is( 'view:node' ) ).to.be.false; expect( frag.is( 'text' ) ).to.be.false; expect( frag.is( 'textProxy' ) ).to.be.false; expect( frag.is( 'element' ) ).to.be.false; + expect( frag.is( 'view:element' ) ).to.be.false; expect( frag.is( 'containerElement' ) ).to.be.false; expect( frag.is( 'attributeElement' ) ).to.be.false; expect( frag.is( 'uiElement' ) ).to.be.false; diff --git a/tests/view/documentselection.js b/tests/view/documentselection.js index fdc1fb0f5..e9e2d5a04 100644 --- a/tests/view/documentselection.js +++ b/tests/view/documentselection.js @@ -725,21 +725,27 @@ describe( 'DocumentSelection', () => { } ); } ); - describe( 'is', () => { + describe( 'is()', () => { it( 'should return true for selection', () => { expect( documentSelection.is( 'selection' ) ).to.be.true; + expect( documentSelection.is( 'view:selection' ) ).to.be.true; } ); it( 'should return true for documentSelection', () => { expect( documentSelection.is( 'documentSelection' ) ).to.be.true; + expect( documentSelection.is( 'view:documentSelection' ) ).to.be.true; } ); it( 'should return false for other values', () => { expect( documentSelection.is( 'node' ) ).to.be.false; + expect( documentSelection.is( 'view:node' ) ).to.be.false; expect( documentSelection.is( 'text' ) ).to.be.false; + expect( documentSelection.is( 'view:text' ) ).to.be.false; expect( documentSelection.is( 'textProxy' ) ).to.be.false; expect( documentSelection.is( 'element' ) ).to.be.false; expect( documentSelection.is( 'rootElement' ) ).to.be.false; + expect( documentSelection.is( 'model:selection' ) ).to.be.false; + expect( documentSelection.is( 'model:documentSelection' ) ).to.be.false; } ); } ); diff --git a/tests/view/editableelement.js b/tests/view/editableelement.js index 3e519204b..17d191091 100644 --- a/tests/view/editableelement.js +++ b/tests/view/editableelement.js @@ -5,16 +5,58 @@ import createDocumentMock from '../../tests/view/_utils/createdocumentmock'; -import RootEditableElement from '../../src/view/rooteditableelement'; +import EditableElement from '../../src/view/editableelement'; import Range from '../../src/view/range'; import { expectToThrowCKEditorError } from '@ckeditor/ckeditor5-utils/tests/_utils/utils'; describe( 'EditableElement', () => { + describe( 'is', () => { + let el; + + before( () => { + el = new EditableElement( 'div' ); + } ); + + it( 'should return true for containerElement/editable/element, also with correct name and element name', () => { + expect( el.is( 'containerElement' ) ).to.be.true; + expect( el.is( 'view:containerElement' ) ).to.be.true; + expect( el.is( 'containerElement', 'div' ) ).to.be.true; + expect( el.is( 'view:containerElement', 'div' ) ).to.be.true; + expect( el.is( 'editableElement' ) ).to.be.true; + expect( el.is( 'view:editableElement' ) ).to.be.true; + expect( el.is( 'editableElement', 'div' ) ).to.be.true; + expect( el.is( 'view:editableElement', 'div' ) ).to.be.true; + expect( el.is( 'element' ) ).to.be.true; + expect( el.is( 'view:element' ) ).to.be.true; + expect( el.is( 'element', 'div' ) ).to.be.true; + expect( el.is( 'view:element', 'div' ) ).to.be.true; + expect( el.is( 'div' ) ).to.be.true; + expect( el.is( 'view:div' ) ).to.be.true; + } ); + + it( 'should return false for other accept values', () => { + expect( el.is( 'rootElement', 'p' ) ).to.be.false; + expect( el.is( 'view:rootElement', 'p' ) ).to.be.false; + expect( el.is( 'containerElement', 'p' ) ).to.be.false; + expect( el.is( 'view:containerElement', 'p' ) ).to.be.false; + expect( el.is( 'element', 'p' ) ).to.be.false; + expect( el.is( 'view:element', 'p' ) ).to.be.false; + expect( el.is( 'p' ) ).to.be.false; + expect( el.is( 'view:p' ) ).to.be.false; + expect( el.is( 'text' ) ).to.be.false; + expect( el.is( 'textProxy' ) ).to.be.false; + expect( el.is( 'attributeElement' ) ).to.be.false; + expect( el.is( 'uiElement' ) ).to.be.false; + expect( el.is( 'emptyElement' ) ).to.be.false; + expect( el.is( 'documentFragment' ) ).to.be.false; + } ); + } ); + describe( 'document', () => { let element, docMock; beforeEach( () => { - element = new RootEditableElement( 'div' ); + element = new EditableElement( 'div' ); docMock = createDocumentMock(); } ); @@ -51,16 +93,16 @@ describe( 'EditableElement', () => { beforeEach( () => { docMock = createDocumentMock(); - viewMain = new RootEditableElement( 'div' ); + viewMain = new EditableElement( 'div' ); viewMain._document = docMock; - viewHeader = new RootEditableElement( 'h1' ); + viewHeader = new EditableElement( 'h1' ); viewHeader._document = docMock; viewHeader.rootName = 'header'; } ); it( 'should be observable', () => { - const root = new RootEditableElement( 'div' ); + const root = new EditableElement( 'div' ); root._document = createDocumentMock(); expect( root.isFocused ).to.be.false; @@ -114,7 +156,7 @@ describe( 'EditableElement', () => { describe( 'isReadOnly', () => { it( 'should be observable', () => { - const root = new RootEditableElement( 'div' ); + const root = new EditableElement( 'div' ); root._document = createDocumentMock(); expect( root.isReadOnly ).to.be.false; @@ -131,7 +173,7 @@ describe( 'EditableElement', () => { } ); it( 'should be bound to the document#isReadOnly', () => { - const root = new RootEditableElement( 'div' ); + const root = new EditableElement( 'div' ); root._document = createDocumentMock(); root.document.isReadOnly = false; @@ -147,7 +189,7 @@ describe( 'EditableElement', () => { describe( 'getDocument', () => { it( 'should return document', () => { const docMock = createDocumentMock(); - const root = new RootEditableElement( 'div' ); + const root = new EditableElement( 'div' ); root._document = docMock; expect( root.document ).to.equal( docMock ); diff --git a/tests/view/element.js b/tests/view/element.js index f05ed1832..1f161e163 100644 --- a/tests/view/element.js +++ b/tests/view/element.js @@ -82,7 +82,7 @@ describe( 'Element', () => { } ); } ); - describe( 'is', () => { + describe( 'is()', () => { let el; before( () => { @@ -91,21 +91,30 @@ describe( 'Element', () => { it( 'should return true for node, element, element with correct name and element name', () => { expect( el.is( 'node' ) ).to.be.true; + expect( el.is( 'view:node' ) ).to.be.true; expect( el.is( 'element' ) ).to.be.true; + expect( el.is( 'view:element' ) ).to.be.true; expect( el.is( 'element', 'p' ) ).to.be.true; + expect( el.is( 'view:element', 'p' ) ).to.be.true; expect( el.is( 'p' ) ).to.be.true; + expect( el.is( 'view:p' ) ).to.be.true; } ); it( 'should return false for other accept values', () => { expect( el.is( 'element', 'span' ) ).to.be.false; + expect( el.is( 'view:element', 'span' ) ).to.be.false; expect( el.is( 'span' ) ).to.be.false; + expect( el.is( 'view:span' ) ).to.be.false; expect( el.is( 'text' ) ).to.be.false; + expect( el.is( 'view:text' ) ).to.be.false; expect( el.is( 'textProxy' ) ).to.be.false; expect( el.is( 'containerElement' ) ).to.be.false; expect( el.is( 'attributeElement' ) ).to.be.false; expect( el.is( 'uiElement' ) ).to.be.false; expect( el.is( 'emptyElement' ) ).to.be.false; + expect( el.is( 'view:emptyElement' ) ).to.be.false; expect( el.is( 'rootElement' ) ).to.be.false; + expect( el.is( 'view:ootElement' ) ).to.be.false; expect( el.is( 'documentFragment' ) ).to.be.false; } ); } ); diff --git a/tests/view/emptyelement.js b/tests/view/emptyelement.js index b216edd8e..695ddd881 100644 --- a/tests/view/emptyelement.js +++ b/tests/view/emptyelement.js @@ -20,7 +20,7 @@ describe( 'EmptyElement', () => { } ); } ); - describe( 'is', () => { + describe( 'is()', () => { let el; before( () => { @@ -29,17 +29,26 @@ describe( 'EmptyElement', () => { it( 'should return true for emptyElement/element, also with correct name and element name', () => { expect( el.is( 'emptyElement' ) ).to.be.true; + expect( el.is( 'view:emptyElement' ) ).to.be.true; expect( el.is( 'emptyElement', 'p' ) ).to.be.true; + expect( el.is( 'view:emptyElement', 'p' ) ).to.be.true; expect( el.is( 'element' ) ).to.be.true; + expect( el.is( 'view:element' ) ).to.be.true; expect( el.is( 'element', 'p' ) ).to.be.true; + expect( el.is( 'view:element', 'p' ) ).to.be.true; expect( el.is( 'p' ) ).to.be.true; + expect( el.is( 'view:p' ) ).to.be.true; } ); it( 'should return false for other accept values', () => { expect( el.is( 'emptyElement', 'span' ) ).to.be.false; + expect( el.is( 'view:emptyElement', 'span' ) ).to.be.false; expect( el.is( 'element', 'span' ) ).to.be.false; + expect( el.is( 'view:element', 'span' ) ).to.be.false; expect( el.is( 'span' ) ).to.be.false; + expect( el.is( 'view:span' ) ).to.be.false; expect( el.is( 'text' ) ).to.be.false; + expect( el.is( 'view:text' ) ).to.be.false; expect( el.is( 'textProxy' ) ).to.be.false; expect( el.is( 'containerElement' ) ).to.be.false; expect( el.is( 'attributeElement' ) ).to.be.false; diff --git a/tests/view/node.js b/tests/view/node.js index f40d6588a..d56a841a4 100644 --- a/tests/view/node.js +++ b/tests/view/node.js @@ -31,10 +31,28 @@ describe( 'Node', () => { } ); describe( 'is()', () => { - it( 'should return true for node', () => { - const node = new Node(); + let node; + beforeEach( () => { + node = new Node(); + } ); + + it( 'should return true for node', () => { expect( node.is( 'node' ) ).to.be.true; + expect( node.is( 'view:node' ) ).to.be.true; + } ); + + it( 'should return false for other accept values', () => { + expect( node.is( 'rootElement' ) ).to.be.false; + expect( node.is( 'containerElement' ) ).to.be.false; + expect( node.is( 'element' ) ).to.be.false; + expect( node.is( 'p' ) ).to.be.false; + expect( node.is( 'text' ) ).to.be.false; + expect( node.is( 'textProxy' ) ).to.be.false; + expect( node.is( 'attributeElement' ) ).to.be.false; + expect( node.is( 'uiElement' ) ).to.be.false; + expect( node.is( 'emptyElement' ) ).to.be.false; + expect( node.is( 'documentFragment' ) ).to.be.false; } ); } ); diff --git a/tests/view/position.js b/tests/view/position.js index 13405951c..7e5ea011e 100644 --- a/tests/view/position.js +++ b/tests/view/position.js @@ -24,10 +24,37 @@ describe( 'Position', () => { describe( 'constructor()', () => { it( 'should create element without attributes', () => { - const elem = new Position( parentMock, 5 ); + const position = new Position( parentMock, 5 ); - expect( elem ).to.have.property( 'parent' ).that.equals( parentMock ); - expect( elem ).to.have.property( 'offset' ).that.equals( 5 ); + expect( position ).to.have.property( 'parent' ).that.equals( parentMock ); + expect( position ).to.have.property( 'offset' ).that.equals( 5 ); + } ); + } ); + + describe( 'is()', () => { + let position; + + beforeEach( () => { + position = new Position( parentMock, 5 ); + } ); + + it( 'should return true for "position"', () => { + expect( position.is( 'position' ) ).to.be.true; + expect( position.is( 'view:position' ) ).to.be.true; + } ); + + it( 'should return false for other accept values', () => { + expect( position.is( 'rootElement' ) ).to.be.false; + expect( position.is( 'containerElement' ) ).to.be.false; + expect( position.is( 'element' ) ).to.be.false; + expect( position.is( 'p' ) ).to.be.false; + expect( position.is( 'text' ) ).to.be.false; + expect( position.is( 'textProxy' ) ).to.be.false; + expect( position.is( 'attributeElement' ) ).to.be.false; + expect( position.is( 'uiElement' ) ).to.be.false; + expect( position.is( 'emptyElement' ) ).to.be.false; + expect( position.is( 'documentFragment' ) ).to.be.false; + expect( position.is( 'model:position' ) ).to.be.false; } ); } ); diff --git a/tests/view/range.js b/tests/view/range.js index c1320282e..8588e4228 100644 --- a/tests/view/range.js +++ b/tests/view/range.js @@ -43,6 +43,34 @@ describe( 'Range', () => { } ); } ); + describe( 'is()', () => { + let range; + + before( () => { + const start = new Position( {}, 1 ); + range = new Range( start ); + } ); + + it( 'should return true for "range"', () => { + expect( range.is( 'range' ) ).to.be.true; + expect( range.is( 'view:range' ) ).to.be.true; + } ); + + it( 'should return false for other accept values', () => { + expect( range.is( 'rootElement' ) ).to.be.false; + expect( range.is( 'containerElement' ) ).to.be.false; + expect( range.is( 'element' ) ).to.be.false; + expect( range.is( 'p' ) ).to.be.false; + expect( range.is( 'text' ) ).to.be.false; + expect( range.is( 'textProxy' ) ).to.be.false; + expect( range.is( 'attributeElement' ) ).to.be.false; + expect( range.is( 'uiElement' ) ).to.be.false; + expect( range.is( 'emptyElement' ) ).to.be.false; + expect( range.is( 'documentFragment' ) ).to.be.false; + expect( range.is( 'model:range' ) ).to.be.false; + } ); + } ); + describe( 'iterator', () => { it( 'should iterate over the range returning tree walker values', () => { const range = getRange( '

fo{o

bar

xy}z

' ); diff --git a/tests/view/rooteditableelement.js b/tests/view/rooteditableelement.js index a3cfa2e57..17b8b31e5 100644 --- a/tests/view/rooteditableelement.js +++ b/tests/view/rooteditableelement.js @@ -38,7 +38,7 @@ describe( 'RootEditableElement', () => { } ); } ); - describe( 'is', () => { + describe( 'is()', () => { let el; before( () => { @@ -47,27 +47,42 @@ describe( 'RootEditableElement', () => { it( 'should return true for rootElement/containerElement/editable/element, also with correct name and element name', () => { expect( el.is( 'rootElement' ) ).to.be.true; + expect( el.is( 'view:rootElement' ) ).to.be.true; expect( el.is( 'rootElement', 'div' ) ).to.be.true; + expect( el.is( 'view:rootElement', 'div' ) ).to.be.true; expect( el.is( 'containerElement' ) ).to.be.true; + expect( el.is( 'view:containerElement' ) ).to.be.true; expect( el.is( 'containerElement', 'div' ) ).to.be.true; + expect( el.is( 'view:containerElement', 'div' ) ).to.be.true; expect( el.is( 'editableElement' ) ).to.be.true; + expect( el.is( 'view:editableElement' ) ).to.be.true; expect( el.is( 'editableElement', 'div' ) ).to.be.true; + expect( el.is( 'view:editableElement', 'div' ) ).to.be.true; expect( el.is( 'element' ) ).to.be.true; + expect( el.is( 'view:element' ) ).to.be.true; expect( el.is( 'element', 'div' ) ).to.be.true; + expect( el.is( 'view:element', 'div' ) ).to.be.true; expect( el.is( 'div' ) ).to.be.true; + expect( el.is( 'view:div' ) ).to.be.true; } ); it( 'should return false for other accept values', () => { expect( el.is( 'rootElement', 'p' ) ).to.be.false; + expect( el.is( 'view:rootElement', 'p' ) ).to.be.false; expect( el.is( 'containerElement', 'p' ) ).to.be.false; + expect( el.is( 'view:containerElement', 'p' ) ).to.be.false; expect( el.is( 'element', 'p' ) ).to.be.false; + expect( el.is( 'view:element', 'p' ) ).to.be.false; expect( el.is( 'p' ) ).to.be.false; + expect( el.is( 'view:p' ) ).to.be.false; expect( el.is( 'text' ) ).to.be.false; + expect( el.is( 'view:text' ) ).to.be.false; expect( el.is( 'textProxy' ) ).to.be.false; expect( el.is( 'attributeElement' ) ).to.be.false; expect( el.is( 'uiElement' ) ).to.be.false; expect( el.is( 'emptyElement' ) ).to.be.false; expect( el.is( 'documentFragment' ) ).to.be.false; + expect( el.is( 'model:rootElement' ) ).to.be.false; } ); } ); diff --git a/tests/view/selection.js b/tests/view/selection.js index 260efe0a5..891f9dee6 100644 --- a/tests/view/selection.js +++ b/tests/view/selection.js @@ -600,18 +600,21 @@ describe( 'Selection', () => { } ); } ); - describe( 'is', () => { + describe( 'is()', () => { it( 'should return true for selection', () => { expect( selection.is( 'selection' ) ).to.be.true; + expect( selection.is( 'view:selection' ) ).to.be.true; } ); it( 'should return false for other values', () => { expect( selection.is( 'documentSelection' ) ).to.be.false; + expect( selection.is( 'view:documentSelection' ) ).to.be.false; expect( selection.is( 'node' ) ).to.be.false; expect( selection.is( 'text' ) ).to.be.false; expect( selection.is( 'textProxy' ) ).to.be.false; expect( selection.is( 'element' ) ).to.be.false; expect( selection.is( 'rootElement' ) ).to.be.false; + expect( selection.is( 'model:selection' ) ).to.be.false; } ); } ); diff --git a/tests/view/text.js b/tests/view/text.js index c0069830f..b3eb9e315 100644 --- a/tests/view/text.js +++ b/tests/view/text.js @@ -17,7 +17,7 @@ describe( 'Text', () => { } ); } ); - describe( 'is', () => { + describe( 'is()', () => { let text; before( () => { @@ -26,18 +26,24 @@ describe( 'Text', () => { it( 'should return true for node, text', () => { expect( text.is( 'node' ) ).to.be.true; + expect( text.is( 'view:node' ) ).to.be.true; expect( text.is( 'text' ) ).to.be.true; + expect( text.is( 'view:text' ) ).to.be.true; } ); it( 'should return false for other accept values', () => { expect( text.is( 'textProxy' ) ).to.be.false; + expect( text.is( 'view:textProxy' ) ).to.be.false; expect( text.is( 'element' ) ).to.be.false; + expect( text.is( 'view:element' ) ).to.be.false; expect( text.is( 'containerElement' ) ).to.be.false; expect( text.is( 'attributeElement' ) ).to.be.false; expect( text.is( 'uiElement' ) ).to.be.false; expect( text.is( 'emptyElement' ) ).to.be.false; expect( text.is( 'rootElement' ) ).to.be.false; expect( text.is( 'documentFragment' ) ).to.be.false; + expect( text.is( 'model:text' ) ).to.be.false; + expect( text.is( 'model:node' ) ).to.be.false; } ); } ); diff --git a/tests/view/textproxy.js b/tests/view/textproxy.js index 0c43f0816..08a4b318f 100644 --- a/tests/view/textproxy.js +++ b/tests/view/textproxy.js @@ -61,14 +61,17 @@ describe( 'TextProxy', () => { } ); } ); - describe( 'is', () => { + describe( 'is()', () => { it( 'should return true for textProxy', () => { expect( textProxy.is( 'textProxy' ) ).to.be.true; + expect( textProxy.is( 'view:textProxy' ) ).to.be.true; } ); it( 'should return false for other accept values', () => { expect( textProxy.is( 'node' ) ).to.be.false; + expect( textProxy.is( 'view:node' ) ).to.be.false; expect( textProxy.is( 'text' ) ).to.be.false; + expect( textProxy.is( 'view:text' ) ).to.be.false; expect( textProxy.is( 'element' ) ).to.be.false; expect( textProxy.is( 'containerElement' ) ).to.be.false; expect( textProxy.is( 'attributeElement' ) ).to.be.false; @@ -76,6 +79,7 @@ describe( 'TextProxy', () => { expect( textProxy.is( 'emptyElement' ) ).to.be.false; expect( textProxy.is( 'rootElement' ) ).to.be.false; expect( textProxy.is( 'documentFragment' ) ).to.be.false; + expect( textProxy.is( 'model:textProxy' ) ).to.be.false; } ); } ); diff --git a/tests/view/uielement.js b/tests/view/uielement.js index 65d591371..92eeda258 100644 --- a/tests/view/uielement.js +++ b/tests/view/uielement.js @@ -46,16 +46,26 @@ describe( 'UIElement', () => { it( 'should return true for uiElement/element, also with correct name and element name', () => { expect( el.is( 'uiElement' ) ).to.be.true; + expect( el.is( 'view:uiElement' ) ).to.be.true; expect( el.is( 'uiElement', 'span' ) ).to.be.true; + expect( el.is( 'view:uiElement', 'span' ) ).to.be.true; expect( el.is( 'element' ) ).to.be.true; + expect( el.is( 'view:element' ) ).to.be.true; + expect( el.is( 'node' ) ).to.be.true; + expect( el.is( 'view:node' ) ).to.be.true; expect( el.is( 'element', 'span' ) ).to.be.true; + expect( el.is( 'view:element', 'span' ) ).to.be.true; expect( el.is( 'span' ) ).to.be.true; + expect( el.is( 'view:span' ) ).to.be.true; } ); it( 'should return false for other accept values', () => { expect( el.is( 'uiElement', 'p' ) ).to.be.false; + expect( el.is( 'view:uiElement', 'p' ) ).to.be.false; expect( el.is( 'element', 'p' ) ).to.be.false; + expect( el.is( 'view:element', 'p' ) ).to.be.false; expect( el.is( 'p' ) ).to.be.false; + expect( el.is( 'view:p' ) ).to.be.false; expect( el.is( 'text' ) ).to.be.false; expect( el.is( 'textProxy' ) ).to.be.false; expect( el.is( 'containerElement' ) ).to.be.false; @@ -63,6 +73,9 @@ describe( 'UIElement', () => { expect( el.is( 'emptyElement' ) ).to.be.false; expect( el.is( 'rootElement' ) ).to.be.false; expect( el.is( 'documentFragment' ) ).to.be.false; + expect( el.is( 'model:element' ) ).to.be.false; + expect( el.is( 'model:span' ) ).to.be.false; + expect( el.is( 'model:node' ) ).to.be.false; } ); } );