import { Map } from 'immutable' ; import { PositionRecord } from '../../constants/flowdesigner.model' ; import * as Position from './position' ; const isNotPositionException = `PositionRecord should be a PositionRecord, was given
"""
object
"""
Map {}
"""
you should use Position module functions to create and transform Position` ; const improperPositionException = `PositionRecord should be a PositionRecord, was given
"""
object
"""
Map { "x": 10, "y": 10 }
"""
you should use Position module functions to create and transform Position` ; const isImproperXCoordinate = 'x should be a number, was given 10 of type string' ; const isImproperYCoordinate = 'y should be a number, was given 50 of type string' ; describe ( 'isPositionElseThrow' , ( ) => { it ( 'return true if parameter position is a PositionRecord' , ( ) => { const testPosition = new PositionRecord ( ) ; const test = Position . isPositionElseThrow ( testPosition ) ; expect ( test ) . toEqual ( true ) ; } ) ; it ( 'thow an error if parameter is not a PositionRecord' , ( ) => { const testPosition = Map ( ) ; expect ( ( ) => Position . isPositionElseThrow ( testPosition ) ) . toThrow ( isNotPositionException ) ; } ) ; } ) ; describe ( 'Position' , ( ) => { const x = 10 ; const y = 50 ; const testPosition = Position . create ( x , y ) ; const improperX = '10' ; const improperY = '50' ; const improperTestPosition = Map ( { x : 10 , y : 10 } ) ; describe ( 'create' , ( ) => { it ( 'given proper x and y coordinate return a Position' , ( ) => { const test = Position . create ( x , y ) ; expect ( Position . isPosition ( test ) ) . toEqual ( true ) ; } ) ; it ( 'throw if given an improper id' , ( ) => { expect ( ( ) => Position . create ( improperX as any , y ) ) . toThrow ( isImproperXCoordinate ) ; } ) ; it ( 'throw if given an improper Position' , ( ) => { expect ( ( ) => Position . create ( x , improperY as any ) ) . toThrow ( isImproperYCoordinate ) ; } ) ; } ) ; describe ( 'isPosition' , ( ) => { it ( 'return true if parameter position is a PositionRecord' , ( ) => { const test = Position . isPosition ( testPosition ) ; expect ( test ) . toEqual ( true ) ; } ) ; it ( 'thow an error if parameter is not a NodeRecord' , ( ) => { const test = Position . isPosition ( improperTestPosition ) ; expect ( test ) . toEqual ( false ) ; } ) ; } ) ; describe ( 'getXCoordinate' , ( ) => { it ( 'given a proper position return x' , ( ) => { const test = Position . getXCoordinate ( testPosition ) ; expect ( test ) . toEqual ( x ) ; } ) ; it ( 'throw given an improper position' , ( ) => { expect ( ( ) => Position . getXCoordinate ( improperTestPosition ) ) . toThrow ( improperPositionException ) ; } ) ; } ) ; describe ( 'setXCoordinate' , ( ) => { it ( 'given a proper Position and X coordinate return a Position with updated coordinate' , ( ) => { const newX = 500 ; const test = Position . setXCoordinate ( newX , testPosition ) ; expect ( Position . getXCoordinate ( test ) ) . toEqual ( newX ) ; } ) ; it ( 'throw given an improper X coordinate' , ( ) => { expect ( ( ) => Position . setXCoordinate ( improperX as any , testPosition ) ) . toThrow ( 'x should be a number, was given 10 of type string' ) ; } ) ; it ( 'throw given an improper Position' , ( ) => { expect ( ( ) => Position . setXCoordinate ( x , improperTestPosition ) ) . toThrow ( improperPositionException ) ; } ) ; } ) ; describe ( 'getYCoordinate' , ( ) => { it ( 'given a proper Position return y' , ( ) => { const test = Position . getYCoordinate ( testPosition ) ; expect ( test ) . toEqual ( y ) ; } ) ; it ( 'throw given an improper position' , ( ) => { expect ( ( ) => Position . getYCoordinate ( improperTestPosition ) ) . toThrow ( improperPositionException ) ; } ) ; } ) ; describe ( 'setYCoordinate' , ( ) => { it ( 'given a proper Position and Y coordinate return a Position with updated coordinate' , ( ) => { const newY = 500 ; const test = Position . setYCoordinate ( newY , testPosition ) ; expect ( Position . getYCoordinate ( test ) ) . toEqual ( newY ) ; } ) ; it ( 'throw given an improperY coordinate' , ( ) => { expect ( ( ) => Position . setYCoordinate ( improperY as any , testPosition ) ) . toThrow ( 'y should be a number, was given 50 of type string' ) ; } ) ; it ( 'throw given an improper Position' , ( ) => { expect ( ( ) => Position . setYCoordinate ( y , improperTestPosition ) ) . toThrow ( improperPositionException ) ; } ) ; } ) ; } ) ;