Files
HiveGrid-Wireframes/03 Quellen und Referenzen/hivegrid-cloud/apps/web/app/components/screens/billing/va-p24a-interim.visual.test.tsx
T

325 lines
19 KiB
TypeScript

// @vitest-environment jsdom
import "@testing-library/jest-dom/vitest";
import React from "react";
import { fireEvent, render, screen, waitFor, within } from "@testing-library/react";
import { describe, expect, it, vi } from "vitest";
import { assertNoA11yViolations } from "~/utils/test/a11y";
import { VaP24aInterimVisualFixture } from "./va-p24a-interim.visual-fixture";
globalThis.ResizeObserver =
globalThis.ResizeObserver ??
class ResizeObserver {
observe() {}
unobserve() {}
disconnect() {}
};
vi.mock("react-i18next", () => ({
useTranslation: () => ({
t: (key: string, values?: Record<string, unknown>) => (values ? `${key}:${Object.values(values).join("/")}` : key),
i18n: { language: "de" },
}),
}));
vi.mock("~/locale/format", () => ({
useLocaleFormatters: () => ({
number: (value: number) => String(value),
currency: (value: number, currency: string) => `${value.toFixed(2)} ${currency}`,
currencyFromCents: (value: number, currency: string) => `${(value / 100).toFixed(2)} ${currency}`,
date: (value: string) => value,
dateTime: (value: string) => value,
}),
}));
async function advanceActivationToPayment(): Promise<void> {
fireEvent.click(screen.getByRole("button", { name: "billing:selfServiceSubscription.activation.wizard.next" }));
await waitFor(() => expect(document.querySelector('[data-ui-id="ui.billing.activation.livePrice"]')).toBeVisible());
await waitFor(() => expect(screen.getByRole("button", { name: "billing:selfServiceSubscription.activation.wizard.next" })).toBeEnabled());
fireEvent.click(screen.getByRole("button", { name: "billing:selfServiceSubscription.activation.wizard.next" }));
await waitFor(() => expect(document.querySelector('[data-ui-id="ui.billing.activation.storage"]')).toBeVisible());
fireEvent.click(screen.getByRole("button", { name: "billing:selfServiceSubscription.activation.wizard.next" }));
fireEvent.click(screen.getByRole("radio", { name: /activation\.wizard\.email\.no/u }));
fireEvent.click(screen.getByRole("button", { name: "billing:selfServiceSubscription.activation.wizard.next" }));
await waitFor(() => expect(document.querySelector('[data-ui-id="ui.billing.activation.payment"]')).toBeVisible());
}
describe("VA-P24a interim visual baseline", () => {
it("opens active billing with a calm overview and keeps plan editing one explicit action away", () => {
const { container } = render(
<main data-ui-id="ui.vaP24a.interim.visualBaseline">
<VaP24aInterimVisualFixture />
</main>
);
expect(container.querySelectorAll("[data-ui-id='ui.billing.selfServiceSubscription.page']")).toHaveLength(1);
expect(container.querySelectorAll("[data-ui-id='ui.billing.selfServiceSubscription.current']")).toHaveLength(1);
expect(container.querySelectorAll("[data-ui-id='ui.billing.selfServiceSubscription.usage']")).toHaveLength(1);
expect(container.querySelectorAll("[data-ui-id='ui.billing.selfServiceSubscription.builder']")).toHaveLength(0);
expect(container.querySelectorAll("[data-ui-id='ui.billing.selfServiceSubscription.emailMarketing']")).toHaveLength(0);
const stableMarkup = container.innerHTML.replace(/<svg\b[^>]*>[\s\S]*?<\/svg>/gu, '<svg data-visual-icon="true"></svg>');
expect(stableMarkup).toMatchSnapshot();
fireEvent.click(screen.getByRole("button", { name: "billing:selfServiceSubscription.management.overview.plan.action" }));
expect(container.querySelectorAll("[data-ui-id='ui.billing.selfServiceSubscription.builder']")).toHaveLength(1);
expect(screen.getByRole("button", { name: "billing:selfServiceSubscription.management.back" })).toBeVisible();
expect(container.querySelectorAll("[data-ui-id='ui.billing.selfServiceSubscription.officeSeats']")).toHaveLength(1);
expect(container.querySelectorAll("[data-ui-id='ui.billing.selfServiceSubscription.fieldSeats']")).toHaveLength(1);
expect(container.querySelectorAll("[data-ui-id='ui.billing.selfServiceSubscription.preview']")).toHaveLength(1);
fireEvent.click(screen.getByRole("button", { name: "billing:selfServiceSubscription.management.back" }));
expect(container.querySelectorAll("[data-ui-id='ui.billing.selfServiceSubscription.current']")).toHaveLength(1);
assertNoA11yViolations(container);
});
it("renders first activation as a focused locked-workspace checkout without app billing clutter", async () => {
const onCheckout = vi.fn(() => new Promise<void>(() => undefined));
const { container } = render(<VaP24aInterimVisualFixture activationMode onCheckout={onCheckout} />);
expect(container.querySelector('[data-ui-id="ui.billing.activation.page"]')).toBeInTheDocument();
expect(container.querySelector('[data-ui-id="ui.billing.activation.locked"]')).toBeInTheDocument();
expect(container.querySelector('[data-ui-id="ui.billing.selfServiceSubscription.usage"]')).not.toBeInTheDocument();
expect(container.querySelector('[data-ui-id="ui.billing.selfServiceSubscription.emailMarketing"]')).not.toBeInTheDocument();
expect(container.querySelector('[data-ui-id="ui.billing.selfServiceSubscription.current"]')).not.toBeInTheDocument();
expect(container.querySelector('[data-ui-id="ui.billing.activation.team"]')).toBeVisible();
expect(screen.getByRole("slider", { name: "billing:selfServiceSubscription.seats.officeLabel" })).toBeVisible();
expect(screen.getByRole("spinbutton", { name: "billing:selfServiceSubscription.seats.officeLabel" })).toBeVisible();
await advanceActivationToPayment();
expect(screen.getByText("billing:selfServiceSubscription.preview.recurringNetTotal")).toBeVisible();
expect(screen.getByText("billing:selfServiceSubscription.preview.recurringGrossTotal")).toBeVisible();
expect(screen.getByText(/billing:selfServiceSubscription\.activation\.trial\.title/u)).toBeVisible();
expect(screen.getByRole("radio", { name: /iDEAL/u })).toBeChecked();
fireEvent.click(screen.getByRole("button", { name: "billing:selfServiceSubscription.checkout.action" }));
expect(onCheckout).toHaveBeenCalledTimes(1);
assertNoA11yViolations(container);
});
it("does not restart an activation preview when the route recreates its actions object", async () => {
const onPreview = vi.fn(async () => {
throw new Error("expected single probe");
});
const { rerender } = render(<VaP24aInterimVisualFixture activationMode onPreview={onPreview} />);
fireEvent.click(screen.getByRole("button", { name: "billing:selfServiceSubscription.activation.wizard.next" }));
await waitFor(() => expect(onPreview).toHaveBeenCalledTimes(1));
rerender(<VaP24aInterimVisualFixture activationMode onPreview={onPreview} />);
await new Promise((resolve) => window.setTimeout(resolve, 400));
expect(onPreview).toHaveBeenCalledTimes(1);
});
it("offers an explicit retry when live plan advice fails", async () => {
const onPlanAdvice = vi
.fn()
.mockRejectedValueOnce(new Error("advisor unavailable"))
.mockResolvedValueOnce({
plans: [{ planId: "plan-core", priceId: "price-core-monthly", amountCents: 19_900, currency: "EUR", billingPeriod: 3, recommended: true }],
selectedPriceId: "price-core-monthly",
recommendedPriceId: "price-core-monthly",
officeSeatQuantity: 3,
fieldSeatQuantity: 5,
});
render(<VaP24aInterimVisualFixture activationMode onPlanAdvice={onPlanAdvice} />);
fireEvent.change(screen.getByRole("spinbutton", { name: "billing:selfServiceSubscription.seats.officeLabel" }), { target: { value: "3" } });
const retry = await screen.findByRole("button", { name: "billing:states.retry" });
fireEvent.click(retry);
await waitFor(() => expect(onPlanAdvice).toHaveBeenCalledTimes(2));
await waitFor(() => expect(screen.queryByRole("button", { name: "billing:states.retry" })).not.toBeInTheDocument());
});
it("shows a recoverable empty state when activation has no purchasable catalog", () => {
const onRetry = vi.fn();
const { container } = render(<VaP24aInterimVisualFixture activationMode emptyCatalog onRetry={onRetry} />);
expect(screen.getByText("billing:selfServiceSubscription.catalog.empty.title")).toBeVisible();
expect(screen.getByText("billing:selfServiceSubscription.catalog.empty.description")).toBeVisible();
fireEvent.click(screen.getByRole("button", { name: "billing:states.retry" }));
expect(onRetry).toHaveBeenCalledTimes(1);
assertNoA11yViolations(container);
});
it("explains the license-grown workspace pool before offering fair fixed storage", async () => {
const { container } = render(<VaP24aInterimVisualFixture activationMode />);
fireEvent.click(screen.getByRole("button", { name: "billing:selfServiceSubscription.activation.wizard.next" }));
await waitFor(() => expect(document.querySelector('[data-ui-id="ui.billing.activation.livePrice"]')).toBeVisible());
await waitFor(() => expect(screen.getByRole("button", { name: "billing:selfServiceSubscription.activation.wizard.next" })).toBeEnabled());
fireEvent.click(screen.getByRole("button", { name: "billing:selfServiceSubscription.activation.wizard.next" }));
await waitFor(() => expect(document.querySelector('[data-ui-id="ui.billing.activation.storage"]')).toBeVisible());
expect(screen.getByText("billing:selfServiceSubscription.activation.wizard.storage.includedTitle:100")).toBeVisible();
expect(screen.getByText("billing:selfServiceSubscription.activation.wizard.storage.poolDescription:100/0/0/10")).toBeVisible();
expect(screen.getByText(/6\.99 EUR/u)).toBeVisible();
expect(screen.getByText(/^\+12\.99 EUR/u)).toBeVisible();
expect(screen.getByText(/60\.99 EUR/u)).toBeVisible();
expect(screen.queryByText(/1\.25 EUR/u)).not.toBeInTheDocument();
assertNoA11yViolations(container);
});
it("states explicitly when the selected activation price has no trial", async () => {
render(<VaP24aInterimVisualFixture activationMode activationTrialDays={0} />);
await advanceActivationToPayment();
expect(screen.getByText(/billing:selfServiceSubscription\.activation\.immediate\.title/u)).toBeVisible();
expect(screen.getByText("billing:selfServiceSubscription.activation.immediate.description:0")).toBeVisible();
expect(screen.queryByText(/billing:selfServiceSubscription\.activation\.trial\.title/u)).not.toBeInTheDocument();
});
it("explains the high-value card requirement and blocks checkout when Mollie has no card", async () => {
const { container } = render(<VaP24aInterimVisualFixture activationMode previewPaymentMethods={{ status: "required_card_unavailable", methods: [] }} />);
await advanceActivationToPayment();
expect(await screen.findByText("billing:selfServiceSubscription.paymentMethods.cardUnavailableTitle")).toBeVisible();
expect(screen.getByRole("button", { name: "billing:selfServiceSubscription.checkout.action" })).toBeDisabled();
assertNoA11yViolations(container);
});
it("labels a card-only high-value checkout before redirecting to Mollie", async () => {
render(<VaP24aInterimVisualFixture activationMode previewPaymentMethods={{ status: "ready", methods: [{ id: "creditcard", label: "Kreditkarte" }] }} />);
await advanceActivationToPayment();
expect(await screen.findByText("billing:selfServiceSubscription.paymentMethods.cardDescription")).toBeVisible();
expect(screen.getByRole("radio", { name: /Kreditkarte/u })).toBeChecked();
});
it("classifies a monthly-to-yearly selection as a period-end billing change", async () => {
render(<VaP24aInterimVisualFixture />);
fireEvent.click(screen.getByRole("button", { name: "billing:selfServiceSubscription.management.overview.plan.action" }));
fireEvent.click(screen.getByRole("radio", { name: /290\.00 EUR/u }));
fireEvent.click(screen.getByRole("button", { name: "billing:selfServiceSubscription.preview.action" }));
await waitFor(() => {
expect(screen.getByText("billing:selfServiceSubscription.preview.changeKind.billing_period_change")).toBeInTheDocument();
});
});
it("names the selection groups and prevents duplicate checkout submissions while loading", async () => {
const onCheckout = vi.fn(() => new Promise<void>(() => undefined));
render(<VaP24aInterimVisualFixture onCheckout={onCheckout} />);
fireEvent.click(screen.getByRole("button", { name: "billing:selfServiceSubscription.management.overview.plan.action" }));
expect(screen.getByRole("radiogroup", { name: "billing:selfServiceSubscription.catalog.title" })).toBeVisible();
expect(screen.getByRole("radiogroup", { name: "billing:selfServiceSubscription.price.title" })).toBeVisible();
expect(screen.getByRole("spinbutton", { name: "billing:selfServiceSubscription.seats.officeLabel" })).toBeVisible();
expect(screen.getByRole("spinbutton", { name: "billing:selfServiceSubscription.seats.fieldLabel" })).toBeVisible();
fireEvent.click(screen.getByRole("button", { name: "billing:selfServiceSubscription.preview.action" }));
expect(await screen.findByRole("radiogroup", { name: "billing:selfServiceSubscription.paymentMethods.title" })).toBeVisible();
expect(screen.getByRole("radio", { name: /iDEAL/u })).toBeChecked();
const checkout = await screen.findByRole("button", { name: "billing:selfServiceSubscription.checkout.action" });
fireEvent.click(checkout);
fireEvent.click(checkout);
expect(onCheckout).toHaveBeenCalledTimes(1);
expect(onCheckout).toHaveBeenCalledWith(expect.any(Object), "ideal", expect.stringMatching(/^[0-9a-f-]{36}$/u));
expect(checkout).toBeDisabled();
});
it("releases the checkout lock when a handled action error returns without redirecting", async () => {
const onCheckout = vi.fn().mockResolvedValue(undefined);
render(<VaP24aInterimVisualFixture onCheckout={onCheckout} />);
fireEvent.click(screen.getByRole("button", { name: "billing:selfServiceSubscription.management.overview.plan.action" }));
fireEvent.click(screen.getByRole("button", { name: "billing:selfServiceSubscription.preview.action" }));
const checkout = await screen.findByRole("button", { name: "billing:selfServiceSubscription.checkout.action" });
fireEvent.click(checkout);
await waitFor(() => expect(checkout).toBeEnabled());
fireEvent.click(checkout);
await waitFor(() => expect(onCheckout).toHaveBeenCalledTimes(2));
expect(onCheckout.mock.calls[1]?.[2]).toBe(onCheckout.mock.calls[0]?.[2]);
});
it("previews an email tier switch, keeps the current tier visible, and pins the chosen method", async () => {
const onEmailMarketingCheckout = vi.fn(() => new Promise<void>(() => undefined));
const { container } = render(<VaP24aInterimVisualFixture onEmailMarketingCheckout={onEmailMarketingCheckout} />);
fireEvent.click(screen.getByRole("button", { name: "billing:selfServiceSubscription.management.overview.addons.action" }));
expect(screen.getByText("billing:selfServiceSubscription.emailMarketing.active.description")).toBeVisible();
expect(container.querySelector('[data-ui-id="ui.billing.selfServiceSubscription.customerPortal"]')).toBeVisible();
fireEvent.click(screen.getByRole("button", { name: "billing:selfServiceSubscription.emailMarketing.switch" }));
const dialog = await screen.findByRole("dialog", { name: "billing:selfServiceSubscription.emailMarketing.dialog.title" });
expect(dialog).toBeVisible();
expect(screen.getByText("billing:selfServiceSubscription.emailMarketing.dialog.replacement.description")).toBeVisible();
expect(screen.getByRole("radio", { name: /iDEAL/u })).toBeChecked();
const checkout = screen.getByRole("button", { name: "billing:selfServiceSubscription.emailMarketing.dialog.checkout" });
fireEvent.click(checkout);
fireEvent.click(checkout);
expect(onEmailMarketingCheckout).toHaveBeenCalledTimes(1);
expect(onEmailMarketingCheckout).toHaveBeenCalledWith(expect.objectContaining({ code: "email_marketing_m" }), "ideal");
expect(checkout).toBeDisabled();
assertNoA11yViolations(container);
});
it("releases the email package checkout lock when the action returns an inline error", async () => {
const onEmailMarketingCheckout = vi.fn().mockResolvedValue(undefined);
render(<VaP24aInterimVisualFixture onEmailMarketingCheckout={onEmailMarketingCheckout} />);
fireEvent.click(screen.getByRole("button", { name: "billing:selfServiceSubscription.management.overview.addons.action" }));
fireEvent.click(screen.getByRole("button", { name: "billing:selfServiceSubscription.emailMarketing.switch" }));
const checkout = await screen.findByRole("button", { name: "billing:selfServiceSubscription.emailMarketing.dialog.checkout" });
fireEvent.click(checkout);
await waitFor(() => expect(checkout).toBeEnabled());
expect(onEmailMarketingCheckout).toHaveBeenCalledTimes(1);
});
it("opens the validated post-activation email package directly as a separate checkout", async () => {
render(<VaP24aInterimVisualFixture initialEmailMarketingAddOnCode="email_marketing_m" />);
const dialog = await screen.findByRole("dialog", { name: "billing:selfServiceSubscription.emailMarketing.dialog.title" });
expect(dialog).toBeVisible();
expect(within(dialog).getByText("billing:selfServiceSubscription.emailMarketing.fixture.m")).toBeVisible();
expect(screen.getByRole("radio", { name: /iDEAL/u })).toBeChecked();
});
it("keeps plan and storage edits isolated and requires a real storage change", async () => {
render(<VaP24aInterimVisualFixture canonicalPlans />);
fireEvent.click(screen.getByRole("button", { name: "billing:selfServiceSubscription.management.overview.plan.action" }));
const planOptions = screen.getByRole("radiogroup", { name: "billing:selfServiceSubscription.catalog.title" });
fireEvent.click(planOptions.querySelectorAll('[role="radio"]')[1]!);
fireEvent.click(screen.getByRole("button", { name: "billing:selfServiceSubscription.management.back" }));
fireEvent.click(screen.getByRole("button", { name: "billing:selfServiceSubscription.management.overview.plan.action" }));
const resetPlanOptions = screen.getByRole("radiogroup", { name: "billing:selfServiceSubscription.catalog.title" });
expect(within(resetPlanOptions).getAllByRole("radio")[0]).toBeChecked();
fireEvent.click(screen.getByRole("button", { name: "billing:selfServiceSubscription.management.back" }));
fireEvent.click(screen.getByRole("button", { name: "billing:selfServiceSubscription.management.overview.addons.action" }));
const storagePreview = screen.getByRole("button", { name: "billing:selfServiceSubscription.storage.previewAction" });
expect(storagePreview).toBeDisabled();
fireEvent.click(screen.getByRole("checkbox", { name: /500 GB/u }));
expect(storagePreview).toBeEnabled();
fireEvent.click(storagePreview);
await waitFor(() => {
expect(document.querySelector('[data-ui-id="ui.billing.selfServiceSubscription.previewDialog"]')).toBeVisible();
});
});
it("keeps a failed email package preview visible in the billing surface", async () => {
render(<VaP24aInterimVisualFixture onEmailMarketingPreview={() => Promise.reject(new Error("provider unavailable"))} />);
fireEvent.click(screen.getByRole("button", { name: "billing:selfServiceSubscription.management.overview.addons.action" }));
fireEvent.click(screen.getByRole("button", { name: "billing:selfServiceSubscription.emailMarketing.switch" }));
expect(await screen.findByText("billing:selfServiceSubscription.emailMarketing.errors.checkoutDescription")).toBeVisible();
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
});
});