App_test.res
1// test/App_test.res
2open VitestHelpers
3
4describe("Waypoint markers", () => {
5 testAsync("waypoints are extracted correctly from signal", async t => {
6 // Create a test waypoint
7 let testWaypoint: Waypoint.attributes = {
8 id: "wp1",
9 point: (85.324, 27.717),
10 from: None,
11 label: "Kathmandu",
12 gid: "kathmandu_gid",
13 country: "NP",
14 cons: [],
15 nonroutable: false,
16 error: None,
17 }
18
19 // Get signal and set waypoint
20 let signal = State.getOrCreateWaypointsSignal("test-doc")
21 signal->Preact.Signal.set([testWaypoint])
22
23 // Verify signal contains the waypoint
24 let waypoints = signal->Preact.Signal.get
25 t->expect(waypoints->Array.length)->toEqual(1)
26
27 switch waypoints->Array.get(0) {
28 | Some(wp) => {
29 t->expect(wp.id)->toEqual("wp1")
30 t->expect(wp.point)->toEqual((85.324, 27.717))
31 t->expect(wp.label)->toEqual("Kathmandu")
32 }
33 | None => t->expect("waypoint should exist")->toEqual("")
34 }
35 })
36
37 testAsync("empty waypoints signal returns empty array", async t => {
38 let signal = State.getOrCreateWaypointsSignal("empty-doc")
39 let waypoints = signal->Preact.Signal.get
40 t->expect(waypoints->Array.length)->toEqual(0)
41 })
42
43 testAsync("waypoints signal updates when set", async t => {
44 let signal = State.getOrCreateWaypointsSignal("update-doc")
45
46 // Start empty
47 t->expect(signal->Preact.Signal.get->Array.length)->toEqual(0)
48
49 // Add waypoints
50 let wp1: Waypoint.attributes = {
51 id: "wp1",
52 point: (85.0, 27.0),
53 from: None,
54 label: "Point 1",
55 gid: "gid1",
56 country: "NP",
57 cons: [],
58 nonroutable: false,
59 error: None,
60 }
61 let wp2: Waypoint.attributes = {
62 id: "wp2",
63 point: (83.0, 28.0),
64 from: None,
65 label: "Point 2",
66 gid: "gid2",
67 country: "NP",
68 cons: [],
69 nonroutable: false,
70 error: None,
71 }
72
73 signal->Preact.Signal.set([wp1, wp2])
74 t->expect(signal->Preact.Signal.get->Array.length)->toEqual(2)
75
76 // Update to single waypoint
77 signal->Preact.Signal.set([wp1])
78 t->expect(signal->Preact.Signal.get->Array.length)->toEqual(1)
79 })
80
81 testAsync("waypoint coordinates are in lon-lat order", async t => {
82 let testWaypoint: Waypoint.attributes = {
83 id: "coord-test",
84 point: (85.324, 27.717), // (longitude, latitude)
85 from: None,
86 label: "Test",
87 gid: "test_gid",
88 country: "NP",
89 cons: [],
90 nonroutable: false,
91 error: None,
92 }
93
94 let signal = State.getOrCreateWaypointsSignal("coord-doc")
95 signal->Preact.Signal.set([testWaypoint])
96
97 let waypoints = signal->Preact.Signal.get
98 switch waypoints->Array.get(0) {
99 | Some(wp) => {
100 let (lon, lat) = wp.point
101 t->expect(lon)->toEqual(85.324)
102 t->expect(lat)->toEqual(27.717)
103 }
104 | None => t->expect("waypoint should exist")->toEqual("")
105 }
106 })
107})