fix(nav): an item Back finds in another list is brought into view
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
// sits in the stream below. The restore matched the unnamed list by its place, missed the name there
|
||||
// and fell back to the saved index — the focus landed on the neighbour, and Enter opened the wrong
|
||||
// notification. Its own file: listNav keeps module-level state.
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { act, cleanup, render } from "@testing-library/react";
|
||||
import { useRef } from "react";
|
||||
|
||||
@@ -72,4 +72,21 @@ describe("Back to an item that moved to another list", () => {
|
||||
]);
|
||||
expect(focused()).toBe("download");
|
||||
});
|
||||
|
||||
it("brings an item found in another list into view; one in its own list stays put", async () => {
|
||||
// The scroll restore put the page where the item WAS: found elsewhere, it would hold the focus
|
||||
// off screen.
|
||||
const reveal = vi.fn();
|
||||
Element.prototype.scrollIntoView = reveal;
|
||||
await leaveAndReturn([["subscribed", "download"], ["older"]], "subscribed", [
|
||||
["download"],
|
||||
["subscribed", "older"],
|
||||
]);
|
||||
expect(reveal).toHaveBeenCalledTimes(1);
|
||||
cleanup();
|
||||
reveal.mockClear();
|
||||
await leaveAndReturn([["subscribed", "download"]], "download", [["download", "subscribed"]]);
|
||||
expect(focused()).toBe("download");
|
||||
expect(reveal).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user