diff options
| author | Adam Malczewski <[email protected]> | 2026-09-07 19:16:08 +0900 |
|---|---|---|
| committer | Adam Malczewski <[email protected]> | 2026-09-07 19:16:08 +0900 |
| commit | 9c201c60a727106f1e3bf8c2af5f86aa7427098f (patch) | |
| tree | 37c0fa07913154386785126bd75093866f05c975 /src/features/workspaces/ui/WorkspacesHome.test.ts | |
| parent | 61733924352285df6c44f66edf69ea6f738fae3e (diff) | |
| download | dispatch-web-9c201c60a727106f1e3bf8c2af5f86aa7427098f.tar.gz dispatch-web-9c201c60a727106f1e3bf8c2af5f86aa7427098f.zip | |
feat(workspaces): sync the home tile layout per device orientation
The Win8-Start home grid's arrangement now syncs from the backend's
home-tile-layout plugin: ONE shared document per device orientation
(wide = landscape/desktop, tall = portrait/mobile) — every landscape
device renders the same layout, every portrait device the same other
one. localStorage persistence is retired (no migration — devices start
from the shared document; the first arrangement creates it).
- adapter/tile-layout-http.ts: the injected HTTP edge (GET/PUT/DELETE
/home/tile-layout/:mode), the features/layout adapter's pattern
- tile-layout-store: server-backed, keyed by geometry mode — boot +
orientation-change probes (stale in-flight responses never land),
locally-applied edits + debounced full-document PUT with rollback to
the last server document, WS push filtered to the active orientation,
quiet ephemeral degrade when the backend is unreachable (no error UI),
sync gated while a probe is in flight
- WorkspacesHome locks the store's orientation to the resolved grid
geometry (the landscape/portrait split IS the device-type split)
- app store: the tile store lives beside the layout store; the WS
dispatch feeds 'tile-layout' broadcasts into it; 'tiles' prop from
App.svelte (the page entry owns the httpBase)
- ws adapter: the 'tile-layout' server message (parse guard) + socket
handler; wire conformance case
Diffstat (limited to 'src/features/workspaces/ui/WorkspacesHome.test.ts')
| -rw-r--r-- | src/features/workspaces/ui/WorkspacesHome.test.ts | 56 |
1 files changed, 34 insertions, 22 deletions
diff --git a/src/features/workspaces/ui/WorkspacesHome.test.ts b/src/features/workspaces/ui/WorkspacesHome.test.ts index eb5b293..9e8411a 100644 --- a/src/features/workspaces/ui/WorkspacesHome.test.ts +++ b/src/features/workspaces/ui/WorkspacesHome.test.ts @@ -1,10 +1,10 @@ +import type { TileGeometryMode, TileLayoutData } from "@dispatch/tile-layout-contract"; import type { Workspace, WorkspaceEntry } from "@dispatch/wire"; import { render, screen, waitFor } from "@testing-library/svelte"; import userEvent from "@testing-library/user-event"; import { describe, expect, it, vi } from "vitest"; -import type { LocalStore } from "../../../adapters/local-storage"; import type { WorkspaceHttp, WorkspaceResult } from "../adapter/http"; -import type { TileLayoutData, TileLayoutEntry } from "../logic/tile-layout"; +import type { TileLayoutHttp } from "../adapter/tile-layout-http"; import { createTileLayoutStore } from "../tile-layout-store.svelte"; import WorkspacesHome from "./WorkspacesHome.svelte"; @@ -46,27 +46,37 @@ function fakeHttp(list: WorkspaceEntry[] = [ws()]): WorkspaceHttp { } as unknown as WorkspaceHttp; } -function memoryLayout(initial: TileLayoutData | null = null): LocalStore<TileLayoutData> & { - data: TileLayoutData | null; -} { - const store = { - data: initial, - load: () => store.data, - save: (value: TileLayoutData) => { - store.data = value; +/** + * A fake tile-layout HTTP edge serving ONE controllable document per mode + * (no mocks of our modules). `docs` is the live store — assertions read it + * after `waitFor` (the boot probe + debounced sync writes land there). + */ +function memoryLayout( + initial: TileLayoutData | null = null, +): TileLayoutHttp & { docs: Map<TileGeometryMode, TileLayoutData> } { + const docs = new Map<TileGeometryMode, TileLayoutData>(); + if (initial !== null) docs.set("wide", initial); + return { + docs, + async getLayout(mode) { + return { ok: true, layout: docs.get(mode) ?? { version: 2, tiles: [] } }; + }, + async putLayout(mode, layout) { + docs.set(mode, layout); + return { ok: true, layout }; }, - clear: () => { - store.data = null; + async deleteLayout(mode) { + docs.set(mode, { version: 2, tiles: [] }); + return { ok: true, layout: docs.get(mode) as TileLayoutData }; }, }; - return store; } describe("WorkspacesHome (tile canvas)", () => { it("renders one tile per workspace, in the persisted tile order (not the list order)", async () => { const list = [ws({ id: "a", title: "A" }), ws({ id: "b", title: "B" })]; const layout = memoryLayout({ - version: 1, + version: 2, tiles: [ { id: "b", order: 0, colSpan: 1, rowSpan: 1 }, { id: "a", order: 1, colSpan: 1, rowSpan: 1 }, @@ -77,7 +87,7 @@ describe("WorkspacesHome (tile canvas)", () => { store: (await import("../store.svelte")).createWorkspaceStore(fakeHttp(list)), onNavigate: vi.fn(), computers: [], - tiles: createTileLayoutStore(layout), + tiles: createTileLayoutStore({ http: layout }), }, }); @@ -94,7 +104,7 @@ describe("WorkspacesHome (tile canvas)", () => { store: (await import("../store.svelte")).createWorkspaceStore(fakeHttp()), onNavigate, computers: [], - tiles: createTileLayoutStore(memoryLayout()), + tiles: createTileLayoutStore({ http: memoryLayout() }), }, }); @@ -113,7 +123,7 @@ describe("WorkspacesHome (tile canvas)", () => { store, onNavigate, computers: [], - tiles: createTileLayoutStore(memoryLayout()), + tiles: createTileLayoutStore({ http: memoryLayout() }), }, }); @@ -139,7 +149,7 @@ describe("WorkspacesHome (tile canvas)", () => { store, onNavigate: vi.fn(), computers: [], - tiles: createTileLayoutStore(memoryLayout()), + tiles: createTileLayoutStore({ http: memoryLayout() }), }, }); @@ -159,7 +169,7 @@ describe("WorkspacesHome (tile canvas)", () => { it("workspaces unknown to the layout append at the end (deep-link auto-create)", async () => { const list = [ws({ id: "a", title: "A" }), ws({ id: "b", title: "B" })]; const layout = memoryLayout({ - version: 1, + version: 2, tiles: [{ id: "b", order: 0, colSpan: 1, rowSpan: 1 }], }); render(WorkspacesHome, { @@ -167,7 +177,7 @@ describe("WorkspacesHome (tile canvas)", () => { store: (await import("../store.svelte")).createWorkspaceStore(fakeHttp(list)), onNavigate: vi.fn(), computers: [], - tiles: createTileLayoutStore(layout), + tiles: createTileLayoutStore({ http: layout }), }, }); @@ -176,7 +186,9 @@ describe("WorkspacesHome (tile canvas)", () => { const wrappers = document.querySelectorAll("[data-tile-id]"); expect([...wrappers].map((el) => el.getAttribute("data-tile-id"))).toEqual(["b", "a"]); // And the sync persisted the appended entry. - const entries = (layout.data?.tiles ?? []).map((tile: TileLayoutEntry) => tile.id); - expect(entries).toEqual(["b", "a"]); + await waitFor(() => { + const tiles = layout.docs.get("wide")?.tiles ?? []; + expect(tiles.map((tile) => tile.id)).toEqual(["b", "a"]); + }); }); }); |
