Skip to content

Commit 3c99fc5

Browse files
evansirokylandonreed
authored andcommitted
test(editor): add more tests for shape recalc
Also fix a few things along the way
1 parent de5c816 commit 3c99fc5

File tree

12 files changed

+1546
-29
lines changed

12 files changed

+1546
-29
lines changed

lib/editor/util/__tests__/__snapshots__/map.js.snap

Lines changed: 832 additions & 4 deletions
Large diffs are not rendered by default.

lib/editor/util/__tests__/map.js

Lines changed: 86 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ import nock from 'nock'
44

55
import {recalculatePatternCoordinates} from '../map'
66

7+
const controlPoints = require('./test-control-points.json')
8+
const followStreets = true
9+
const patternShape = require('./test-pattern-shape.json')
10+
711
describe('editor > util > map >', () => {
812
describe('recalculatePatternCoordinates >', () => {
9-
const controlPoints = require('./fake-control-points.json')
10-
const followStreets = true
11-
const patternShape = require('./fake-pattern-shape.json')
12-
13-
function makeTestCase ({disableNock, editType, index, mapzenResponeFile, newPoint}) {
13+
function makeTestCase ({editType, index, mapzenResponeFile, newPoint}) {
1414
return async () => {
15-
if (!disableNock) {
16-
// setup nock
15+
// setup nock
16+
if (mapzenResponeFile) {
1717
nock('https://valhalla.mapzen.com')
1818
.get(/^\/route\?json.*/)
1919
.reply(200, require(mapzenResponeFile))
@@ -43,6 +43,85 @@ describe('editor > util > map >', () => {
4343
newPoint: [-77.92553, 42.08666]
4444
})
4545
)
46+
47+
it(
48+
'should insert a point after the last stop',
49+
makeTestCase({
50+
editType: 'insert',
51+
index: 5,
52+
mapzenResponeFile: './mapzen-response-2.json',
53+
newPoint: [-77.92262, 42.09828]
54+
})
55+
)
56+
57+
it(
58+
'should insert a point in the middle of the control points',
59+
makeTestCase({
60+
editType: 'insert',
61+
index: 3,
62+
mapzenResponeFile: './mapzen-response-3.json',
63+
newPoint: [-77.92382, 42.09182]
64+
})
65+
)
66+
})
67+
68+
describe('updating >', () => {
69+
it(
70+
'should update the first stop',
71+
makeTestCase({
72+
editType: 'update',
73+
index: 0,
74+
mapzenResponeFile: './mapzen-response-4.json',
75+
newPoint: [-77.92553, 42.08666]
76+
})
77+
)
78+
79+
it(
80+
'should update the last stop',
81+
makeTestCase({
82+
editType: 'update',
83+
index: 4,
84+
mapzenResponeFile: './mapzen-response-5.json',
85+
newPoint: [-77.92262, 42.09828]
86+
})
87+
)
88+
89+
it(
90+
'should update a point in the middle of the control points',
91+
makeTestCase({
92+
editType: 'update',
93+
index: 3,
94+
mapzenResponeFile: './mapzen-response-6.json',
95+
newPoint: [-77.92382, 42.09182]
96+
})
97+
)
98+
})
99+
100+
describe('deleting >', () => {
101+
it(
102+
'should delete the first stop',
103+
makeTestCase({
104+
editType: 'delete',
105+
index: 0
106+
})
107+
)
108+
109+
it(
110+
'should delete the last stop',
111+
makeTestCase({
112+
editType: 'delete',
113+
index: 4
114+
})
115+
)
116+
117+
it(
118+
'should delete a point in the middle of the control points',
119+
makeTestCase({
120+
editType: 'delete',
121+
index: 3,
122+
mapzenResponeFile: './mapzen-response-7.json'
123+
})
124+
)
46125
})
47126
})
48127
})
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
{
2+
"trip": {
3+
"language": "en-US",
4+
"summary": {
5+
"max_lon": -77.923058,
6+
"max_lat": 42.097988,
7+
"time": 12,
8+
"length": 0.209,
9+
"min_lat": 42.096169,
10+
"min_lon": -77.923637
11+
},
12+
"locations": [{
13+
"lon": -77.923058,
14+
"lat": 42.096169,
15+
"type": "break"
16+
},
17+
{
18+
"side_of_street": "right",
19+
"lon": -77.922623,
20+
"lat": 42.098282,
21+
"type": "break"
22+
}
23+
],
24+
"units": "kilometers",
25+
"legs": [{
26+
"shape": "oajhoAbn`ssCqRzAu^rFuUbFs_@xMeFxB",
27+
"summary": {
28+
"max_lon": -77.923058,
29+
"max_lat": 42.097988,
30+
"time": 12,
31+
"length": 0.209,
32+
"min_lat": 42.096169,
33+
"min_lon": -77.923637
34+
},
35+
"maneuvers": [{
36+
"travel_mode": "drive",
37+
"begin_shape_index": 0,
38+
"length": 0.209,
39+
"time": 12,
40+
"type": 1,
41+
"end_shape_index": 5,
42+
"instruction": "Drive north on Stannards Road/NY 19.",
43+
"verbal_pre_transition_instruction": "Drive north on Stannards Road, New York 19 for 200 meters.",
44+
"travel_type": "bus",
45+
"street_names": [
46+
"Stannards Road",
47+
"NY 19"
48+
]
49+
},
50+
{
51+
"travel_type": "bus",
52+
"travel_mode": "drive",
53+
"begin_shape_index": 5,
54+
"time": 0,
55+
"type": 5,
56+
"end_shape_index": 5,
57+
"instruction": "Your destination is on the right.",
58+
"length": 0,
59+
"verbal_transition_alert_instruction": "Your destination will be on the right.",
60+
"verbal_pre_transition_instruction": "Your destination is on the right."
61+
}
62+
]
63+
}],
64+
"status_message": "Found route between points",
65+
"status": 0
66+
}
67+
}
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
{
2+
"trip": {
3+
"language": "en-US",
4+
"summary": {
5+
"max_lon": -77.922508,
6+
"max_lat": 42.094261,
7+
"time": 68,
8+
"length": 0.532,
9+
"min_lat": 42.09182,
10+
"min_lon": -77.923752
11+
},
12+
"locations": [{
13+
"lon": -77.922523,
14+
"lat": 42.09235,
15+
"type": "break"
16+
},
17+
{
18+
"side_of_street": "right",
19+
"lon": -77.92382,
20+
"lat": 42.09182,
21+
"type": "break"
22+
},
23+
{
24+
"lon": -77.92276,
25+
"lat": 42.094261,
26+
"type": "break"
27+
}
28+
],
29+
"units": "kilometers",
30+
"legs": [{
31+
"shape": "{rbhoAvl_ssChH]V`GLtcAtU\\",
32+
"summary": {
33+
"max_lon": -77.922508,
34+
"max_lat": 42.09235,
35+
"time": 21,
36+
"length": 0.159,
37+
"min_lat": 42.09182,
38+
"min_lon": -77.923752
39+
},
40+
"maneuvers": [{
41+
"travel_type": "bus",
42+
"street_names": [
43+
"Stannards Road",
44+
"NY 19"
45+
],
46+
"verbal_pre_transition_instruction": "Drive south on Stannards Road, New York 19 for 20 meters. Then Turn right.",
47+
"instruction": "Drive south on Stannards Road/NY 19.",
48+
"end_shape_index": 1,
49+
"type": 1,
50+
"time": 0,
51+
"verbal_multi_cue": true,
52+
"length": 0.017,
53+
"begin_shape_index": 0,
54+
"travel_mode": "drive"
55+
},
56+
{
57+
"travel_type": "bus",
58+
"verbal_pre_transition_instruction": "Turn right.",
59+
"verbal_transition_alert_instruction": "Turn right.",
60+
"length": 0.102,
61+
"instruction": "Turn right.",
62+
"end_shape_index": 3,
63+
"type": 10,
64+
"time": 16,
65+
"verbal_post_transition_instruction": "Continue for 100 meters.",
66+
"begin_shape_index": 1,
67+
"travel_mode": "drive"
68+
},
69+
{
70+
"travel_type": "bus",
71+
"travel_mode": "drive",
72+
"verbal_pre_transition_instruction": "Turn left. Then Your destination will be on the right.",
73+
"verbal_transition_alert_instruction": "Turn left.",
74+
"length": 0.04,
75+
"instruction": "Turn left.",
76+
"end_shape_index": 4,
77+
"type": 15,
78+
"time": 5,
79+
"verbal_multi_cue": true,
80+
"verbal_post_transition_instruction": "Continue for 40 meters.",
81+
"begin_shape_index": 3
82+
},
83+
{
84+
"travel_type": "bus",
85+
"travel_mode": "drive",
86+
"begin_shape_index": 4,
87+
"time": 0,
88+
"type": 5,
89+
"end_shape_index": 4,
90+
"instruction": "Your destination is on the right.",
91+
"length": 0,
92+
"verbal_transition_alert_instruction": "Your destination will be on the right.",
93+
"verbal_pre_transition_instruction": "Your destination is on the right."
94+
}
95+
]
96+
},
97+
{
98+
"shape": "uqahoAnyassCuU]MucAWaGipA`HgNz@gIl@oNjAmE^",
99+
"summary": {
100+
"max_lon": -77.922508,
101+
"max_lat": 42.094261,
102+
"time": 47,
103+
"length": 0.373,
104+
"min_lat": 42.09182,
105+
"min_lon": -77.923752
106+
},
107+
"maneuvers": [{
108+
"travel_type": "bus",
109+
"travel_mode": "drive",
110+
"begin_shape_index": 0,
111+
"length": 0.04,
112+
"end_shape_index": 1,
113+
"instruction": "Drive north.",
114+
"verbal_pre_transition_instruction": "Drive north for 40 meters. Then Turn right.",
115+
"verbal_multi_cue": true,
116+
"type": 3,
117+
"time": 4
118+
},
119+
{
120+
"travel_type": "bus",
121+
"verbal_pre_transition_instruction": "Turn right.",
122+
"verbal_transition_alert_instruction": "Turn right.",
123+
"length": 0.102,
124+
"instruction": "Turn right.",
125+
"end_shape_index": 3,
126+
"type": 10,
127+
"time": 16,
128+
"verbal_post_transition_instruction": "Continue for 100 meters.",
129+
"begin_shape_index": 1,
130+
"travel_mode": "drive"
131+
},
132+
{
133+
"travel_type": "bus",
134+
"travel_mode": "drive",
135+
"verbal_pre_transition_instruction": "Turn left onto Stannards Road, New York 19.",
136+
"verbal_transition_alert_instruction": "Turn left onto Stannards Road.",
137+
"length": 0.23,
138+
"instruction": "Turn left onto Stannards Road/NY 19.",
139+
"end_shape_index": 8,
140+
"type": 15,
141+
"time": 27,
142+
"verbal_post_transition_instruction": "Continue for 200 meters.",
143+
"street_names": [
144+
"Stannards Road",
145+
"NY 19"
146+
],
147+
"begin_shape_index": 3
148+
},
149+
{
150+
"travel_type": "bus",
151+
"travel_mode": "drive",
152+
"begin_shape_index": 8,
153+
"time": 0,
154+
"type": 4,
155+
"end_shape_index": 8,
156+
"instruction": "You have arrived at your destination.",
157+
"length": 0,
158+
"verbal_transition_alert_instruction": "You will arrive at your destination.",
159+
"verbal_pre_transition_instruction": "You have arrived at your destination."
160+
}
161+
]
162+
}
163+
],
164+
"status_message": "Found route between points",
165+
"status": 0
166+
}
167+
}

0 commit comments

Comments
 (0)