Files
jobtrackingapp/job-tracker-ui/src/pro-feature-notice.test.tsx
T

50 lines
2.1 KiB
TypeScript

import React from "react";
import "@testing-library/jest-dom";
import { fireEvent, render, screen } from "@testing-library/react";
import ProFeatureNotice from "./components/ProFeatureNotice";
import { AccountPlanProvider } from "./accountPlan";
import { I18nProvider } from "./i18n/I18nProvider";
beforeEach(() => window.sessionStorage.clear());
test.each([
["en", "AI assistance is unavailable", "Review AI settings"],
["nb", "KI-hjelp er utilgjengelig", "Se KI-innstillinger"],
])("keeps paid users on the manual path without an upgrade prompt (%s)", (language, title, action) => {
window.localStorage.setItem("uiLanguage", language);
render(
<I18nProvider>
<AccountPlanProvider value={{ plan: "pro", canUseAi: false, canUseProThemes: true }}>
<ProFeatureNotice featureKey="cv-writing-ai" title="Upgrade prompt">Upgrade body</ProFeatureNotice>
</AccountPlanProvider>
</I18nProvider>,
);
expect(screen.getByText(title)).toBeInTheDocument();
expect(screen.getByRole("link", { name: action })).toHaveAttribute("href", "/settings");
expect(screen.queryByText("Upgrade body")).not.toBeInTheDocument();
fireEvent.click(screen.getByRole("button", { name: new RegExp(title) }));
expect(screen.queryByText(title)).not.toBeInTheDocument();
window.localStorage.removeItem("uiLanguage");
});
test("shows a respectful upgrade action and remembers dismissal for the session", () => {
const { unmount } = render(
<ProFeatureNotice featureKey="test-feature" title="Draft faster with Pro.">
Existing content stays editable.
</ProFeatureNotice>,
);
expect(screen.getByRole("link", { name: "View Pro" })).toHaveAttribute("href", "/settings");
fireEvent.click(screen.getByRole("button", { name: "Dismiss Draft faster with Pro." }));
expect(screen.queryByText("Draft faster with Pro.")).not.toBeInTheDocument();
unmount();
render(
<ProFeatureNotice featureKey="test-feature" title="Draft faster with Pro.">
Existing content stays editable.
</ProFeatureNotice>,
);
expect(screen.queryByText("Draft faster with Pro.")).not.toBeInTheDocument();
});