36 lines
1.1 KiB
TypeScript
36 lines
1.1 KiB
TypeScript
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.351633, 6);
|
|
expect(bounds[0][1]).toBeCloseTo(30.810505, 6);
|
|
expect(bounds[1][0]).toBeCloseTo(121.772485, 6);
|
|
expect(bounds[1][1]).toBeCloseTo(31.007214, 6);
|
|
expect(options).toMatchObject({
|
|
duration: 600,
|
|
padding: { top: 0, right: 0, bottom: 0, left: 0 }
|
|
});
|
|
expect(options).not.toHaveProperty("zoom");
|
|
expect(options).not.toHaveProperty("maxZoom");
|
|
});
|
|
});
|