test(nav): pin the restore's last look and the clearing of the name it looks for
This commit is contained in:
@@ -13,6 +13,7 @@ import {
|
|||||||
NAV_REVEAL_EVENT,
|
NAV_REVEAL_EVENT,
|
||||||
navItemAttrs,
|
navItemAttrs,
|
||||||
navPosition,
|
navPosition,
|
||||||
|
pendingNavName,
|
||||||
restoreNavPosition,
|
restoreNavPosition,
|
||||||
useListNav,
|
useListNav,
|
||||||
} from "./listNav";
|
} from "./listNav";
|
||||||
@@ -150,4 +151,56 @@ describe("Back to an item that moved to another list", () => {
|
|||||||
document.querySelector("main")!.firstElementChild,
|
document.querySelector("main")!.firstElementChild,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("looks in another list at its last look when its own never renders the place it counts", async () => {
|
||||||
|
vi.useFakeTimers();
|
||||||
|
try {
|
||||||
|
const { unmount } = render(<Page lists={[["older", "subscribed"], ["subscribed-2"]]} />);
|
||||||
|
button("subscribed").focus();
|
||||||
|
const pos = navPosition()!;
|
||||||
|
unmount();
|
||||||
|
// Its own list still counts two, and keeps showing one; the item is in the next list.
|
||||||
|
render(<Page lists={[["older"], ["subscribed"]]} counts={[2]} />);
|
||||||
|
const cancel = restoreNavPosition(pos);
|
||||||
|
await act(async () => vi.advanceTimersByTimeAsync(1000));
|
||||||
|
expect(focused()).toBeUndefined(); // still giving its own list the chance
|
||||||
|
await act(async () => vi.advanceTimersByTimeAsync(1100));
|
||||||
|
expect(focused()).toBe("subscribed");
|
||||||
|
cancel();
|
||||||
|
} finally {
|
||||||
|
vi.useRealTimers();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("the name a Back is still looking for", () => {
|
||||||
|
const pos = { list: 0, lists: 1, index: 0, name: "subscribed" };
|
||||||
|
|
||||||
|
it("is there while it looks, and gone once cancelled", () => {
|
||||||
|
const cancel = restoreNavPosition(pos);
|
||||||
|
expect(pendingNavName()).toBe("subscribed");
|
||||||
|
cancel();
|
||||||
|
expect(pendingNavName()).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("is gone once the focus went somewhere else", async () => {
|
||||||
|
render(<button>elsewhere</button>);
|
||||||
|
const cancel = restoreNavPosition(pos);
|
||||||
|
button("elsewhere").focus();
|
||||||
|
await wait(80);
|
||||||
|
expect(pendingNavName()).toBeNull();
|
||||||
|
cancel();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("is gone once it gave up", async () => {
|
||||||
|
vi.useFakeTimers();
|
||||||
|
try {
|
||||||
|
const cancel = restoreNavPosition(pos);
|
||||||
|
await vi.advanceTimersByTimeAsync(2100);
|
||||||
|
expect(pendingNavName()).toBeNull();
|
||||||
|
cancel();
|
||||||
|
} finally {
|
||||||
|
vi.useRealTimers();
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user