69 lines
3.2 KiB
TypeScript
69 lines
3.2 KiB
TypeScript
// @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 <h1>.
|
|
it.each(screens)("%s exposes a semantic main heading", (file) => {
|
|
const content = source(file);
|
|
expect(content).toContain("<PageHeader");
|
|
expect(content).toContain("shared/PageShell");
|
|
});
|
|
|
|
it("exposes stable selectors for customer-facing billing actions", () => {
|
|
const subscription = source("SubscriptionOverviewPage.tsx");
|
|
const payment = source("BillingPaymentPage.tsx");
|
|
expect(subscription).toContain('data-ui-id="ui.billing.subscriptionOverview.contact"');
|
|
expect(subscription).toContain("actions.onOpenContact");
|
|
expect(uiIdIndex(subscription, "ui.billing.subscriptionOverview.contact")).toBeLessThan(
|
|
uiIdIndex(subscription, "ui.billing.subscriptionOverview.page")
|
|
);
|
|
expect(subscription).not.toContain("<a ");
|
|
expect(subscription).toContain('data-ui-id="ui.billing.subscriptionOverview.cancel"');
|
|
expect(subscription).toContain('data-ui-id="ui.billing.subscriptionOverview.cancelConfirm"');
|
|
expect(subscription).toContain('aria-label={t("billing:subscriptionOverview.cancel.title")}');
|
|
expect(payment).toContain('data-ui-id="ui.billing.payment.invoiceDownload"');
|
|
expect(payment).toContain("actions.onDownloadInvoice");
|
|
expect(payment).not.toContain("<a ");
|
|
});
|
|
});
|