119 lines
4.1 KiB
TypeScript
119 lines
4.1 KiB
TypeScript
// @vitest-environment jsdom
|
|
import "@testing-library/jest-dom/vitest";
|
|
import { render, screen } from "@testing-library/react";
|
|
import type React from "react";
|
|
import { describe, expect, it, vi } from "vitest";
|
|
|
|
import RegisterScreen from "./RegisterScreen";
|
|
|
|
globalThis.ResizeObserver =
|
|
globalThis.ResizeObserver ??
|
|
class ResizeObserver {
|
|
observe() {}
|
|
unobserve() {}
|
|
disconnect() {}
|
|
};
|
|
|
|
vi.mock("react-router", async (importOriginal) => {
|
|
const actual = await importOriginal<typeof import("react-router")>();
|
|
return {
|
|
...actual,
|
|
Form: ({ children, ...props }: React.FormHTMLAttributes<HTMLFormElement>) => <form {...props}>{children}</form>,
|
|
Link: ({ children, to, ...props }: React.AnchorHTMLAttributes<HTMLAnchorElement> & { to: string }) => (
|
|
<a href={to} {...props}>
|
|
{children}
|
|
</a>
|
|
),
|
|
useNavigate: () => vi.fn(),
|
|
useNavigation: () => ({ state: "idle" }),
|
|
useSearchParams: () => [new URLSearchParams()],
|
|
};
|
|
});
|
|
|
|
vi.mock("react-i18next", () => ({
|
|
useTranslation: () => ({ t: (key: string) => key }),
|
|
}));
|
|
|
|
vi.mock("~/utils/data/useRootData", () => ({
|
|
useRootData: () => ({
|
|
csrf: "csrf-token",
|
|
appConfiguration: {
|
|
auth: {
|
|
requireEmailVerification: true,
|
|
requireOrganization: true,
|
|
requireName: true,
|
|
authMethods: { emailPassword: { enabled: true } },
|
|
captcha: { enabled: false, provider: "mcaptcha" },
|
|
},
|
|
},
|
|
}),
|
|
}));
|
|
|
|
vi.mock("~/components/captcha/Captcha", () => ({ default: () => null }));
|
|
|
|
const subscriptionPlans = [
|
|
{
|
|
planId: "product_starter",
|
|
planCode: "starter",
|
|
titleKey: "Core",
|
|
descriptionKey: "Core plan",
|
|
priceId: "price_starter",
|
|
amountCents: 19_900,
|
|
baseAmountCents: 19_900,
|
|
currency: "EUR",
|
|
billingPeriod: 3,
|
|
includedOfficeSeatQuantity: 2,
|
|
includedFieldSeatQuantity: 5,
|
|
includedStorageGb: 100,
|
|
storagePerAdditionalSeatGb: 10,
|
|
extraOfficeSeatQuantity: 0,
|
|
extraFieldSeatQuantity: 0,
|
|
recommended: true,
|
|
},
|
|
] as const;
|
|
|
|
describe("RegisterScreen recovery state", () => {
|
|
it("marks every configured organization and name field as required", () => {
|
|
const { container } = render(
|
|
<RegisterScreen
|
|
creationRequestKey="d7077797-054b-497a-b1ce-8e4f36257a96"
|
|
subscriptionPlans={subscriptionPlans}
|
|
selectedSubscriptionPriceId="price_starter"
|
|
recommendedSubscriptionPriceId="price_starter"
|
|
initialOfficeSeatQuantity={1}
|
|
initialFieldSeatQuantity={0}
|
|
/>
|
|
);
|
|
|
|
expect(container.querySelector('input[name="company"]')).toBeRequired();
|
|
expect(container.querySelector('input[name="first-name"]')).toBeRequired();
|
|
expect(container.querySelector('input[name="last-name"]')).toBeRequired();
|
|
expect(container.querySelector('input[name="selectedSubscriptionPriceId"]')).toHaveValue("price_starter");
|
|
});
|
|
|
|
it("keeps the generic pending screen visible and renders resend errors in place", () => {
|
|
const creationRequestKey = "d7077797-054b-497a-b1ce-8e4f36257a96";
|
|
|
|
const { container } = render(
|
|
<RegisterScreen
|
|
verificationEmailSent
|
|
error="api.errors.tooManyRequests"
|
|
data={{ email: "ada@example.test" }}
|
|
creationRequestKey={creationRequestKey}
|
|
subscriptionPlans={subscriptionPlans}
|
|
selectedSubscriptionPriceId="price_starter"
|
|
recommendedSubscriptionPriceId="price_starter"
|
|
initialOfficeSeatQuantity={1}
|
|
initialFieldSeatQuantity={0}
|
|
/>
|
|
);
|
|
|
|
expect(container.querySelector('[data-ui-id="ui.auth.register.verificationSent"]')).toBeInTheDocument();
|
|
expect(container.querySelector('[data-ui-id="ui.auth.register.form"]')).not.toBeInTheDocument();
|
|
expect(screen.getByRole("alert")).toHaveTextContent("api.errors.tooManyRequests");
|
|
expect(container.querySelector('[data-ui-id="ui.auth.register.resendError"]')).toBeInTheDocument();
|
|
expect(container.querySelector(`input[name="creationRequestKey"][value="${creationRequestKey}"]`)).toBeInTheDocument();
|
|
expect(container.querySelector('input[name="selectedSubscriptionPriceId"]')).toHaveValue("price_starter");
|
|
});
|
|
});
|