/**
 * 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 { LinkRecord } from '../../constants/flowdesigner.model' ; import * as Link from './link' ; const isNotLinkException = `Linkrecord should be a Linkrecord, was given
"""
object
"""
Map {}
"""
you should use Link module functions to create and transform Link` ; const protectedValueException = 'linkType is a protected value of the Link, please use getLinkType setLinkType from this module to make change on those values' ; describe ( 'isLinkElseThrow' , ( ) => { it ( 'return true if parameter link is a LinkRecord' , ( ) => { const testLink = new LinkRecord ( ) ; const test = Link . isLinkElseThrow ( testLink ) ; expect ( test ) . toEqual ( true ) ; } ) ; it ( 'thow an error if parameter is not a LinkRecord' , ( ) => { const testLink = Map ( ) ; expect ( ( ) => Link . isLinkElseThrow ( testLink ) ) . toThrow ( isNotLinkException ) ; } ) ; } ) ; describe ( 'Link' , ( ) => { const id = 'ID' ; const sourceId = 'SOURCE_ID' ; const targetId = 'TARGET_ID' ; const linkType = 'LinkType' ; const testLink = Link . create ( id , sourceId , targetId , linkType ) ; const key = 'KEY' ; const value = { whatever : 'whatever' } ; const improperId = 34 ; const improperSourceId = 42 ; const improperTargetId = 64 ; const improperLinkType = { } ; const improperLink = Map ( ) ; describe ( 'create' , ( ) => { it ( 'given proper id, sourceId, targetid and componentType return a Link' , ( ) => { const test = Link . create ( id , sourceId , targetId , linkType ) ; expect ( Link . isLink ( test ) ) . toEqual ( true ) ; } ) ; it ( 'throw if given an improper id' , ( ) => { expect ( ( ) => Link . create ( improperId as any , sourceId , targetId , linkType ) ) . toThrow ( 'id should be a string, was given 34' ) ; } ) ; it ( 'throw if given an improper sourceId' , ( ) => { expect ( ( ) => Link . create ( id , improperSourceId as any , targetId , linkType ) ) . toThrow ( 'id should be a string, was given 42' ) ; } ) ; it ( 'throw if given an improper targetId' , ( ) => { expect ( ( ) => Link . create ( id , sourceId , improperTargetId as any , linkType ) ) . toThrow ( 'id should be a string, was given 64' ) ; } ) ; it ( 'throw if given an improper componentType' , ( ) => { expect ( ( ) => Link . create ( id , sourceId , targetId , improperLinkType as any ) ) . toThrow ( 'linkType should be a string, was given [object Object]' ) ; } ) ; } ) ; describe ( 'isLink' , ( ) => { it ( 'return true if parameter link is a LinkRecord' , ( ) => { const test = Link . isLink ( testLink ) ; expect ( test ) . toEqual ( true ) ; } ) ; it ( 'thow an error if parameter is not a LinkRecord' , ( ) => { const test = Link . isLink ( improperLink ) ; expect ( test ) . toEqual ( false ) ; } ) ; } ) ; describe ( 'getId' , ( ) => { it ( 'given a proper Link return an Id' , ( ) => { const test = Link . getId ( testLink ) ; expect ( test ) . toEqual ( id ) ; } ) ; it ( 'throw given an improper link' , ( ) => { expect ( ( ) => Link . getId ( improperLink ) ) . toThrow ( isNotLinkException ) ; } ) ; } ) ; describe ( 'getSourceId' , ( ) => { it ( 'given a proper Link return a SourceId' , ( ) => { const test = Link . getSourceId ( testLink ) ; expect ( test ) . toEqual ( sourceId ) ; } ) ; it ( 'throw given an improper link' , ( ) => { expect ( ( ) => Link . getSourceId ( improperLink ) ) . toThrow ( isNotLinkException ) ; } ) ; } ) ; describe ( 'setSourceId' , ( ) => { it ( 'given a proper Link and SourceId return a Link with updated SourceId' , ( ) => { const newSourceId = 'newSourceId' ; const test = Link . setSourceId ( newSourceId , testLink ) ; expect ( Link . getSourceId ( test ) ) . toEqual ( newSourceId ) ; } ) ; it ( 'throw given an improper SourceId' , ( ) => { expect ( ( ) => Link . setSourceId ( improperSourceId as any , testLink ) ) . toThrow ( 'id should be a string, was given 42' ) ; } ) ; it ( 'throw given an improper Link' , ( ) => { expect ( ( ) => Link . setSourceId ( sourceId , improperLink ) ) . toThrow ( isNotLinkException ) ; } ) ; } ) ; describe ( 'getTargetId' , ( ) => { it ( 'given a proper Link return a TargetId' , ( ) => { const test = Link . getTargetId ( testLink ) ; expect ( test ) . toEqual ( targetId ) ; } ) ; it ( 'throw given an improper link' , ( ) => { expect ( ( ) => Link . getTargetId ( improperLink ) ) . toThrow ( isNotLinkException ) ; } ) ; } ) ; describe ( 'setTargetId' , ( ) => { it ( 'given a proper Link and TargetId return a Link with updated TargetId' , ( ) => { const newTargetId = 'newTargetId' ; const test = Link . setTargetId ( newTargetId , testLink ) ; expect ( Link . getTargetId ( test ) ) . toEqual ( newTargetId ) ; } ) ; it ( 'throw given an improper TargetId' , ( ) => { expect ( ( ) => Link . setTargetId ( improperTargetId as any , testLink ) ) . toThrow ( 'id should be a string, was given 64' ) ; } ) ; it ( 'throw given an improper Link' , ( ) => { expect ( ( ) => Link . setTargetId ( targetId , improperLink ) ) . toThrow ( isNotLinkException ) ; } ) ; } ) ; describe ( 'getComponentType' , ( ) => { it ( 'given a proper Link return a ComponentType' , ( ) => { const test = Link . getComponentType ( testLink ) ; expect ( test ) . toEqual ( linkType ) ; } ) ; it ( 'throw given an improper Link' , ( ) => { expect ( ( ) => Link . getComponentType ( improperLink ) ) . toThrow ( isNotLinkException ) ; } ) ; } ) ; describe ( 'setComponentType' , ( ) => { it ( 'given a proper Link and ComponentType return a Link with updated ComponentType' , ( ) => { const newComponentType = 'monotoneLink' ; const test = Link . setComponentType ( newComponentType , testLink ) ; expect ( Link . getComponentType ( test ) ) . toEqual ( newComponentType ) ; } ) ; it ( 'throw given an improper ComponentType' , ( ) => { const newComponentType = { type : 'squareOne' } ; expect ( ( ) => Link . setComponentType ( newComponentType as any , testLink ) ) . toThrow ( 'linkType should be a string, was given [object Object]' ) ; } ) ; it ( 'throw given an improper Link' , ( ) => { expect ( ( ) => Link . setComponentType ( linkType , improperLink ) ) . toThrow ( isNotLinkException ) ; } ) ; } ) ; describe ( 'setData' , ( ) => { it ( 'given a proper key, value and link return said link with the new key/value' , ( ) => { const newKey = 'newKey' ; const newValue = 'newValue' ; const test = Link . setData ( newKey , newValue , testLink ) ; expect ( Link . getData ( newKey , test ) ) . toEqual ( newValue ) ; } ) ; it ( 'throw given an improper key' , ( ) => { const improperKey = 8 ; expect ( ( ) => Link . setData ( improperKey as any , value , testLink ) ) . toThrow ( `key should be a string, was given ${ improperKey && improperKey . toString ( ) } of type ${ typeof improperKey }` ) ; } ) ; it ( 'throw given an improper link' , ( ) => { expect ( ( ) => Link . setData ( key , value , improperLink ) ) . toThrow ( isNotLinkException ) ; } ) ; } ) ; describe ( 'getData' , ( ) => { it ( 'given a proper key and link return value associated with the key' , ( ) => { const newKey = 'newKey' ; const newValue = 'newValue' ; const preparedLink = Link . setData ( newKey , newValue , testLink ) ; const test = Link . getData ( newKey , preparedLink ) ; expect ( test ) . toEqual ( newValue ) ; } ) ; it ( 'throw given an improper key' , ( ) => { const improperKey = 8 ; expect ( ( ) => Link . getData ( improperKey as any , testLink ) ) . toThrow ( `key should be a string, was given ${ improperKey && improperKey . toString ( ) } of type ${ typeof improperKey }` ) ; } ) ; it ( 'throw given an improper link' , ( ) => { expect ( ( ) => Link . getData ( key , improperLink ) ) . toThrow ( isNotLinkException ) ; } ) ; } ) ; describe ( 'hasData' , ( ) => { it ( 'given a proper key and link return true if key exist' , ( ) => { const newKey = 'newKey' ; const newValue = 'newValue' ; const preparedLink = Link . setData ( newKey , newValue , testLink ) ; const test = Link . hasData ( newKey , preparedLink ) ; expect ( test ) . toEqual ( true ) ; } ) ; it ( 'throw given an improper key' , ( ) => { const improperKey = 8 ; expect ( ( ) => Link . hasData ( improperKey as any , testLink ) ) . toThrow ( `key should be a string, was given ${ improperKey && improperKey . toString ( ) } of type ${ typeof improperKey }` ) ; } ) ; it ( 'throw given an improper link' , ( ) => { expect ( ( ) => Link . hasData ( key , improperLink ) ) . toThrow ( isNotLinkException ) ; } ) ; } ) ; describe ( 'deleteData' , ( ) => { it ( 'given a proper key and link return link without the key in data property if key exist' , ( ) => { const newKey = 'newKey' ; const newValue = 'newValue' ; const preparedLink = Link . setData ( newKey , newValue , testLink ) ; const test = Link . deleteData ( newKey , preparedLink ) ; expect ( Link . hasData ( newKey , test ) ) . toEqual ( false ) ; } ) ; it ( 'throw given an improper key' , ( ) => { const improperKey = 8 ; expect ( ( ) => Link . deleteData ( improperKey as any , testLink ) ) . toThrow ( `key should be a string, was given ${ improperKey && improperKey . toString ( ) } of type ${ typeof improperKey }` ) ; } ) ; it ( 'throw given an improper link' , ( ) => { expect ( ( ) => Link . deleteData ( key , improperLink ) ) . toThrow ( isNotLinkException ) ; } ) ; } ) ; describe ( 'setGraphicalAttribute' , ( ) => { it ( 'given a proper key, value and link return said link with the new key/value' , ( ) => { const newKey = 'newKey' ; const newValue = 'newValue' ; const test = Link . setGraphicalAttribute ( newKey , newValue , testLink ) ; expect ( Link . getGraphicalAttribute ( newKey , test ) ) . toEqual ( newValue ) ; } ) ; it ( 'throw given a key being part of FORBIDEN_GRAPHICAL_ATTRIBUTES' , ( ) => { const improperNewKey = 'linkType' ; const newValue = 'newValue' ; expect ( ( ) => Link . setGraphicalAttribute ( improperNewKey , newValue , testLink ) ) . toThrow ( protectedValueException ) ; } ) ; it ( 'throw given an improper key' , ( ) => { const improperKey = 8 ; expect ( ( ) => Link . setGraphicalAttribute ( improperKey as any , value , testLink ) ) . toThrow ( `key should be a string, was given ${ improperKey && improperKey . toString ( ) } of type ${ typeof improperKey }` ) ; } ) ; it ( 'throw given an improper link' , ( ) => { expect ( ( ) => Link . setGraphicalAttribute ( key , value , improperLink ) ) . toThrow ( isNotLinkException ) ; } ) ; } ) ; describe ( 'getGraphicalAttribute' , ( ) => { it ( 'given a proper key and link return value associated with the key' , ( ) => { const newKey = 'newKey' ; const newValue = 'newValue' ; const preparedLink = Link . setGraphicalAttribute ( newKey , newValue , testLink ) ; const test = Link . getGraphicalAttribute ( newKey , preparedLink ) ; expect ( test ) . toEqual ( newValue ) ; } ) ; it ( 'throw given a key being part of FORBIDEN_GRAPHICAL_ATTRIBUTES' , ( ) => { const improperNewKey = 'linkType' ; expect ( ( ) => Link . getGraphicalAttribute ( improperNewKey , testLink ) ) . toThrow ( protectedValueException ) ; } ) ; it ( 'throw given an improper key' , ( ) => { const improperKey = 8 ; expect ( ( ) => Link . getGraphicalAttribute ( improperKey as any , testLink ) ) . toThrow ( `key should be a string, was given ${ improperKey && improperKey . toString ( ) } of type ${ typeof improperKey }` ) ; } ) ; it ( 'throw given an improper link' , ( ) => { expect ( ( ) => Link . getGraphicalAttribute ( key , improperLink ) ) . toThrow ( isNotLinkException ) ; } ) ; } ) ; describe ( 'hasGraphicalAttribute' , ( ) => { it ( 'given a proper key and link return true if key exist' , ( ) => { const newKey = 'newKey' ; const newValue = 'newValue' ; const preparedLink = Link . setGraphicalAttribute ( newKey , newValue , testLink ) ; const test = Link . hasGraphicalAttribute ( newKey , preparedLink ) ; expect ( test ) . toEqual ( true ) ; } ) ; it ( 'throw given a key being part of FORBIDEN_GRAPHICAL_ATTRIBUTES' , ( ) => { const improperKey = 'linkType' ; expect ( ( ) => Link . hasGraphicalAttribute ( improperKey , testLink ) ) . toThrow ( protectedValueException ) ; } ) ; it ( 'throw given an improper key' , ( ) => { const improperKey = 8 ; expect ( ( ) => Link . hasGraphicalAttribute ( improperKey as any , testLink ) ) . toThrow ( `key should be a string, was given ${ improperKey && improperKey . toString ( ) } of type ${ typeof improperKey }` ) ; } ) ; it ( 'throw given an improper link' , ( ) => { expect ( ( ) => Link . hasGraphicalAttribute ( key , improperLink ) ) . toThrow ( isNotLinkException ) ; } ) ; } ) ; describe ( 'deleteGraphicalAttribute' , ( ) => { it ( 'given a proper key and link return link without the key in data property if key exist' , ( ) => { const newKey = 'newKey' ; const newValue = 'newValue' ; const preparedLink = Link . setGraphicalAttribute ( newKey , newValue , testLink ) ; const test = Link . deleteGraphicalAttribute ( newKey , preparedLink ) ; expect ( Link . hasGraphicalAttribute ( newKey , test ) ) . toEqual ( false ) ; } ) ; it ( 'throw given a key being part of FORBIDEN_GRAPHICAL_ATTRIBUTES' , ( ) => { const improperKey = 'linkType' ; expect ( ( ) => Link . deleteGraphicalAttribute ( improperKey , testLink ) ) . toThrow ( protectedValueException ) ; } ) ; it ( 'throw given an improper key' , ( ) => { const improperKey = 8 ; expect ( ( ) => Link . deleteGraphicalAttribute ( improperKey as any , testLink ) ) . toThrow ( `key should be a string, was given ${ improperKey && improperKey . toString ( ) } of type ${ typeof improperKey }` ) ; } ) ; it ( 'throw given an improper link' , ( ) => { expect ( ( ) => Link . deleteGraphicalAttribute ( key , improperLink ) ) . toThrow ( isNotLinkException ) ; } ) ; } ) ; } ) ;