import { act, fireEvent, render, screen } from "@testing-library/react";
import RestartBanner from "@/features/settings/RestartBanner";
import { dismissRestartBanner, raiseRestartBanner } from "@/features/settings/restartBanner";

beforeEach(() => {
	act(() => dismissRestartBanner());
});

test("hidden until raised, dismissible, and a new raise shows it again", () => {
	render(<RestartBanner />);
	expect(screen.queryByRole("status")).toBeNull();

	act(() => raiseRestartBanner());
	expect(screen.getByRole("status").textContent).toContain("Restart nxdns to apply");

	fireEvent.click(screen.getByRole("button", { name: "Dismiss" }));
	expect(screen.queryByRole("status")).toBeNull();

	act(() => raiseRestartBanner());
	expect(screen.getByRole("status")).toBeTruthy();
});

test("raising while already raised keeps the banner up", () => {
	render(<RestartBanner />);
	act(() => raiseRestartBanner());
	act(() => raiseRestartBanner());
	expect(screen.getByRole("status")).toBeTruthy();
});
