import { render, screen, fireEvent, waitFor } from "@testing-library/react";
import { describe, it, expect, vi } from "vitest";
import ProfileReminderModal from "./ProfileReminderModal";
const MSG = "Complete your profile to unlock rewards!";
describe("ProfileReminderModal", () => {
it("renders nothing when closed", () => {
render();
expect(screen.queryByText(MSG)).toBeNull();
});
it("hides again when the open prop flips back to false", async () => {
const { rerender } = render();
expect(screen.getByText(MSG)).toBeInTheDocument();
rerender();
await waitFor(() => expect(screen.queryByText(MSG)).toBeNull());
});
it("renders the message and a link to /settings/profile when open", () => {
render();
expect(screen.getByText(MSG)).toBeInTheDocument();
expect(screen.getByText("Complete Profile").closest("a")).toHaveAttribute(
"href",
"/settings/profile",
);
});
it("calls onClose when the close button is clicked", () => {
const onClose = vi.fn();
render();
fireEvent.click(screen.getByLabelText("Close"));
expect(onClose).toHaveBeenCalled();
});
it("calls onClose when the member follows the Complete Profile link", () => {
const onClose = vi.fn();
render();
fireEvent.click(screen.getByText("Complete Profile"));
expect(onClose).toHaveBeenCalled();
});
it("does not write a session dismissal of its own", () => {
const onClose = vi.fn();
render();
fireEvent.click(screen.getByLabelText("Close"));
expect(sessionStorage.getItem("te_profile_reminder_dismissed")).toBeNull();
});
});