Files
siftlode/frontend/src/components/SettingsPanel.account.dom.test.tsx
T
peter 373415a2eb feat(account): show the account its own last sign-in
Settings → Account names the latest sign-in on any device (only the
admin's user list did, though the 0.88 notes said otherwise), and the role
in the reader's language instead of the raw `user`.
2026-09-19 04:51:43 +02:00

61 lines
2.1 KiB
TypeScript

// @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<typeof import("react-i18next")>();
return {
...actual,
useTranslation: () => ({
t: (key: string, vars?: Record<string, unknown>) =>
vars?.time != null ? `${key}:${String(vars.time)}` : key,
i18n: { language: "en" },
}),
};
});
vi.mock("../lib/format", async (importOriginal) => {
const actual = await importOriginal<typeof import("../lib/format")>();
return { ...actual, formatDateTime: (iso: string) => `at ${iso}` };
});
import { AccountHeader } from "./SettingsPanel";
afterEach(cleanup);
const me = (extra: Partial<Me>): Me =>
({
email: "someone@example.com",
display_name: "Someone",
avatar_url: null,
role: "user",
is_demo: false,
last_login_at: null,
...extra,
}) as Me;
describe("AccountHeader", () => {
it("names the latest sign-in and the role in the reader's language", () => {
render(<AccountHeader me={me({ last_login_at: "2026-09-19T02:00:00Z" })} />);
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, and says nothing about it for the demo", () => {
render(<AccountHeader me={me({})} />);
expect(screen.getByTestId("account-last-login").textContent).toBe(
"settings.account.lastLoginNone",
);
cleanup();
render(<AccountHeader me={me({ is_demo: true })} />);
expect(screen.queryByTestId("account-last-login")).toBeNull();
expect(screen.getByText("nav.role.demo")).toBeTruthy();
});
});