A pure move (git mv, history kept): 333 files leave components/, which now holds only the platform layer (ui/) and the legal pages. The shell is the frame (App, header, nav rail, palette, boot); each page lives in modules/<page>/ with its rail, store and tests; what several pages share sits in features/<name>/; the shared-link page is watch/. Domain-free helpers went straight to ui/ (ViewSwitcher, FilterRail, the confirm dialog, the language switcher, the copy rows). Every relative specifier was rewritten (imports, dynamic imports, vi.mock, new URL), and the contract tests that scan sources now scan the whole app source, not only components/ — each glob was counted before and after so none went green over fewer files. The locale-format rule matched `/src/components/` only, so the move would have taken ~300 files out from under its i18n-singleton check; it now covers every folder that holds components, with a test per folder.
40 lines
1.4 KiB
TypeScript
40 lines
1.4 KiB
TypeScript
// @vitest-environment jsdom
|
|
//
|
|
// A render crash's notice speaks the reader's language. It showed `error.message` — the JS
|
|
// engine's English ("Cannot read properties of undefined (reading 'x')") — in the toast and the inbox,
|
|
// where it outlives the reload. The technical text stays in the `ui.crash` log.
|
|
import { afterEach, expect, it, vi } from "vitest";
|
|
import { cleanup, render } from "@testing-library/react";
|
|
|
|
const notify = vi.fn();
|
|
vi.mock("../lib/notifications", () => ({ notify: (...args: unknown[]) => notify(...args) }));
|
|
|
|
import i18n from "../i18n";
|
|
import { clear, events } from "../lib/log";
|
|
import ErrorBoundary from "./ErrorBoundary";
|
|
|
|
afterEach(() => {
|
|
cleanup();
|
|
clear();
|
|
vi.restoreAllMocks();
|
|
});
|
|
|
|
it("a crash is reported in words the reader reads; the engine's text goes to the log", () => {
|
|
vi.spyOn(console, "error").mockImplementation(() => {}); // React reports the throw itself too
|
|
const Broken = () => {
|
|
throw new TypeError("Cannot read properties of undefined (reading 'x')");
|
|
};
|
|
render(
|
|
<ErrorBoundary>
|
|
<Broken />
|
|
</ErrorBoundary>,
|
|
);
|
|
|
|
expect(notify).toHaveBeenCalledWith(
|
|
expect.objectContaining({ level: "fatal", message: i18n.t("errors.boundary.notifMessage") }),
|
|
);
|
|
expect(JSON.stringify(events().filter((e) => e.event === "ui.crash"))).toContain(
|
|
"Cannot read properties of undefined",
|
|
);
|
|
});
|