| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- import assert from "node:assert/strict"
- const SRC = "../../../../../src/modules/cockpit/"
- const { fetchEventAnalysis, fetchHandlingEfficiency, fetchEventHistory } = await import(SRC + "services/warningResponseApi.js")
- const { fetchCurrentEvents } = await import(SRC + "services/eventApi.js")
- const { panelView } = await import(SRC + "domain/panelViews.js")
- const { SECTION_STATE, section } = await import(SRC + "domain/sectionState.js")
- const config = { dataSource: "real", api: { baseUrl: "http://test.invalid" } }
- const urls = []
- const respond = { ok: true, status: 200, json: async () => ({ code: 200, msg: "ok", data: {} }) }
- const fetchImpl = async (url) => { urls.push(String(url)); return respond }
- async function collect(fn, options) {
- urls.length = 0
- await fn({ ...options, config, fetchImpl })
- return [...urls]
- }
- // A. 预警分析:真收片区
- for (const [scope, expect] of [["south","district=0"],["north","district=1"],["taichang","district=2"],["unassigned","district=UNASSIGNED"]]) {
- const list = await collect(fetchEventAnalysis, { mode: "WARNING", rangeType: "LAST_7_DAYS", scope })
- const hit = list.filter((u) => u.includes(expect))
- console.log("analysis", scope, "requests:", list.length, "with", expect + ":", hit.length)
- assert.ok(hit.length >= 1, "analysis 缺 " + expect)
- }
- const allScope = await collect(fetchEventAnalysis, { mode: "WARNING", rangeType: "LAST_7_DAYS", scope: "all" })
- console.log("analysis all -> district present:", allScope.some((u) => u.includes("district=")))
- assert.equal(allScope.some((u) => u.includes("district=")), false, "all 不该带 district")
- // 多窗(90 天)每窗都要带
- const multi = await collect(fetchEventAnalysis, { mode: "WARNING", rangeType: "LAST_90_DAYS", scope: "south" })
- console.log("analysis 90d windows:", multi.length, "all district=0:", multi.every((u) => u.includes("district=0")))
- assert.ok(multi.length > 1, "90d 应是多窗")
- assert.ok(multi.every((u) => u.includes("district=0")), "多窗每窗都要带 district")
- // B. 不认片区的三个端点一个都不许带
- for (const [name, fn, opt] of [
- ["history", fetchEventHistory, { mode: "WARNING", rangeType: "LAST_7_DAYS", scope: "south" }],
- ["efficiency", fetchHandlingEfficiency, { mode: "WARNING", rangeType: "LAST_7_DAYS", scope: "south" }],
- ["current", fetchCurrentEvents, { mode: "WARNING", scope: "south" }],
- ]) {
- const list = await collect(fn, opt)
- const leak = list.filter((u) => u.includes("district="))
- console.log(name, "requests:", list.length, "leaking district:", leak.length)
- assert.equal(leak.length, 0, name + " 不该带 district: " + leak.join(","))
- }
- // D. 面板口径说明
- const empty = section(SECTION_STATE.EMPTY, { data: null })
- const { currentEventsView } = await import(SRC + "domain/eventList.js")
- const curView = currentEventsView(null, empty)
- console.log("currentEvents gap:", String(curView.gap).slice(0, 50) + "…")
- assert.ok(curView.gap && curView.gap.includes("当前范围"), "currentEvents 缺片区口径说明")
- const mustHave = ["historyAnalysis","responseEfficiency","monitoringOverview","operationOverview","operation","emergency","perceptionDevices","pipeNetwork","warningStudy","alarmDisposal"]
- const mustNot = ["archive","management","monitoringDistribution","eventAnalysis"]
- for (const id of mustHave) {
- const view = panelView(id, null, empty)
- assert.ok(view && view.gap && view.gap.includes("当前范围"), id + " 缺片区口径说明: " + (view && view.gap))
- console.log("gap ok:", id, "->", String(view.gap).slice(0, 40) + "…")
- }
- for (const id of mustNot) {
- const view = panelView(id, null, empty)
- assert.ok(!view || !String(view.gap || "").includes("不作用于本面板"), id + " 不该有片区缺口: " + (view && view.gap))
- console.log("no district gap ok:", id)
- }
- console.log("SELFTEST PASS")
|