// @vitest-environment jsdom // // Settings → Account names the account's latest sign-in (prod UAT 2026-09-19: only the admin's user // list showed it), and its role in the reader's language — the raw `user` read in English under HU. import { afterEach, describe, expect, it, vi } from "vitest"; import { cleanup, render, screen } from "@testing-library/react"; import type { Me } from "../lib/api"; vi.mock("react-i18next", async (importOriginal) => { const actual = await importOriginal(); return { ...actual, useTranslation: () => ({ t: (key: string, vars?: Record) => vars?.time != null ? `${key}:${String(vars.time)}` : key, i18n: { language: "en" }, }), }; }); vi.mock("../lib/format", async (importOriginal) => { const actual = await importOriginal(); return { ...actual, formatDateTime: (iso: string) => `at ${iso}` }; }); import { AccountHeader } from "./SettingsPanel"; afterEach(cleanup); const me = (extra: Partial): Me => ({ email: "someone@example.com", display_name: "Someone", avatar_url: null, role: "user", last_login_at: null, ...extra, }) as Me; describe("AccountHeader", () => { it("names the latest sign-in and the role in the reader's language", () => { render(); expect(screen.getByTestId("account-last-login").textContent).toBe( "settings.account.lastLogin:at 2026-09-19T02:00:00Z", ); expect(screen.getByText("nav.role.user")).toBeTruthy(); }); it("says when none is recorded", () => { render(); expect(screen.getByTestId("account-last-login").textContent).toBe( "settings.account.lastLoginNone", ); }); });