/**
 * test are not exhaustive in this section related to functions :
 * 	setData,
 *	getData,
 *	hasData,
 *	deleteData,
 *	setGraphicalAttribute,
 *	getGraphicalAttribute,
 *	hasGraphicalAttribute,
 *	deleteGraphicalAttribute

    because the underlying module data is itself tested.
 */ import { Map } from 'immutable' ; import { NodeRecord , NestedNodeRecord } from '../../constants/flowdesigner.model' ; import * as Node from './node' ; import * as Position from '../position/position' ; import * as Size from '../size/size' ; const isNotNodeException = `NodeRecord should be a NodeRecord, was given
"""
object
"""
Map {}
"""` ; const improperSizeMessage = `SizeRecord should be a SizeRecord, was given
"""
object
"""
Map { "width": 20, "height": 50 }
"""
you should use Size module functions to create and transform Size` ; const improperPositionMessage = `PositionRecord should be a PositionRecord, was given
"""
object
"""
Map { "x": 10, "y": 10 }
"""
` ; const protectedValueException = 'position is a protected value of the Node, please use getPosition setPosition from this module to make change on those values' ; describe ( 'isNodeElseThrow' , ( ) => { it ( 'return true if parameter node is a NodeRecord' , ( ) => { const testNode = new NodeRecord ( ) ; const test = Node . isNodeElseThrow ( testNode ) ; expect ( test ) . toEqual ( true ) ; } ) ; it ( 'return true if parameter node is a NestedNodeRecord' , ( ) => { const testNode = new NestedNodeRecord ( ) ; const test = Node . isNodeElseThrow ( testNode ) ; expect ( test ) . toEqual ( true ) ; } ) ; it ( 'thow an error if parameter is not a NodeRecord' , ( ) => { const testNode = Map ( ) ; expect ( ( ) => Node . isNodeElseThrow ( testNode ) ) . toThrow ( isNotNodeException ) ; } ) ; } ) ; describe ( 'Node' , ( ) => { const id = 'ID' ; const position = Position . create ( 10 , 10 ) ; const size = Size . create ( 50 , 80 ) ; const nodeType = 'NodeType' ; const testNode = Node . create ( id , position , size , nodeType ) ; const key = 'KEY' ; const value = { whatever : 'whatever' } ; const improperId = 34 ; const improperPosition = Map ( { x : 10 , y : 10 } ) ; const improperSize = Map ( { width : 20 , height : 50 } ) ; const improperNodeType = { } ; const improperNode = Map ( ) ; describe ( 'create' , ( ) => { it ( 'given proper id, position, size and componentType return a Node' , ( ) => { const test = Node . create ( id , position , size , nodeType ) ; expect ( Node . isNode ( test ) ) . toEqual ( true ) ; } ) ; it ( 'throw if given an improper id' , ( ) => { expect ( ( ) => Node . create ( improperId as any , position , size , nodeType ) ) . toThrow ( 'nodeId should be a string, was given 34' ) ; } ) ; it ( 'throw if given an improper Position' , ( ) => { expect ( ( ) => Node . create ( id , improperPosition , size , nodeType ) ) . toThrow ( improperPositionMessage ) ; } ) ; it ( 'throw if given an improper Size' , ( ) => { expect ( ( ) => Node . create ( id , position , improperSize , nodeType ) ) . toThrow ( improperSizeMessage ) ; } ) ; it ( 'throw if given an improper componentType' , ( ) => { expect ( ( ) => Node . create ( id , position , size , improperNodeType as any ) ) . toThrow ( 'nodeType should be a string, was given [object Object]' ) ; } ) ; } ) ; describe ( 'isNode' , ( ) => { it ( 'return true if parameter node is a NodeRecord' , ( ) => { const test = Node . isNode ( testNode ) ; expect ( test ) . toEqual ( true ) ; } ) ; it ( 'thow an error if parameter is not a NodeRecord' , ( ) => { const test = Node . isNode ( improperNode ) ; expect ( test ) . toEqual ( false ) ; } ) ; } ) ; describe ( 'getId' , ( ) => { it ( 'given a proper Node return an Id' , ( ) => { const test = Node . getId ( testNode ) ; expect ( test ) . toEqual ( id ) ; } ) ; it ( 'throw given an improper node' , ( ) => { expect ( ( ) => Node . getId ( improperNode ) ) . toThrow ( isNotNodeException ) ; } ) ; } ) ; describe ( 'getPosition' , ( ) => { it ( 'given a proper Node return a Position' , ( ) => { const test = Node . getPosition ( testNode ) ; expect ( test ) . toEqual ( position ) ; } ) ; it ( 'throw given an improper node' , ( ) => { expect ( ( ) => Node . getPosition ( improperNode ) ) . toThrow ( isNotNodeException ) ; } ) ; } ) ; describe ( 'setPosition' , ( ) => { it ( 'given a proper Node and Position return a Node with updated Position' , ( ) => { const newPosition = Position . create ( 100 , 100 ) ; const test = Node . setPosition ( newPosition , testNode ) ; expect ( Node . getPosition ( test ) ) . toEqual ( newPosition ) ; } ) ; it ( 'throw given an improper Position' , ( ) => { expect ( ( ) => Node . setPosition ( improperPosition , testNode ) ) . toThrow ( `PositionRecord should be a PositionRecord, was given
"""
object
"""
Map { "x": 10, "y": 10 }
"""
you should use Position module functions to create and transform Position` ) ; } ) ; it ( 'throw given an improper Node' , ( ) => { expect ( ( ) => Node . setPosition ( position , improperNode ) ) . toThrow ( isNotNodeException ) ; } ) ; } ) ; describe ( 'getSize' , ( ) => { it ( 'given a proper Node return a Size' , ( ) => { const test = Node . getSize ( testNode ) ; expect ( test ) . toEqual ( size ) ; } ) ; it ( 'throw given an improper node' , ( ) => { expect ( ( ) => Node . getSize ( improperNode ) ) . toThrow ( isNotNodeException ) ; } ) ; } ) ; describe ( 'setSize' , ( ) => { it ( 'given a proper Node and Size return a Node with updated Size' , ( ) => { const newSize = Size . create ( 100 , 100 ) ; const test = Node . setSize ( newSize , testNode ) ; expect ( Node . getSize ( test ) ) . toEqual ( newSize ) ; } ) ; it ( 'throw given an improper Size' , ( ) => { expect ( ( ) => Node . setSize ( improperSize , testNode ) ) . toThrow ( improperSizeMessage ) ; } ) ; it ( 'throw given an improper Node' , ( ) => { expect ( ( ) => Node . setSize ( size , improperNode ) ) . toThrow ( isNotNodeException ) ; } ) ; } ) ; describe ( 'getComponentType' , ( ) => { it ( 'given a proper Node return a ComponentType' , ( ) => { const test = Node . getComponentType ( testNode ) ; expect ( test ) . toEqual ( nodeType ) ; } ) ; it ( 'throw given an improper Link' , ( ) => { expect ( ( ) => Node . getComponentType ( improperNode ) ) . toThrow ( isNotNodeException ) ; } ) ; } ) ; describe ( 'setComponentType' , ( ) => { it ( 'given a proper Node and ComponentType return a Node with updated ComponentType' , ( ) => { const newComponentType = 'squareOne' ; const test = Node . setComponentType ( newComponentType , testNode ) ; expect ( Node . getComponentType ( test ) ) . toEqual ( newComponentType ) ; } ) ; it ( 'throw given an improper ComponentType' , ( ) => { const newComponentType = { type : 'squareOne' } ; expect ( ( ) => Node . setComponentType ( newComponentType as any , testNode ) ) . toThrow ( 'nodeType should be a string, was given [object Object]' ) ; } ) ; it ( 'throw given an improper Node' , ( ) => { expect ( ( ) => Node . setComponentType ( nodeType , improperNode ) ) . toThrow ( isNotNodeException ) ; } ) ; } ) ; describe ( 'setData' , ( ) => { it ( 'given a proper key, value and node return said node with the new key/value' , ( ) => { const newKey = 'newKey' ; const newValue = 'newValue' ; const test = Node . setData ( newKey , newValue , testNode ) ; expect ( Node . getData ( newKey , test ) ) . toEqual ( newValue ) ; } ) ; it ( 'throw given an improper key' , ( ) => { const improperKey = 8 ; expect ( ( ) => Node . setData ( improperKey as any , value , testNode ) ) . toThrow ( `key should be a string, was given ${ improperKey && improperKey . toString ( ) } of type ${ typeof improperKey }` ) ; } ) ; it ( 'throw given an improper node' , ( ) => { expect ( ( ) => Node . setData ( key , value , improperNode ) ) . toThrow ( isNotNodeException ) ; } ) ; } ) ; describe ( 'getData' , ( ) => { it ( 'given a proper key and node return value associated with the key' , ( ) => { const newKey = 'newKey' ; const newValue = 'newValue' ; const preparedNode = Node . setData ( newKey , newValue , testNode ) ; const test = Node . getData ( newKey , preparedNode ) ; expect ( test ) . toEqual ( newValue ) ; } ) ; it ( 'throw given an improper key' , ( ) => { const improperKey = 8 ; expect ( ( ) => Node . getData ( improperKey as any , testNode ) ) . toThrow ( `key should be a string, was given ${ improperKey && improperKey . toString ( ) } of type ${ typeof improperKey }` ) ; } ) ; it ( 'throw given an improper node' , ( ) => { expect ( ( ) => Node . getData ( key , improperNode ) ) . toThrow ( isNotNodeException ) ; } ) ; } ) ; describe ( 'hasData' , ( ) => { it ( 'given a proper key and node return true if key exist' , ( ) => { const newKey = 'newKey' ; const newValue = 'newValue' ; const preparedNode = Node . setData ( newKey , newValue , testNode ) ; const test = Node . hasData ( newKey , preparedNode ) ; expect ( test ) . toEqual ( true ) ; } ) ; it ( 'throw given an improper key' , ( ) => { const improperKey = 8 ; expect ( ( ) => Node . hasData ( improperKey as any , testNode ) ) . toThrow ( `key should be a string, was given ${ improperKey && improperKey . toString ( ) } of type ${ typeof improperKey }` ) ; } ) ; it ( 'throw given an improper node' , ( ) => { expect ( ( ) => Node . hasData ( key , improperNode ) ) . toThrow ( isNotNodeException ) ; } ) ; } ) ; describe ( 'deleteData' , ( ) => { it ( 'given a proper key and node return node without the key in data property if key exist' , ( ) => { const newKey = 'newKey' ; const newValue = 'newValue' ; const preparedNode = Node . setData ( newKey , newValue , testNode ) ; const test = Node . deleteData ( newKey , preparedNode ) ; expect ( Node . hasData ( newKey , test ) ) . toEqual ( false ) ; } ) ; it ( 'throw given an improper key' , ( ) => { const improperKey = 8 ; expect ( ( ) => Node . deleteData ( improperKey as any , testNode ) ) . toThrow ( `key should be a string, was given ${ improperKey && improperKey . toString ( ) } of type ${ typeof improperKey }` ) ; } ) ; it ( 'throw given an improper node' , ( ) => { expect ( ( ) => Node . deleteData ( key , improperNode ) ) . toThrow ( isNotNodeException ) ; } ) ; } ) ; describe ( 'setGraphicalAttribute' , ( ) => { it ( 'given a proper key, value and node return said node with the new key/value' , ( ) => { const newKey = 'newKey' ; const newValue = 'newValue' ; const test = Node . setGraphicalAttribute ( newKey , newValue , testNode ) ; expect ( Node . getGraphicalAttribute ( newKey , test ) ) . toEqual ( newValue ) ; } ) ; it ( 'throw given a key being part of FORBIDEN_GRAPHICAL_ATTRIBUTES' , ( ) => { const improperNewKey = 'position' ; const newValue = 'newValue' ; expect ( ( ) => Node . setGraphicalAttribute ( improperNewKey , newValue , testNode ) ) . toThrow ( protectedValueException ) ; } ) ; it ( 'throw given an improper key' , ( ) => { const improperKey = 8 ; expect ( ( ) => Node . setGraphicalAttribute ( improperKey as any , value , testNode ) ) . toThrow ( `key should be a string, was given ${ improperKey && improperKey . toString ( ) } of type ${ typeof improperKey }` ) ; } ) ; it ( 'throw given an improper node' , ( ) => { expect ( ( ) => Node . setGraphicalAttribute ( key , value , improperNode ) ) . toThrow ( isNotNodeException ) ; } ) ; } ) ; describe ( 'getGraphicalAttribute' , ( ) => { it ( 'given a proper key and node return value associated with the key' , ( ) => { const newKey = 'newKey' ; const newValue = 'newValue' ; const preparedNode = Node . setGraphicalAttribute ( newKey , newValue , testNode ) ; const test = Node . getGraphicalAttribute ( newKey , preparedNode ) ; expect ( test ) . toEqual ( newValue ) ; } ) ; it ( 'throw given a key being part of FORBIDEN_GRAPHICAL_ATTRIBUTES' , ( ) => { const improperNewKey = 'position' ; expect ( ( ) => Node . getGraphicalAttribute ( improperNewKey , testNode ) ) . toThrow ( protectedValueException ) ; } ) ; it ( 'throw given an improper key' , ( ) => { const improperKey = 8 ; expect ( ( ) => Node . getGraphicalAttribute ( improperKey as any , testNode ) ) . toThrow ( `key should be a string, was given ${ improperKey && improperKey . toString ( ) } of type ${ typeof improperKey }` ) ; } ) ; it ( 'throw given an improper node' , ( ) => { expect ( ( ) => Node . getGraphicalAttribute ( key , improperNode ) ) . toThrow ( isNotNodeException ) ; } ) ; } ) ; describe ( 'hasGraphicalAttribute' , ( ) => { it ( 'given a proper key and node return true if key exist' , ( ) => { const newKey = 'newKey' ; const newValue = 'newValue' ; const preparedNode = Node . setGraphicalAttribute ( newKey , newValue , testNode ) ; const test = Node . hasGraphicalAttribute ( newKey , preparedNode ) ; expect ( test ) . toEqual ( true ) ; } ) ; it ( 'throw given a key being part of FORBIDEN_GRAPHICAL_ATTRIBUTES' , ( ) => { const improperKey = 'position' ; expect ( ( ) => Node . hasGraphicalAttribute ( improperKey , testNode ) ) . toThrow ( protectedValueException ) ; } ) ; it ( 'throw given an improper key' , ( ) => { const improperKey = 8 ; expect ( ( ) => Node . hasGraphicalAttribute ( improperKey as any , testNode ) ) . toThrow ( `key should be a string, was given ${ improperKey && improperKey . toString ( ) } of type ${ typeof improperKey }` ) ; } ) ; it ( 'throw given an improper node' , ( ) => { expect ( ( ) => Node . hasGraphicalAttribute ( key , improperNode ) ) . toThrow ( isNotNodeException ) ; } ) ; } ) ; describe ( 'deleteGraphicalAttribute' , ( ) => { it ( 'given a proper key and node return node without the key in data property if key exist' , ( ) => { const newKey = 'newKey' ; const newValue = 'newValue' ; const preparedNode = Node . setGraphicalAttribute ( newKey , newValue , testNode ) ; const test = Node . deleteGraphicalAttribute ( newKey , preparedNode ) ; expect ( Node . hasGraphicalAttribute ( newKey , test ) ) . toEqual ( false ) ; } ) ; it ( 'throw given a key being part of FORBIDEN_GRAPHICAL_ATTRIBUTES' , ( ) => { const improperKey = 'position' ; expect ( ( ) => Node . deleteGraphicalAttribute ( improperKey , testNode ) ) . toThrow ( protectedValueException ) ; } ) ; it ( 'throw given an improper key' , ( ) => { const improperKey = 8 ; expect ( ( ) => Node . deleteGraphicalAttribute ( improperKey as any , testNode ) ) . toThrow ( `key should be a string, was given ${ improperKey && improperKey . toString ( ) } of type ${ typeof improperKey }` ) ; } ) ; it ( 'throw given an improper node' , ( ) => { expect ( ( ) => Node . deleteGraphicalAttribute ( key , improperNode ) ) . toThrow ( isNotNodeException ) ; } ) ; } ) ; } ) ;