// @vitest-environment node import fs from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; import { describe, expect, it } from "vitest"; const billingScreenDir = path.dirname(fileURLToPath(import.meta.url)); function source(file: string): string { return fs.readFileSync(path.join(billingScreenDir, file), "utf8"); } /** A ui id is either written on the element (`data-ui-id`) or handed to a shared screen primitive (`uiId`). */ function hasUiId(content: string, id: string): boolean { return content.includes(`data-ui-id="${id}"`) || content.includes(`uiId="${id}"`); } function uiIdIndex(content: string, id: string): number { const dataIndex = content.indexOf(`data-ui-id="${id}"`); const propIndex = content.indexOf(`uiId="${id}"`); return [dataIndex, propIndex].filter((index) => index >= 0).sort((a, b) => a - b)[0] ?? -1; } describe("AK-P20 billing interim screen contracts", () => { const screens = ["SubscriptionOverviewPage.tsx", "BillingUsagePage.tsx", "BillingPaymentPage.tsx"]; it.each(screens)("%s separates loading, error, empty, and ready states", (file) => { const content = source(file); expect(content).toContain('vm.status === "idle" || vm.status === "loading"'); expect(content).toContain('vm.status === "error"'); expect(content).toContain('vm.status === "empty"'); expect(content.includes('vm.status === "ready"') || hasUiId(content, "ui.billing.subscriptionOverview.page")).toBe(true); expect(content).toContain("actions.onRetry"); expect(content).toContain("billing:states.retry"); }); it.each(screens)("%s stays app-chrome-free and uses synchronized UI components", (file) => { const content = source(file); expect(content).toContain('from "~/ui/components/'); expect(content).not.toContain("DefaultPageLayout"); expect(content).not.toContain("EditPageLayout"); expect(content).not.toContain("Sidebar"); }); // The heading comes from the shared PageHeader (screens/shared/PageShell.tsx), which renders the single