ContextMenu_test.res

 1open VitestHelpers
 2
 3describe("ContextMenu", () => {
 4  test("waypoint content decodes correctly from Waldo result", ctx => {
 5    let result: Waldo.result = {
 6      gid: 102191569,
 7      name: "Washington",
 8      placetype: "region",
 9      lon: -77.0369,
10      lat: 38.9072,
11      distance: 0.0,
12      bearing: 0.0,
13      region: ["Washington", "District of Columbia", "United States", "North America"],
14      country: "US",
15    }
16
17    // Construct content using the same pattern as ContextMenu.handleWaypoint
18    let waypointContent = Obj.magic({
19      "type": "waypoint",
20      "attrs": {
21        "id": "test-id",
22        "point": (result.lon, result.lat),
23        "label": result.name,
24        "country": result.country,
25        "gid": Int.toString(result.gid),
26        "from": None,
27        "cons": [],
28        "nonroutable": false,
29        "error": None,
30      },
31    })
32
33    // Verify round-trip: JSON -> Waypoint.attributes decodes correctly
34    switch Waypoint.fromJSON(Obj.magic(waypointContent)["attrs"]) {
35    | Ok(attrs) => {
36        ctx->expect(attrs.label)->toBe("Washington")
37        ctx->expect(attrs.country)->toBe("US")
38        ctx->expect(attrs.gid)->toBe("102191569")
39        ctx->expect(attrs.point)->toEqual((-77.0369, 38.9072))
40        ctx->expect(attrs.cons)->toEqual([])
41        ctx->expect(attrs.nonroutable)->toBe(false)
42        ctx->expect(attrs.error)->toEqual(None)
43        ctx->expect(attrs.from)->toEqual(None)
44      }
45    | Error(msg) => ctx->fail(`Waypoint decode failed: ${msg}`)
46    }
47  })
48})