import assert from "node:assert"; import { describe, test, } from "node:test"; import { getNextClustersByPointClick } from "./getNextClustersByPointClick"; import type { TCluster } from "../../config/types/index"; const getBaseClusters = (): TCluster[] => ([ { id: "cluster-1", points: [ { id: "point-1", coords: [ 55.751244, 37.618423 ], state: { isActive: false, isDisabled: false, }, }, { id: "point-2", coords: [ 55.751444, 37.618923 ], state: { isActive: false, isDisabled: false, }, }, ], }, ]); describe("getNextClustersByPointClick", () => { test("activates first point on first click (single active mode)", () => { const { nextClusters, nextIsActive } = getNextClustersByPointClick({ clusters: getBaseClusters(), pointId: "point-1", maxActivePoints: 1, }); const [ point1, point2 ] = nextClusters[0].points; assert.strictEqual(nextIsActive, true); assert.strictEqual(point1.state?.isActive, true); assert.strictEqual(point2.state?.isActive, false); }); test("switches active point when clicking second point after first", () => { const firstClick = getNextClustersByPointClick({ clusters: getBaseClusters(), pointId: "point-1", maxActivePoints: 1, }).nextClusters; const secondClick = getNextClustersByPointClick({ clusters: firstClick, pointId: "point-2", maxActivePoints: 1, }); const [ point1, point2 ] = secondClick.nextClusters[0].points; assert.strictEqual(secondClick.nextIsActive, true); assert.strictEqual(point1.state?.isActive, false); assert.strictEqual(point2.state?.isActive, true); }); test("deactivates currently active point on second click", () => { const firstClick = getNextClustersByPointClick({ clusters: getBaseClusters(), pointId: "point-1", maxActivePoints: 1, }).nextClusters; const secondClick = getNextClustersByPointClick({ clusters: firstClick, pointId: "point-1", maxActivePoints: 1, }); const [ point1, point2 ] = secondClick.nextClusters[0].points; assert.strictEqual(secondClick.nextIsActive, false); assert.strictEqual(point1.state?.isActive, false); assert.strictEqual(point2.state?.isActive, false); }); });