import React from "react";
import "@testing-library/jest-dom";
import { fireEvent, render, screen } from "@testing-library/react";

import ProFeatureNotice from "./components/ProFeatureNotice";

beforeEach(() => window.sessionStorage.clear());

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();
});
