52 lines
2.2 KiB
TypeScript
52 lines
2.2 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import { readFileSync } from "node:fs";
|
|
import test from "node:test";
|
|
|
|
const overviewSource = readFileSync(
|
|
new URL("../src/panels/plaza/PlazaOverview.tsx", import.meta.url),
|
|
"utf8",
|
|
);
|
|
const mapSource = readFileSync(
|
|
new URL("../src/panels/plaza/SuperAgentPanel.tsx", import.meta.url),
|
|
"utf8",
|
|
);
|
|
const projectLandingSource = readFileSync(
|
|
new URL("../src/ProjectLanding.tsx", import.meta.url),
|
|
"utf8",
|
|
);
|
|
const regionsSource = readFileSync(
|
|
new URL("../src/spatialMapRegions.ts", import.meta.url),
|
|
"utf8",
|
|
);
|
|
|
|
test("every map-enabled project uses the single KnowledgeMap template", () => {
|
|
assert.match(overviewSource, /isKnowledgeMapProject && \(/);
|
|
assert.match(overviewSource, /<KnowledgeMap/);
|
|
assert.doesNotMatch(overviewSource, /<SuperAgentPanel/);
|
|
});
|
|
|
|
test("the shared map preserves approved logos and counts only current-region graph POIs", () => {
|
|
assert.match(mapSource, /MAP_SHORTCUT_CATEGORIES = \["美食", "酒店", "景点", "交通设施"\]/);
|
|
assert.match(mapSource, /MAP_SHORTCUT_CATEGORIES\.map/);
|
|
assert.match(mapSource, /省域馆藏汇总/);
|
|
assert.match(mapSource, /regionPois\.length\.toLocaleString\(\)/);
|
|
assert.doesNotMatch(mapSource, /cov\?\.total/);
|
|
assert.match(mapSource, /regionLevel === "province"/);
|
|
assert.match(mapSource, /poiLoading \? "加载中…" : poiError \? "—"/);
|
|
assert.match(mapSource, /当前已入藏知识 \/ POI 条目/);
|
|
});
|
|
|
|
test("switching a graph version remounts the map and clears stale POIs", () => {
|
|
assert.match(overviewSource, /key=\{.*projectContext\.projectId.*projectContext\.graphName.*spatialMap\.region_adcode/);
|
|
assert.match(mapSource, /setPoiError\(""\);\s+setMapPois\(\[\]\);\s+setSelectedCategories\(\[\]\)/);
|
|
assert.match(overviewSource, /if \(sequence !== fetchSequence\.current\) return/);
|
|
});
|
|
|
|
test("map-enabled project creation requires an explicit administrative region", () => {
|
|
assert.match(projectLandingSource, /name="map_region_adcode"/);
|
|
assert.match(projectLandingSource, /请选择地图区域/);
|
|
assert.match(projectLandingSource, /spatialMapConfigForRegion/);
|
|
assert.match(regionsSource, /adcode: "520100", name: "贵阳市"/);
|
|
assert.match(regionsSource, /adcode: "522722", name: "荔波县"/);
|
|
});
|