67 lines
1.6 KiB
JavaScript
67 lines
1.6 KiB
JavaScript
import assert from "node:assert/strict"
|
|
import test from "node:test"
|
|
|
|
import {
|
|
mapSizeChanged,
|
|
shouldApplyInitialViewport,
|
|
viewportMatchesBounds
|
|
} from "./map_viewport_sync.mjs"
|
|
|
|
const bounds = ({west, south, east, north}) => ({
|
|
getWest: () => west,
|
|
getSouth: () => south,
|
|
getEast: () => east,
|
|
getNorth: () => north
|
|
})
|
|
|
|
test("a server acknowledgement rounded to six decimals does not move the map again", () => {
|
|
const viewport = {
|
|
west: 30.543427,
|
|
south: 50.42413,
|
|
east: 30.551643,
|
|
north: 50.429139
|
|
}
|
|
|
|
assert.equal(
|
|
viewportMatchesBounds(
|
|
viewport,
|
|
bounds({
|
|
west: 30.543426946507708,
|
|
south: 50.42413000000005,
|
|
east: 30.55164305349291,
|
|
north: 50.42913900000016
|
|
})
|
|
),
|
|
true
|
|
)
|
|
})
|
|
|
|
test("a materially different saved viewport still repositions the map", () => {
|
|
const viewport = {west: 30.5, south: 50.4, east: 30.6, north: 50.5}
|
|
|
|
assert.equal(
|
|
viewportMatchesBounds(
|
|
viewport,
|
|
bounds({west: 30.51, south: 50.41, east: 30.61, north: 50.51})
|
|
),
|
|
false
|
|
)
|
|
})
|
|
|
|
test("map resize is requested only when the rendered dimensions change", () => {
|
|
assert.equal(mapSizeChanged(null, {width: 767, height: 734}), true)
|
|
assert.equal(
|
|
mapSizeChanged({width: 767, height: 734}, {width: 767, height: 734}),
|
|
false
|
|
)
|
|
assert.equal(
|
|
mapSizeChanged({width: 767, height: 734}, {width: 768, height: 734}),
|
|
true
|
|
)
|
|
})
|
|
|
|
test("server viewport is never reapplied after the user camera is initialized", () => {
|
|
assert.equal(shouldApplyInitialViewport(false), true)
|
|
assert.equal(shouldApplyInitialViewport(true), false)
|
|
})
|