/**
 * 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 { PortRecord } from '../../constants/flowdesigner.model' ; import * as Port from './port' ; import * as Position from '../position/position' ; describe ( 'isPortElseThrow' , ( ) => { it ( 'return true if given parameter is a PortRecord' , ( ) => { const testPort = new PortRecord ( ) ; const test = Port . isPortElseThrow ( testPort ) ; expect ( test ) . toEqual ( true ) ; } ) ; it ( 'throw if given parameter is not a PortRecord' , ( ) => { const testPort = Map ( ) ; expect ( ( ) => Port . isPortElseThrow ( testPort ) ) . toThrow ( ) ; } ) ; } ) ; describe ( 'isTopologyElseThrow' , ( ) => { it ( 'return true if given parameter is a valid Topology' , ( ) => { expect ( Port . isTopologyElseThrow ( 'INCOMING' ) ) . toBe ( true ) ; } ) ; it ( 'throw if given parameter is not a valid Topology and doThrow is true' , ( ) => { const invalidtopology = 'LOOKUP' ; expect ( ( ) => Port . isTopologyElseThrow ( 'LOOKUP' ) ) . toThrow ( `Should be a topology 'OUTGOING' or 'INCOMING', was given ${ invalidtopology }` ) ; } ) ; } ) ; describe ( 'port api' , ( ) => { const id = 'ID' ; const nodeId = 'NODE_ID' ; const position = Position . create ( 10 , 10 ) ; const index = 1 ; const topology = 'OUTGOING' ; const portType = 'PortType' ; const testPort = Port . create ( id , nodeId , index , topology , portType ) ; const key = 'KEY' ; const value = { whatever : 'whatever' } ; const improperId = 34 ; const improperNodeId = 42 ; const improperIndex = '10' ; const impropertopology = { } ; const improperPosition = Map ( { x : 10 , y : 10 } ) ; const improperPortType = { } ; const improperPort = Map ( ) ; describe ( 'create' , ( ) => { it ( 'given proper id, nodeId, index, topology and componentType return a Node' , ( ) => { const test = Port . create ( id , nodeId , index , topology , portType ) ; expect ( Port . isPort ( test ) ) . toEqual ( true ) ; } ) ; it ( 'throw if given an improper id' , ( ) => { expect ( ( ) => Port . create ( improperId as any , nodeId , index , topology , portType ) ) . toThrow ( ) ; } ) ; it ( 'throw if given an improper NodeId' , ( ) => { expect ( ( ) => Port . create ( id , improperNodeId as any , index , topology , portType ) ) . toThrow ( ) ; } ) ; it ( 'throw if given an improper index' , ( ) => { expect ( ( ) => Port . create ( id , nodeId , improperIndex as any , topology , portType ) ) . toThrow ( ) ; } ) ; it ( 'throw if given an improper topology' , ( ) => { expect ( ( ) => Port . create ( id , nodeId , index , impropertopology as any , portType ) ) . toThrow ( ) ; } ) ; it ( 'throw if given an improper componentType' , ( ) => { expect ( ( ) => Port . create ( id , nodeId , index , topology , improperPortType as any ) ) . toThrow ( ) ; } ) ; } ) ; describe ( 'isPort' , ( ) => { it ( 'return true if given parameter is a PortRecord' , ( ) => { const test = Port . isPort ( testPort ) ; expect ( test ) . toBe ( true ) ; } ) ; it ( 'return false if given parameter is not a PortRecord' , ( ) => { const test = Port . isPort ( improperPort ) ; expect ( test ) . toEqual ( false ) ; } ) ; } ) ; describe ( 'getId' , ( ) => { it ( 'given a proper Node return an Id' , ( ) => { const test = Port . getId ( testPort ) ; expect ( test ) . toEqual ( id ) ; } ) ; it ( 'throw given an improper Port' , ( ) => { expect ( ( ) => Port . getId ( improperPort ) ) . toThrow ( ) ; } ) ; } ) ; describe ( 'getNodeId' , ( ) => { it ( 'given a proper Port return a NodeId' , ( ) => { const test = Port . getNodeId ( testPort ) ; expect ( test ) . toEqual ( nodeId ) ; } ) ; it ( 'throw given an improper Port' , ( ) => { expect ( ( ) => Port . getId ( improperPort ) ) . toThrow ( ) ; } ) ; } ) ; describe ( 'setNodeId' , ( ) => { it ( 'given a proper Port and NodeId return a Port with updated NodeId' , ( ) => { const newNodeId = 'NEW_NODE_ID' ; const test = Port . setNodeId ( newNodeId , testPort ) ; expect ( Port . getNodeId ( test ) ) . toEqual ( newNodeId ) ; } ) ; it ( 'throw given an improper NodeId' , ( ) => { expect ( ( ) => Port . setNodeId ( improperNodeId as any , testPort ) ) . toThrow ( ) ; } ) ; it ( 'throw given an improper Port' , ( ) => { expect ( ( ) => Port . setNodeId ( nodeId , improperPort ) ) . toThrow ( ) ; } ) ; } ) ; describe ( 'getComponentType' , ( ) => { it ( 'given a proper Port return a ComponentType' , ( ) => { const test = Port . getComponentType ( testPort ) ; expect ( test ) . toEqual ( portType ) ; } ) ; it ( 'throw given an improper Port' , ( ) => { expect ( ( ) => Port . getComponentType ( improperPort ) ) . toThrow ( ) ; } ) ; } ) ; describe ( 'setComponentType' , ( ) => { it ( 'given a proper Port and ComponentType return a Port with updated ComponentType' , ( ) => { const newComponentType = 'NEW_COMPONENT_TYPE' ; const test = Port . setComponentType ( newComponentType , testPort ) ; expect ( Port . getComponentType ( test ) ) . toEqual ( newComponentType ) ; } ) ; it ( 'throw given an improper ComponentType' , ( ) => { expect ( ( ) => Port . setComponentType ( improperNodeId as any , testPort ) ) . toThrow ( ) ; } ) ; it ( 'throw given an improper Port' , ( ) => { expect ( ( ) => Port . setComponentType ( portType , improperPort ) ) . toThrow ( ) ; } ) ; } ) ; describe ( 'getPosition' , ( ) => { it ( 'given a proper Port return a Position' , ( ) => { const test = Port . getPosition ( Port . setPosition ( position , testPort ) ) ; expect ( test ) . toEqual ( position ) ; } ) ; it ( 'throw given an improper Port' , ( ) => { expect ( ( ) => Port . getPosition ( improperPortType ) ) . toThrow ( ) ; } ) ; } ) ; describe ( 'setPosition' , ( ) => { it ( 'given a proper Port and Position return a Port with updated Position' , ( ) => { const newPosition = Position . create ( 42 , 24 ) ; const test = Port . setPosition ( newPosition , testPort ) ; expect ( Port . getPosition ( test ) ) . toEqual ( newPosition ) ; } ) ; it ( 'throw given an improper position' , ( ) => { expect ( ( ) => Port . setPosition ( improperPosition as any , testPort ) ) . toThrow ( ) ; } ) ; it ( 'throw given an improper Port' , ( ) => { expect ( ( ) => Port . setPosition ( position , improperPort ) ) . toThrow ( ) ; } ) ; } ) ; describe ( 'getTopology' , ( ) => { it ( 'given a proper Port return a topology' , ( ) => { const test = Port . getTopology ( testPort ) ; expect ( test ) . toEqual ( topology ) ; } ) ; it ( 'throw given an improper Port' , ( ) => { expect ( ( ) => Port . getTopology ( improperPort ) ) . toThrow ( ) ; } ) ; } ) ; describe ( 'setTopology' , ( ) => { it ( 'given a proper Port and topology return a Port with updated topology' , ( ) => { const newTopology = 'INCOMING' ; const test = Port . setTopology ( newTopology , testPort ) ; expect ( Port . getTopology ( test ) ) . toEqual ( newTopology ) ; } ) ; it ( 'throw given an improper topology' , ( ) => { expect ( ( ) => Port . setTopology ( impropertopology as any , testPort ) ) . toThrow ( ) ; } ) ; it ( 'throw given an improper Port' , ( ) => { expect ( ( ) => Port . setTopology ( topology , improperPort ) ) . toThrow ( ) ; } ) ; } ) ; describe ( 'getIndex' , ( ) => { it ( 'given a proper Port return an index' , ( ) => { const test = Port . getIndex ( testPort ) ; expect ( test ) . toEqual ( index ) ; } ) ; it ( 'throw given an improper Port' , ( ) => { expect ( ( ) => Port . getIndex ( improperPort ) ) . toThrow ( ) ; } ) ; } ) ; describe ( 'setIndex' , ( ) => { it ( 'given a proper Port and Index return a Port with updated Index' , ( ) => { const newIndex = 64 ; const test = Port . setIndex ( newIndex , testPort ) ; expect ( Port . getIndex ( test ) ) . toEqual ( newIndex ) ; } ) ; it ( 'throw given an improper index' , ( ) => { expect ( ( ) => Port . setTopology ( improperIndex , testPort ) ) . toThrow ( ) ; } ) ; it ( 'throw given an improper Port' , ( ) => { expect ( ( ) => Port . setTopology ( topology , improperPort ) ) . toThrow ( ) ; } ) ; } ) ; describe ( 'setData' , ( ) => { it ( 'given a proper key, value and port return said port with the new key/value' , ( ) => { const newKey = 'newKey' ; const newValue = 'newValue' ; const test = Port . setData ( newKey , newValue , testPort ) ; expect ( Port . getData ( newKey , test ) ) . toEqual ( newValue ) ; } ) ; it ( 'throw given an improper key' , ( ) => { const improperKey = 12 ; expect ( ( ) => Port . setData ( improperKey as any , value , testPort ) ) . toThrow ( ) ; } ) ; it ( 'throw given an improper port' , ( ) => { expect ( ( ) => Port . setData ( key , value , improperPort ) ) . toThrow ( ) ; } ) ; } ) ; describe ( 'getData' , ( ) => { it ( 'given a proper key and port return value associated with the key' , ( ) => { const newKey = 'newKey' ; const newValue = 'newValue' ; const preparedPort = Port . setData ( newKey , newValue , testPort ) ; const test = Port . getData ( newKey , preparedPort ) ; expect ( test ) . toEqual ( newValue ) ; } ) ; it ( 'throw given an improper key' , ( ) => { const improperKey = 12 ; expect ( ( ) => Port . getData ( improperKey as any , testPort ) ) . toThrow ( ) ; } ) ; it ( 'throw given an improper port' , ( ) => { expect ( ( ) => Port . getData ( key , improperPort ) ) . toThrow ( ) ; } ) ; } ) ; describe ( 'hasData' , ( ) => { it ( 'given a proper key and port return true if key exist' , ( ) => { const newKey = 'newKey' ; const newValue = 'newValue' ; const preparedPort = Port . setData ( newKey , newValue , testPort ) ; const test = Port . hasData ( newKey , preparedPort ) ; expect ( test ) . toEqual ( true ) ; } ) ; it ( 'throw given an improper key' , ( ) => { const improperKey = 12 ; expect ( ( ) => Port . hasData ( improperKey as any , testPort ) ) . toThrow ( ) ; } ) ; it ( 'throw given an improper port' , ( ) => { expect ( ( ) => Port . hasData ( key , improperPort ) ) . toThrow ( ) ; } ) ; } ) ; describe ( 'deleteData' , ( ) => { it ( 'given a proper key and port return port without the key in data property if key exist' , ( ) => { const newKey = 'newKey' ; const newValue = 'newValue' ; const preparedPort = Port . setData ( newKey , newValue , testPort ) ; const test = Port . deleteData ( newKey , preparedPort ) ; expect ( Port . hasData ( newKey , test ) ) . toEqual ( false ) ; } ) ; it ( 'throw given an improper key' , ( ) => { const improperKey = 12 ; expect ( ( ) => Port . deleteData ( improperKey as any , testPort ) ) . toThrow ( ) ; } ) ; it ( 'throw given an improper port' , ( ) => { expect ( ( ) => Port . deleteData ( key , improperPort ) ) . toThrow ( ) ; } ) ; } ) ; describe ( 'setGraphicalAttribute' , ( ) => { it ( 'given a proper key, value and port return said port with the new key/value' , ( ) => { const newKey = 'newKey' ; const newValue = 'newValue' ; const test = Port . setGraphicalAttribute ( newKey , newValue , testPort ) ; expect ( Port . getGraphicalAttribute ( newKey , test ) ) . toEqual ( newValue ) ; } ) ; it ( 'throw given a key being part of FORBIDEN_GRAPHICAL_ATTRIBUTES' , ( ) => { const improperNewKey = 'portType' ; const newValue = 'newValue' ; expect ( ( ) => Port . setGraphicalAttribute ( improperNewKey , newValue , testPort ) ) . toThrow ( ) ; } ) ; it ( 'throw given an improper key' , ( ) => { const improperKey = 12 ; expect ( ( ) => Port . setGraphicalAttribute ( improperKey as any , value , testPort ) ) . toThrow ( ) ; } ) ; it ( 'throw given an improper port' , ( ) => { expect ( ( ) => Port . setGraphicalAttribute ( key , value , improperPort ) ) . toThrow ( ) ; } ) ; } ) ; describe ( 'getGraphicalAttribute' , ( ) => { it ( 'given a proper key and port return value associated with the key' , ( ) => { const newKey = 'newKey' ; const newValue = 'newValue' ; const preparedPort = Port . setGraphicalAttribute ( newKey , newValue , testPort ) ; const test = Port . getGraphicalAttribute ( newKey , preparedPort ) ; expect ( test ) . toEqual ( newValue ) ; } ) ; it ( 'throw given a key being part of FORBIDEN_GRAPHICAL_ATTRIBUTES' , ( ) => { const improperNewKey = 'portType' ; expect ( ( ) => Port . getGraphicalAttribute ( improperNewKey , testPort ) ) . toThrow ( ) ; } ) ; it ( 'throw given an improper key' , ( ) => { const improperKey = 12 ; expect ( ( ) => Port . getGraphicalAttribute ( improperKey as any , testPort ) ) . toThrow ( ) ; } ) ; it ( 'throw given an improper port' , ( ) => { expect ( ( ) => Port . getGraphicalAttribute ( key , improperPort ) ) . toThrow ( ) ; } ) ; } ) ; describe ( 'hasGraphicalAttribute' , ( ) => { it ( 'given a proper key and port return true if key exist' , ( ) => { const newKey = 'newKey' ; const newValue = 'newValue' ; const preparedPort = Port . setGraphicalAttribute ( newKey , newValue , testPort ) ; const test = Port . hasGraphicalAttribute ( newKey , preparedPort ) ; expect ( test ) . toEqual ( true ) ; } ) ; it ( 'throw given a key being part of FORBIDEN_GRAPHICAL_ATTRIBUTES' , ( ) => { const improperKey = 'portType' ; expect ( ( ) => Port . hasGraphicalAttribute ( improperKey , testPort ) ) . toThrow ( ) ; } ) ; it ( 'throw given an improper key' , ( ) => { const improperKey = 12 ; expect ( ( ) => Port . hasGraphicalAttribute ( improperKey as any , testPort ) ) . toThrow ( ) ; } ) ; it ( 'throw given an improper port' , ( ) => { expect ( ( ) => Port . hasGraphicalAttribute ( key , improperPort ) ) . toThrow ( ) ; } ) ; } ) ; describe ( 'deleteGraphicalAttribute' , ( ) => { it ( 'given a proper key and port return port without the key in data property if key exist' , ( ) => { const newKey = 'newKey' ; const newValue = 'newValue' ; const preparedPort = Port . setGraphicalAttribute ( newKey , newValue , testPort ) ; const test = Port . deleteGraphicalAttribute ( newKey , preparedPort ) ; expect ( Port . hasGraphicalAttribute ( newKey , test ) ) . toEqual ( false ) ; } ) ; it ( 'throw given a key being part of FORBIDEN_GRAPHICAL_ATTRIBUTES' , ( ) => { const improperKey = 'portType' ; expect ( ( ) => Port . deleteGraphicalAttribute ( improperKey , testPort ) ) . toThrow ( ) ; } ) ; it ( 'throw given an improper key' , ( ) => { const improperKey = 12 ; expect ( ( ) => Port . deleteGraphicalAttribute ( improperKey as any , testPort ) ) . toThrow ( ) ; } ) ; it ( 'throw given an improper port' , ( ) => { expect ( ( ) => Port . deleteGraphicalAttribute ( key , improperPort ) ) . toThrow ( ) ; } ) ; } ) ; } ) ;