summaryrefslogtreecommitdiffhomepage
path: root/src/adapters/portal.test.ts
diff options
context:
space:
mode:
authorAdam Malczewski <[email protected]>2026-06-27 01:13:28 +0900
committerAdam Malczewski <[email protected]>2026-06-27 01:13:31 +0900
commit2fa03f8d7410c2b8d6be8e10ad088863e83d7177 (patch)
tree94e1923180ae38d571d34b578afecb0a18913c24 /src/adapters/portal.test.ts
parent80f99665034a0e510300793205c162fc7a46769f (diff)
parent08b12478636f4a5c86a1f3c40a843f2906b7c82f (diff)
downloaddispatch-web-2fa03f8d7410c2b8d6be8e10ad088863e83d7177.tar.gz
dispatch-web-2fa03f8d7410c2b8d6be8e10ad088863e83d7177.zip
Merge branch 'dev' into feature/heartbeat
# Conflicts: # src/app/App.svelte # src/app/store.svelte.ts # src/app/store.test.ts # src/features/workspaces/ui/WorkspaceCard.test.ts
Diffstat (limited to 'src/adapters/portal.test.ts')
-rw-r--r--src/adapters/portal.test.ts88
1 files changed, 44 insertions, 44 deletions
diff --git a/src/adapters/portal.test.ts b/src/adapters/portal.test.ts
index 792d3b4..a5624d5 100644
--- a/src/adapters/portal.test.ts
+++ b/src/adapters/portal.test.ts
@@ -2,48 +2,48 @@ import { afterEach, describe, expect, it } from "vitest";
import { portal } from "./portal";
describe("portal action", () => {
- afterEach(() => {
- // Strip any leftover teleported nodes between tests.
- document.querySelectorAll("body > :not(script)").forEach((n) => {
- if (n instanceof HTMLElement) n.remove();
- });
- });
-
- it("teleports the node to document.body (escaping an ancestor with transform)", () => {
- // Simulate the sidebar: a transformed ancestor establishes a containing
- // block for `position: fixed`.
- const ancestor = document.createElement("div");
- ancestor.style.transform = "translateX(0)";
- document.body.appendChild(ancestor);
-
- const node = document.createElement("div");
- node.setAttribute("data-testid", "modal");
- ancestor.appendChild(node);
- expect(node.parentNode).toBe(ancestor);
-
- const action = portal(node);
-
- // After the action, the node is a direct child of <body>, not the ancestor.
- expect(node.parentNode).toBe(document.body);
- expect(ancestor.contains(node)).toBe(false);
-
- action.destroy();
-
- // On destroy the node is removed from <body>.
- expect(document.body.contains(node)).toBe(false);
- });
-
- it("is a no-op (does not throw) when document is unavailable (SSR guard)", () => {
- const originalDocument = globalThis.document;
- // @ts-expect-error — deliberately undefined to exercise the SSR guard.
- globalThis.document = undefined;
- try {
- const stub = {} as HTMLElement;
- const action = portal(stub);
- // Must not throw, and returns a destroy that is safe to call.
- action.destroy();
- } finally {
- globalThis.document = originalDocument;
- }
- });
+ afterEach(() => {
+ // Strip any leftover teleported nodes between tests.
+ document.querySelectorAll("body > :not(script)").forEach((n) => {
+ if (n instanceof HTMLElement) n.remove();
+ });
+ });
+
+ it("teleports the node to document.body (escaping an ancestor with transform)", () => {
+ // Simulate the sidebar: a transformed ancestor establishes a containing
+ // block for `position: fixed`.
+ const ancestor = document.createElement("div");
+ ancestor.style.transform = "translateX(0)";
+ document.body.appendChild(ancestor);
+
+ const node = document.createElement("div");
+ node.setAttribute("data-testid", "modal");
+ ancestor.appendChild(node);
+ expect(node.parentNode).toBe(ancestor);
+
+ const action = portal(node);
+
+ // After the action, the node is a direct child of <body>, not the ancestor.
+ expect(node.parentNode).toBe(document.body);
+ expect(ancestor.contains(node)).toBe(false);
+
+ action.destroy();
+
+ // On destroy the node is removed from <body>.
+ expect(document.body.contains(node)).toBe(false);
+ });
+
+ it("is a no-op (does not throw) when document is unavailable (SSR guard)", () => {
+ const originalDocument = globalThis.document;
+ // @ts-expect-error — deliberately undefined to exercise the SSR guard.
+ globalThis.document = undefined;
+ try {
+ const stub = {} as HTMLElement;
+ const action = portal(stub);
+ // Must not throw, and returns a destroy that is safe to call.
+ action.destroy();
+ } finally {
+ globalThis.document = originalDocument;
+ }
+ });
});