Files
NODEDC_MISSION_CORE/apps/control-station/test/mapView.test.mjs
T

122 lines
3.4 KiB
JavaScript

import assert from "node:assert/strict";
import { readFile } from "node:fs/promises";
import { after, before, test } from "node:test";
import { createServer } from "vite";
let server;
let mapView;
before(async () => {
server = await createServer({
appType: "custom",
logLevel: "silent",
server: { middlewareMode: true },
});
mapView = await server.ssrLoadModule("/src/core/map/mapView.ts");
});
after(async () => {
await server?.close();
});
function serverDocument(overrides = {}) {
return {
schema_version: "missioncore.map-view/v1",
revision: 0,
view: {
camera: null,
visual_settings: {
atmosphere_enabled: true,
lighting_enabled: true,
monochrome_enabled: false,
terrain_exaggeration: 1,
buildings_maximum_screen_space_error: 16,
camera_animation_enabled: true,
},
map_height: 720,
inspector_open_sections: [],
cache_intent: {
enabled: true,
no_overwrite: true,
},
selected_subject_id: null,
layer_visibility: {
imagery: true,
terrain: true,
buildings: true,
grid: false,
targets: true,
},
},
...overrides,
};
}
test("map view starts without a fabricated global camera or subject", () => {
const document = mapView.defaultMapViewDocument();
assert.equal(document.view.camera, null);
assert.equal(document.view.selectedSubjectId, null);
assert.equal(document.view.cacheIntent.enabled, true);
assert.equal(document.view.cacheIntent.noOverwrite, true);
});
test("map view decodes and re-encodes the complete versioned contract", () => {
const decoded = mapView.decodeMapViewDocument(serverDocument({
revision: 3,
view: {
...serverDocument().view,
camera: {
longitude: 37.6176,
latitude: 55.7558,
height: 2500,
heading: 12,
pitch: -48,
roll: 0,
},
inspector_open_sections: ["camera"],
},
}));
const encoded = mapView.encodeMapViewPut(decoded);
assert.equal(decoded.revision, 3);
assert.equal(decoded.view.camera.longitude, 37.6176);
assert.equal(decoded.view.inspectorOpenSections[0], "camera");
assert.equal(encoded.view.camera.latitude, 55.7558);
assert.equal(encoded.view.cache_intent.no_overwrite, true);
assert.equal("schema_version" in encoded, false);
});
test("map view fails closed on credentials, runtime URLs and unbound selection", () => {
assert.throws(
() => mapView.decodeMapViewDocument(serverDocument({
view: {
...serverDocument().view,
token: "forbidden",
},
})),
);
assert.throws(
() => mapView.decodeMapViewDocument(serverDocument({
view: {
...serverDocument().view,
inspector_open_sections: ["selection"],
},
})),
/stable subject id|стабильный subject id/i,
);
});
test("map workspace keeps the canonical top actions without a bottom toolbar", async () => {
const source = await readFile(
new URL("../src/workspaces/map/WorldMapWorkspace.tsx", import.meta.url),
"utf8",
);
assert.doesNotMatch(source, /<Toolbar/);
assert.match(source, /className="mission-map__map-actions"/);
assert.match(source, /label="Настройки карты"/);
assert.match(source, /label="Слои карты"/);
assert.doesNotMatch(source, /label="Сбросить камеру"/);
});