mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-19 00:12:18 +00:00
fix(documents): check that closing a document consumed its history entry
Closing a card-opened document asks the browser to go back, so the entry the selection pushed is consumed and the reader's next Back reaches the page before it. A traversal is a request, not a guarantee: one asked for while another is still settling can be dropped, and nothing raises when it is. The sheet closes, React stays consistent, and the address bar goes on naming a document nobody has open, so a reload or a shared link re-opens the sheet that was just closed. Pressing Escape straight after the browser's Forward button is exactly that shape, and it reproduces: ten repeats across both viewports failed two of twenty with the URL still carrying the id, and none of twenty once the close verifies itself. The check is guarded by the document id, so a traversal that landed on a different selection is left alone, and it is cancelled the moment the sheet re-opens. The browser test that found it could not say so. It asserted the sheet was closed through a locator matched on the document TITLE, and the sheet falls back to an untitled label while its detail read is pending, so the assertion also passed on an open sheet showing a skeleton, resolved immediately instead of waiting, and pushed the failure into a URL poll ten seconds later. It now asserts the dialog role, which is what the neighbouring deep-link test already does.
This commit is contained in:
1 parent
e2eea55b6e
commit
a5b6508961
3 files changed
+110
-2
No files matched your search
+18
-2
@@ -235,6 +235,19 @@ test.describe("document vault", () => {
|
||||
await expect(openButton(page, "MRT Knie")).toBeVisible();
|
||||
await openButton(page, "MRT Knie").click();
|
||||
const detail = page.getByRole("dialog", { name: "MRT Knie" });
|
||||
// The sheet is CLOSED is a different claim from the sheet is showing this
|
||||
// document, and only one of them can be made by a name-matched locator.
|
||||
//
|
||||
// The sheet takes its accessible name from the document title and falls
|
||||
// back to "Untitled document" while the detail read is pending, so
|
||||
// `expect(detail).not.toBeVisible()` also passes on an OPEN sheet that has
|
||||
// gone back to its skeleton — measured, not theorised: a slow detail read
|
||||
// reports the named dialog invisible and the unnamed one visible at the
|
||||
// same instant. That resolves immediately instead of waiting, which is the
|
||||
// wait this test needs after a history traversal, and the assertion that
|
||||
// depended on it then reads a URL the app has not finished with. The
|
||||
// deep-link test above already uses the unnamed role for this reason.
|
||||
const sheet = page.getByRole("dialog");
|
||||
|
||||
await expect
|
||||
.poll(() => new URL(page.url()).searchParams.get("doc"))
|
||||
@@ -246,15 +259,18 @@ test.describe("document vault", () => {
|
||||
expect(new URL(page.url()).searchParams.get("q")).toBe("MRT");
|
||||
|
||||
await page.goBack();
|
||||
await expect(detail).not.toBeVisible();
|
||||
await expect(sheet).not.toBeVisible();
|
||||
expect(new URL(page.url()).searchParams.get("doc")).toBeNull();
|
||||
expect(new URL(page.url()).searchParams.get("view")).toBe("compact");
|
||||
|
||||
await page.goForward();
|
||||
// Both: the sheet is open AND it is this document, so Escape is pressed on
|
||||
// a settled sheet rather than on one still resolving its title.
|
||||
await expect(sheet).toBeVisible();
|
||||
await expect(detail).toBeVisible();
|
||||
|
||||
await page.keyboard.press("Escape");
|
||||
await expect(detail).not.toBeVisible();
|
||||
await expect(sheet).not.toBeVisible();
|
||||
await expect
|
||||
.poll(() => new URL(page.url()).searchParams.get("doc"))
|
||||
.toBeNull();
|
||||
|
||||
Reference in new issue
Block a user