test: pin the focus restore, the choice labels and the phone layout to their fix

Three round-1 fixes whose tests passed against the broken version too.

The focus restore keeps watching until the element that closed the box is GONE, rather than spending
itself on the first render after the change — the distinction Chrome exposed and jsdom did not,
because jsdom commits the save in one render where Chrome takes two. Driven now through the general
case instead: the user moved the focus elsewhere while the request was out, renders keep coming
while that element is still there, and the restore happens only once it disappears.

The choice test's i18n mock returned an option's bare value, which is exactly what dropping the
`config.choices.*` lookup renders — a Hungarian admin would have seen `on`/`off` instead of
`GPU`/`Szoftver` with the gate green. Marked labels now, still short enough not to move the
segmented-bar budget the same file measures.

The admin config row's stacking had no test at all, only its sibling fix did — and stacking is the
only fix for a text or number key, whose fixed-width input is the wide control. Class contract, as
SearchBar.dom.test.tsx already does for the narrow-header rules, since jsdom does no layout.

Also: the time-zone cleanup deleted TZ, and Node re-reads it on assignment only, so the process kept
the last zone the file set. Harmless until someone appends a test below it.
This commit is contained in:
2026-09-17 23:45:41 +02:00
parent 986bc8d01e
commit a28193a00c
4 changed files with 142 additions and 14 deletions
@@ -136,6 +136,39 @@ describe("DiagnosticsSettings", () => {
expect(document.activeElement).toBe(levelButton("settings.diagnostics.levels.INFO"));
});
it("the watch outlives a render in which the element it is watching is still there", async () => {
// The distinguishing property of the restore, and the one the browser found: it keeps looking
// until the element is GONE, instead of spending itself on the first render after the change.
// Chrome commits a saved level as two renders and jsdom as one, so this drives the general
// case directly — the user moved the focus somewhere else while the request was out, and that
// somewhere else disappears later, several renders on.
vi.useFakeTimers();
try {
// Raised, so the status line's countdown is mounted and its 30 s tick keeps re-rendering.
const until = new Date(Date.now() + 3_600_000).toISOString();
mount({ diagnostics: { level: "DEBUG", until, retention_days: 7 } });
fireEvent.click(levelButton("settings.diagnostics.levels.TRACE"));
const elsewhere = document.createElement("button");
document.body.append(elsewhere);
elsewhere.focus();
// Cancel closes the box; the watch is armed on `elsewhere`, which is still in the page.
fireEvent.click(screen.getByRole("button", { name: "settings.diagnostics.consent.cancel" }));
expect(document.activeElement).toBe(elsewhere); // their place is kept, nothing is stolen
// Renders keep coming (the countdown ticks) while it is still there, and must not spend it.
await vi.advanceTimersByTimeAsync(60_000);
expect(document.activeElement).toBe(elsewhere);
elsewhere.remove(); // now the focus really has fallen to <body>
expect(document.activeElement).toBe(document.body);
await vi.advanceTimersByTimeAsync(30_000);
expect(document.activeElement).toBe(levelButton("settings.diagnostics.levels.DEBUG"));
} finally {
vi.useRealTimers();
}
});
it("the ticking status line is not a live region", async () => {
const until = new Date(Date.now() + 3_600_000).toISOString();
mount({ diagnostics: { level: "DEBUG", until, retention_days: 7 } });