fix(notifications): Back to a row that folded away since opens Earlier on it

This commit is contained in:
2026-10-29 00:47:52 +01:00
parent e3a4593acf
commit d6e72d7576
3 changed files with 97 additions and 37 deletions
@@ -49,7 +49,7 @@ vi.mock("../../components/ui/PageShell", async (importOriginal) => ({
}));
import NotificationsPanel from "./NotificationsPanel";
import { focusNavItem } from "../../lib/listNav";
import { focusNavItem, restoreNavPosition } from "../../lib/listNav";
// The server list goes through the real live query, so an optimistic patch of its cache is seen.
beforeEach(() => {
@@ -94,7 +94,10 @@ function mount() {
const qc = new QueryClient();
const tree = () => (
<QueryClientProvider client={qc}>
<NotificationsPanel />
{/* The page's scroller, as in the app: Back finds a row in another of the page's lists. */}
<main>
<NotificationsPanel />
</main>
</QueryClientProvider>
);
const { rerender } = render(tree());
@@ -147,6 +150,29 @@ describe("NotificationsPanel · order", () => {
expect(rows()).toEqual(["Ready 1", "Activity 3", "Ready 2"]);
});
it("Back to a row that folded away while the page was gone opens Earlier on it", async () => {
// Read during the visit it was opened from, the row kept its place in Needs you; on the next
// visit it is read and over a week old, and folded under Earlier the restore found no list
// holding it — the focus fell on the neighbour at its old place.
h.server = [server(1, 8 * D, false), server(2, 9 * D, true)];
h.client = [];
const cancel = restoreNavPosition({
list: 0,
lists: 2,
index: 0,
name: "inbox.downloadDone.title: Ready 2",
});
mount();
await loaded();
await waitFor(() =>
expect(document.activeElement?.closest("[data-nav-index]")?.textContent).toMatch(/Ready 2/),
);
cancel();
expect(
screen.getByRole("button", { name: "inbox.earlier:1" }).getAttribute("aria-expanded"),
).toBe("true");
});
it("numbers each list's rows from 0 for the keyboard walk", async () => {
h.server = [server(1, 1 * H, false), server(2, 2 * H, true), server(3, 10 * D, true)];
h.client = [client(4, 3 * H)];