48 lines
1.3 KiB
TypeScript
48 lines
1.3 KiB
TypeScript
import { renderToStaticMarkup } from "react-dom/server";
|
|
import { describe, expect, it, vi } from "vitest";
|
|
|
|
const mocks = vi.hoisted(() => ({
|
|
screenProps: vi.fn(),
|
|
}));
|
|
|
|
vi.mock("../subscription-screen", () => ({
|
|
SubscriptionScreen: (props: Record<string, unknown>) => {
|
|
mocks.screenProps(props);
|
|
return <main>Global subscription</main>;
|
|
},
|
|
}));
|
|
|
|
import SubscriptionPage from "../page";
|
|
|
|
describe("SubscriptionPage", () => {
|
|
it("renders outside CharacterProvider and treats character as return context", async () => {
|
|
const page = await SubscriptionPage({
|
|
searchParams: Promise.resolve({
|
|
character: "maya",
|
|
returnTo: "sidebar",
|
|
type: "topup",
|
|
}),
|
|
});
|
|
|
|
expect(renderToStaticMarkup(page)).toContain("Global subscription");
|
|
expect(mocks.screenProps).toHaveBeenCalledWith(
|
|
expect.objectContaining({
|
|
returnTo: "sidebar",
|
|
sourceCharacterSlug: "maya",
|
|
subscriptionType: "topup",
|
|
}),
|
|
);
|
|
});
|
|
|
|
it("uses Elio for missing source navigation context", async () => {
|
|
const page = await SubscriptionPage({
|
|
searchParams: Promise.resolve({}),
|
|
});
|
|
|
|
renderToStaticMarkup(page);
|
|
expect(mocks.screenProps).toHaveBeenLastCalledWith(
|
|
expect.objectContaining({ sourceCharacterSlug: "elio" }),
|
|
);
|
|
});
|
|
});
|