A name goes in as raw(), a translated word as its own msg(): tsc now lists every value, and the ones that froze are said when shown — Watch later and an untitled channel in the pin and channel notices, a Plex season's name in its removal toast (a new seasonTitleText, which seasonTitle says).
67 lines
2.3 KiB
TypeScript
67 lines
2.3 KiB
TypeScript
// @vitest-environment jsdom
|
|
//
|
|
// The app says what its entry URL tells the account signed in about a switch of account, once, and
|
|
// only once that account is known. Without the hook in the shell, a refused switch or a tab that
|
|
// reloaded as another account comes back without a word.
|
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
import { renderHook } from "@testing-library/react";
|
|
|
|
vi.mock("react-i18next", async (importOriginal) => {
|
|
const actual = await importOriginal<typeof import("react-i18next")>();
|
|
return {
|
|
...actual,
|
|
useTranslation: () => ({
|
|
t: (key: string, values?: Record<string, string>) =>
|
|
values ? `${key} ${JSON.stringify(values)}` : key,
|
|
i18n: { language: "en" },
|
|
}),
|
|
};
|
|
});
|
|
const notifyMock = vi.fn();
|
|
vi.mock("./notifications", async (importOriginal) => {
|
|
const actual = await importOriginal<typeof import("./notifications")>();
|
|
return { ...actual, notify: (...a: unknown[]) => notifyMock(...a) };
|
|
});
|
|
const notice = vi.fn();
|
|
vi.mock("./entryUrl", async (importOriginal) => {
|
|
const actual = await importOriginal<typeof import("./entryUrl")>();
|
|
return { ...actual, accountSwitchNotice: () => notice() };
|
|
});
|
|
const { useAccountSwitchNotice } = await import("./useAccountSwitchNotice");
|
|
const { msg, raw } = await import("./notifications");
|
|
|
|
afterEach(() => {
|
|
notifyMock.mockClear();
|
|
notice.mockReset();
|
|
});
|
|
|
|
describe("the shell's word on a switch of account", () => {
|
|
it("waits for the account, then says it once", () => {
|
|
notice.mockReturnValue({
|
|
level: "info",
|
|
key: "header.account.switchRequested",
|
|
values: { email: raw("b@example.com") },
|
|
});
|
|
const { rerender } = renderHook(({ signedIn }) => useAccountSwitchNotice(signedIn), {
|
|
initialProps: { signedIn: false },
|
|
});
|
|
expect(notifyMock).not.toHaveBeenCalled();
|
|
|
|
rerender({ signedIn: true });
|
|
rerender({ signedIn: false });
|
|
rerender({ signedIn: true });
|
|
|
|
expect(notifyMock).toHaveBeenCalledTimes(1);
|
|
expect(notifyMock).toHaveBeenCalledWith({
|
|
level: "info",
|
|
message: msg("header.account.switchRequested", { email: raw("b@example.com") }),
|
|
});
|
|
});
|
|
|
|
it("says nothing when the entry URL has nothing to say", () => {
|
|
notice.mockReturnValue(null);
|
|
renderHook(() => useAccountSwitchNotice(true));
|
|
expect(notifyMock).not.toHaveBeenCalled();
|
|
});
|
|
});
|