import React from "react"; import "@testing-library/jest-dom"; import { render, screen } from "@testing-library/react"; import ViewStateNotice from "./components/ViewStateNotice"; import { I18nProvider } from "./i18n/I18nProvider"; import { translations } from "./i18n/translations"; test.each(["en", "nb"] as const)("[PRES-E08] %s loading/error/recovery updates one persistent polite region", language => { localStorage.setItem("uiLanguage", language); const t = translations[language]; const error = { kind: "unavailable" as const, message: "Unavailable", retryable: true }; const view = (loading: boolean, failed = false) => ; const { rerender } = render(view(true)); const status = screen.getByRole("status"); expect(status).toHaveTextContent(t.loading); expect(status).toHaveAttribute("aria-live", "polite"); expect(status).toHaveAttribute("aria-atomic", "true"); rerender(view(false, true)); expect(status).toBeEmptyDOMElement(); expect(screen.getByRole("alert")).toHaveTextContent("Unavailable"); rerender(view(false)); expect(screen.getByRole("status")).toBe(status); expect(status).toHaveTextContent(language === "en" ? "Content loaded." : "Innhold lastet."); rerender(view(false)); expect(screen.getByRole("status")).toBe(status); expect(screen.queryByRole("progressbar")).not.toBeInTheDocument(); localStorage.clear(); }); test("[PRES-E08] idle/error-only notices do not invent a load completion; later loading still announces", () => { const view = (loading = false) => ; const { rerender } = render(view()); expect(screen.getByRole("status")).toBeEmptyDOMElement(); rerender(view(true)); expect(screen.getByRole("status")).toHaveTextContent("Loading..."); rerender(view()); expect(screen.getByRole("status")).toHaveTextContent("Content loaded."); });