import assert from "node:assert/strict" import { createPinia, setActivePinia } from "pinia" const SRC = "../../../../../src/modules/cockpit/" setActivePinia(createPinia()) const { useEventStore } = await import(SRC + "stores/eventStore.js") const config = { dataSource: "real", api: { baseUrl: "http://test.invalid" } } let urls = [] /** 回显请求里的 page,让分页视图与请求一致(否则会被"越界夹回"逻辑拉回第 1 页)。 */ const fetchImpl = async (url) => { urls.push(String(url)) const page = Number((String(url).match(/[?&]page=(\d+)/) || [])[1] || 1) return { ok: true, status: 200, json: async () => ({ code: 200, msg: "ok", data: { pagination: { page, pageSize: 10, total: 30, totalPages: 3 } } }) } } const store = useEventStore() store.configure({ config, fetchImpl }) await store.loadPanels({ mode: "WARNING", industry: "all", scope: "all" }) assert.equal(store.currentPage, 1) await store.setCurrentPage(2) console.log("after setCurrentPage(2), currentPage =", store.currentPage) assert.equal(store.currentPage, 2) urls = [] await store.loadPanels({ scope: "south" }) console.log("after scope change, pages =", store.currentPage, store.historyPage, store.workOrderPage) assert.equal(store.currentPage, 1, "换片区必须回第 1 页") assert.equal(store.historyPage, 1) assert.equal(store.workOrderPage, 1) const currentReq = urls.find((u) => u.includes("/events/current")) const analysisReq = urls.find((u) => u.includes("/multidimensional-analysis")) console.log("current url:", currentReq) console.log("analysis url:", analysisReq) assert.ok(currentReq && /[?&]page=1(&|$)/.test(currentReq), "当前事件应回第 1 页") assert.ok(currentReq && !currentReq.includes("district="), "当前事件不该带 district") assert.ok(analysisReq && analysisReq.includes("district=0"), "预警分析应带 district=0") await store.setCurrentPage(2) assert.equal(store.currentPage, 2) urls = [] await store.loadPanels({}) console.log("after same-condition reload, currentPage =", store.currentPage) assert.equal(store.currentPage, 2, "同条件重取不复位页码") console.log("STORE TEST PASS")