| 1 | import assert from "node:assert/strict"; |
| 2 | import { browserElementDrafts } from "../lib/browserElementDrafts"; |
| 3 | import { attachBrowserComposer } from "../app-runtime/browserComposerBridge"; |
| 4 | |
| 5 | const original: string[] = [], other: string[] = []; |
| 6 | browserElementDrafts.setState({ target: undefined, pending: {} }); |
| 7 | const closeOriginal = attachBrowserComposer("task", "session-old", text => original.push(text)); |
| 8 | const captured = browserElementDrafts.getState().target!; |
| 9 | closeOriginal(); |
| 10 | const closeOther = attachBrowserComposer("task", "session-new", text => other.push(text)); |
| 11 | // A picker begun in the old session resolves after navigation to a new session. |
| 12 | browserElementDrafts.getState().add(captured.taskId, captured.sessionId, { role: "button", name: "Save", epoch: 3 }); |
| 13 | assert.deepEqual(other, [], "late selection must never enter the new session draft"); |
| 14 | assert.equal(Object.keys(browserElementDrafts.getState().pending).length, 1); |
| 15 | closeOther(); |
| 16 | const closeRestored = attachBrowserComposer("task", "session-old", text => original.push(text)); |
| 17 | assert.equal(original.length, 1); |
| 18 | assert.equal(JSON.parse(original[0]).executableReference, false); |
| 19 | assert.equal(JSON.parse(original[0]).browserElement.name, "Save"); |
| 20 | assert.equal(Object.keys(browserElementDrafts.getState().pending).length, 0); |
| 21 | closeRestored(); |
| 22 | const closeAgain = attachBrowserComposer("task", "session-old", text => original.push(text)); |
| 23 | assert.equal(original.length, 1, "returning to the session must not duplicate an attachment"); |
| 24 | closeAgain(); |
| 25 | console.log("browser element drafts: late selection stays with its original session and is delivered once"); |
| 26 |