import type { Map as MapLibreMap } from "maplibre-gl"; import { describe, expect, it, vi } from "vitest"; import { fitNetworkBounds } from "./camera"; import { WATER_NETWORK_GLOBAL_VIEW } from "./sources"; describe("fitNetworkBounds", () => { it("fits the global WebMercator bbox through MapLibre lng/lat bounds", () => { const fitBounds = vi.fn(); const map = { fitBounds, getCanvas: () => ({ clientWidth: 1280, clientHeight: 720, width: 1280, height: 720 }) } as unknown as MapLibreMap; fitNetworkBounds(map, WATER_NETWORK_GLOBAL_VIEW); expect(fitBounds).toHaveBeenCalledTimes(1); const [bounds, options] = fitBounds.mock.calls[0] ?? []; expect(bounds[0][0]).toBeCloseTo(121.735034, 6); expect(bounds[0][1]).toBeCloseTo(30.846365, 6); expect(bounds[1][0]).toBeCloseTo(121.970518, 6); expect(bounds[1][1]).toBeCloseTo(30.994738, 6); expect(options).toMatchObject({ duration: 600, maxZoom: 12, padding: { top: 48, right: 48, bottom: 48, left: 48 } }); expect(options).not.toHaveProperty("zoom"); }); });