import { test } from "node:test"; import assert from "node:assert/strict"; import { toAppHashUrl } from "../src/utils/appUrl"; /** 整页跳转地址单测:只锁「最终只有一个 hash」这条线上缺陷口径,不替代浏览器实测 */ test("办理页入口:resolve 出的 #/diagram 不再追加到当前 hash 之后", () => { const out = toAppHashUrl( "#/diagram?instanceId=107&mode=user", "https://base.yhxt.com.cn/flow-center/front/index.html#/task/339", ); assert.equal(out, "https://base.yhxt.com.cn/flow-center/front/index.html#/diagram?instanceId=107&mode=user"); assert.equal(out.split("#").length - 1, 1); }); test("参数原样保留:instanceId 与 mode 不因去 hash 而丢失", () => { const out = toAppHashUrl("#/diagram?instanceId=107&mode=dept", "https://h/flow-center/front/index.html#/task/339"); assert.match(out, /instanceId=107/); assert.match(out, /mode=dept/); }); test("无 hash 的入口地址:直接接上目标 hash", () => { assert.equal( toAppHashUrl("#/diagram?instanceId=1", "https://h/flow-center/front/index.html"), "https://h/flow-center/front/index.html#/diagram?instanceId=1", ); }); test("真实 query 保留在 hash 之前(部署带 ?v= 缓存位时不被吞)", () => { assert.equal( toAppHashUrl("#/diagram?instanceId=1", "https://h/index.html?v=9#/task/339"), "https://h/index.html?v=9#/diagram?instanceId=1", ); }); test("不带前导 # 的 resolve 结果同样归一,且不出现双 hash", () => { const out = toAppHashUrl("/diagram?instanceId=1", "https://h/index.html#/task/339"); assert.equal(out, "https://h/index.html#/diagram?instanceId=1"); }); test("查看大图:不再用 origin+BASE_URL 拼出 host 尾点地址", () => { // 旧写法 origin + "./" + "#/diagram?…" 会得到 https://base.yhxt.com.cn./#/diagram?… const legacy = `${"https://base.yhxt.com.cn"}${"./"}#/diagram?instanceId=1`; assert.match(legacy, /com\.cn\.\//); const fixed = toAppHashUrl("#/diagram?instanceId=1", "https://base.yhxt.com.cn/flow-center/front/index.html#/admin/instances"); assert.ok(!/\.cn\.\//.test(fixed), fixed); assert.equal(fixed, "https://base.yhxt.com.cn/flow-center/front/index.html#/diagram?instanceId=1"); });