fix(diagnostics): Back from a request's lines returns to the view it came from

Every filter change replaced the history entry, so Back after a request or
job pivot left the console altogether (the 0.90 notes promised otherwise).
A pivot follows a link and is its own entry now; the console reads the
landed entry back on popstate. The other filters still adjust in place.
This commit is contained in:
2026-09-19 04:51:42 +02:00
parent 51e98bfc38
commit 6096dd6927
2 changed files with 58 additions and 2 deletions
@@ -124,6 +124,42 @@ describe("AdminLogs", () => {
expect([url.get("lreq"), url.get("lgrp"), url.get("lq")]).toEqual(["req-00000001", null, null]);
});
it("Back from a request's lines returns to the view the pivot was made from", async () => {
window.history.replaceState({ sfPage: "logs" }, "", "/?page=logs&lgrp=error&lq=boom");
const depth = window.history.length;
logsMock.mockResolvedValue({ items: [row(1)], accounts: {}, next_cursor: null });
renderConsole();
await waitFor(() => expect(lines()).toHaveLength(1));
fireEvent.click(lines()[0]!);
fireEvent.click(screen.getByRole("button", { name: "req-00000001" }));
await waitFor(() =>
expect(screen.getByText("adminLogs.pivotRequest:req-00000001")).toBeTruthy(),
);
expect(window.history.length).toBe(depth + 1);
await act(async () => {
const landed = new Promise((resolve) =>
window.addEventListener("popstate", resolve, { once: true }),
);
window.history.back();
await landed;
});
await waitFor(() =>
expect(logsMock).toHaveBeenLastCalledWith(
expect.objectContaining({
request_id: undefined,
levels: ["ERROR", "CRITICAL"],
q: "boom",
}),
null,
),
);
expect(screen.queryByText("adminLogs.pivotRequest:req-00000001")).toBeNull();
const url = new URLSearchParams(window.location.search);
expect([url.get("lreq"), url.get("lgrp"), url.get("lq")]).toEqual([null, "error", "boom"]);
});
it("keeps the account in use offered when the facets no longer count it", async () => {
window.history.replaceState(null, "", "/?page=logs&lu=7");
logsMock.mockResolvedValue({ items: [], accounts: {}, next_cursor: null });