@@ -4,98 +4,107 @@ import nock from 'nock'
44
55import { recalculateShape } from '../map'
66
7- const controlPoints = require ( './fixtures/test-control-points.json' )
7+ const fixtureControlPoints = require ( './fixtures/test-control-points.json' )
88const followStreets = true
99const patternShape = require ( './fixtures/test-pattern-shape.json' )
1010
1111describe ( 'editor > util > map >' , ( ) => {
1212 describe ( 'recalculateShape >' , ( ) => {
13- function makeTestCase ( { editType, index, mapzenResponeFile, newPoint} ) {
14- return async ( ) => {
15- // setup nock
16- if ( mapzenResponeFile ) {
17- nock ( 'https://valhalla.mapzen.com' )
18- . get ( / ^ \/ r o u t e \? j s o n .* / )
19- . reply ( 200 , require ( mapzenResponeFile ) )
20- }
13+ function makeTestCase ( {
14+ controlPoints = fixtureControlPoints ,
15+ editType,
16+ index,
17+ mapzenResponeFile,
18+ newPoint,
19+ resultCoordsCanBeNull = false ,
20+ title
21+ } ) {
22+ return it (
23+ title ,
24+ async ( ) => {
25+ // setup nock
26+ if ( mapzenResponeFile ) {
27+ nock ( 'https://valhalla.mapzen.com' )
28+ . get ( / ^ \/ r o u t e \? j s o n .* / )
29+ . reply ( 200 , require ( mapzenResponeFile ) )
30+ }
2131
22- const result = await recalculateShape ( {
23- controlPoints,
24- editType,
25- index,
26- followStreets,
27- newPoint,
28- patternShape
29- } )
32+ const result = await recalculateShape ( {
33+ controlPoints,
34+ editType,
35+ index,
36+ followStreets,
37+ newPoint,
38+ patternShape
39+ } )
3040
31- expect ( result ) . toMatchSnapshot ( )
32- const { coordinates} = result
33- expect ( coordinates . length ) . toBeGreaterThan ( 0 )
34- coordinates . forEach ( coord => {
35- expect ( coord . length ) . toBe ( 2 )
36- expect ( Math . abs ( coord [ 0 ] ) ) . toBeLessThanOrEqual ( 180 )
37- expect ( Math . abs ( coord [ 1 ] ) ) . toBeLessThanOrEqual ( 90 )
38- } )
39- }
41+ expect ( result ) . toMatchSnapshot ( )
42+ const { coordinates} = result
43+ if ( ! resultCoordsCanBeNull ) {
44+ expect ( coordinates . length ) . toBeGreaterThan ( 0 )
45+ coordinates . forEach ( coord => {
46+ expect ( coord . length ) . toBe ( 2 )
47+ expect ( Math . abs ( coord [ 0 ] ) ) . toBeLessThanOrEqual ( 180 )
48+ expect ( Math . abs ( coord [ 1 ] ) ) . toBeLessThanOrEqual ( 90 )
49+ } )
50+ }
51+ }
52+ )
4053 }
4154
4255 describe ( 'updating >' , ( ) => {
43- it (
44- 'should update the first stop' ,
45- makeTestCase ( {
46- editType : 'update' ,
47- index : 0 ,
48- mapzenResponeFile : './fixtures/mapzen-response-update-first-stop.json' ,
49- newPoint : [ - 77.92553 , 42.08666 ]
50- } )
51- )
56+ makeTestCase ( {
57+ editType : 'update' ,
58+ index : 0 ,
59+ mapzenResponeFile : './fixtures/mapzen-response-update-first-stop.json' ,
60+ newPoint : [ - 77.92553 , 42.08666 ] ,
61+ title : 'should update the first stop'
62+ } )
5263
53- it (
54- 'should update the last stop' ,
55- makeTestCase ( {
56- editType : 'update' ,
57- index : 4 ,
58- mapzenResponeFile : './fixtures/mapzen-response-update-last-stop.json' ,
59- newPoint : [ - 77.92262 , 42.09828 ]
60- } )
61- )
64+ makeTestCase ( {
65+ editType : 'update' ,
66+ index : 4 ,
67+ mapzenResponeFile : './fixtures/mapzen-response-update-last-stop.json' ,
68+ newPoint : [ - 77.92262 , 42.09828 ] ,
69+ title : 'should update the last stop'
70+ } )
6271
63- it (
64- 'should update a point in the middle of the control points' ,
65- makeTestCase ( {
66- editType : 'update' ,
67- index : 3 ,
68- mapzenResponeFile : './fixtures/mapzen-response-update-middle-control-point.json' ,
69- newPoint : [ - 77.92382 , 42.09182 ]
70- } )
71- )
72+ makeTestCase ( {
73+ editType : 'update' ,
74+ index : 3 ,
75+ mapzenResponeFile : './fixtures/mapzen-response-update-middle-control-point.json' ,
76+ newPoint : [ - 77.92382 , 42.09182 ] ,
77+ title : 'should update a point in the middle of the control points'
78+ } )
7279 } )
7380
7481 describe ( 'deleting >' , ( ) => {
75- it (
76- 'should delete the first stop' ,
77- makeTestCase ( {
78- editType : 'delete' ,
79- index : 0
80- } )
81- )
82+ makeTestCase ( {
83+ editType : 'delete' ,
84+ index : 0 ,
85+ title : 'should delete the first stop'
86+ } )
8287
83- it (
84- 'should delete the last stop' ,
85- makeTestCase ( {
86- editType : 'delete' ,
87- index : 4
88- } )
89- )
88+ makeTestCase ( {
89+ editType : 'delete' ,
90+ index : 4 ,
91+ title : 'should delete the last stop'
92+ } )
9093
91- it (
92- 'should delete a point in the middle of the control points' ,
93- makeTestCase ( {
94- editType : 'delete' ,
95- index : 3 ,
96- mapzenResponeFile : './fixtures/mapzen-response-delete-middle-control-point.json'
97- } )
98- )
94+ makeTestCase ( {
95+ controlPoints : require ( './fixtures/test-control-points-with-extra-point-at-end.json' ) ,
96+ editType : 'delete' ,
97+ index : 2 ,
98+ resultCoordsCanBeNull : true ,
99+ title : 'should delete the last stop when there are control points after the last stop'
100+ } )
101+
102+ makeTestCase ( {
103+ editType : 'delete' ,
104+ index : 3 ,
105+ mapzenResponeFile : './fixtures/mapzen-response-delete-middle-control-point.json' ,
106+ title : 'should delete a point in the middle of the control points'
107+ } )
99108 } )
100109 } )
101110} )
0 commit comments