79 lines
3.1 KiB
JavaScript
79 lines
3.1 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import { readFile } from "node:fs/promises";
|
|
import test from "node:test";
|
|
import { deriveBetaOnboarding } from "../app/dashboard/onboarding.ts";
|
|
|
|
const baseEntitlement = {
|
|
mode: "none",
|
|
publicBetaState: "gated",
|
|
unlimited: false,
|
|
availableSlots: 0,
|
|
};
|
|
|
|
test("routes every free-beta access state to one concrete next action", () => {
|
|
assert.deepEqual(
|
|
deriveBetaOnboarding({ entitlement: baseEntitlement, hasPendingRequest: false }),
|
|
{
|
|
state: "request_needed",
|
|
pairingAccessState: "gated",
|
|
primaryHref: "/dashboard/billing",
|
|
primaryLabel: "申请免费闭测",
|
|
tone: "warn",
|
|
title: "公开接入尚未开放",
|
|
detail: "安全门禁仍在核对,可以先申请小范围免费闭测。",
|
|
},
|
|
);
|
|
|
|
const pending = deriveBetaOnboarding({ entitlement: baseEntitlement, hasPendingRequest: true });
|
|
assert.equal(pending.state, "request_pending");
|
|
assert.equal(pending.pairingAccessState, "request_pending");
|
|
assert.equal(pending.primaryLabel, "查看申请进度");
|
|
|
|
const inactive = deriveBetaOnboarding({
|
|
entitlement: { ...baseEntitlement, publicBetaState: "inactive" },
|
|
hasPendingRequest: false,
|
|
});
|
|
assert.equal(inactive.state, "request_needed");
|
|
assert.equal(inactive.pairingAccessState, "inactive");
|
|
assert.match(inactive.detail, /不会绑定支付方式/);
|
|
|
|
const invited = deriveBetaOnboarding({
|
|
entitlement: { ...baseEntitlement, mode: "grant", availableSlots: 2 },
|
|
hasPendingRequest: false,
|
|
});
|
|
assert.equal(invited.state, "ready");
|
|
assert.equal(invited.primaryHref, "/dashboard/hosts/new");
|
|
assert.match(invited.detail, /2 台/);
|
|
|
|
const unlimited = deriveBetaOnboarding({
|
|
entitlement: { ...baseEntitlement, mode: "public_beta", publicBetaState: "open", unlimited: true, availableSlots: null },
|
|
hasPendingRequest: false,
|
|
});
|
|
assert.equal(unlimited.state, "ready");
|
|
assert.match(unlimited.detail, /不按主机槽位限额/);
|
|
|
|
const full = deriveBetaOnboarding({
|
|
entitlement: { ...baseEntitlement, mode: "grant", availableSlots: 0 },
|
|
hasPendingRequest: false,
|
|
});
|
|
assert.equal(full.state, "full");
|
|
assert.equal(full.pairingAccessState, "full");
|
|
assert.equal(full.primaryHref, "/dashboard/hosts");
|
|
});
|
|
|
|
test("connects dashboard and blocked pairing surfaces to the derived beta journey", async () => {
|
|
const [dashboard, newHostPage, pairingForm] = await Promise.all([
|
|
readFile(new URL("../app/dashboard/page.tsx", import.meta.url), "utf8"),
|
|
readFile(new URL("../app/dashboard/hosts/new/page.tsx", import.meta.url), "utf8"),
|
|
readFile(new URL("../app/dashboard/hosts/new/PairingForm.tsx", import.meta.url), "utf8"),
|
|
]);
|
|
assert.match(dashboard, /deriveBetaOnboarding/);
|
|
assert.match(dashboard, /href=\{onboarding\.primaryHref\}/);
|
|
assert.match(dashboard, /获得免费测试资格/);
|
|
assert.match(newHostPage, /hasPendingRequest/);
|
|
assert.match(newHostPage, /onboarding\.pairingAccessState/);
|
|
assert.match(pairingForm, /request_pending/);
|
|
assert.match(pairingForm, /申请免费闭测/);
|
|
assert.match(pairingForm, /管理主机和配对/);
|
|
});
|