The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import { beforeEach, describe, expect, it } from "vite-plus/test"; |
| 2 | |
| 3 | import { |
| 4 | acquireBrowserSurface, |
| 5 | acquireBrowserSurfaceActivity, |
| 6 | useBrowserSurfaceStore, |
| 7 | } from "./browserSurfaceStore"; |
| 8 | |
| 9 | describe("browserSurfaceStore", () => { |
| 10 | beforeEach(() => { |
| 11 | useBrowserSurfaceStore.setState({ activityByTabId: {}, byTabId: {} }); |
| 12 | }); |
| 13 | |
| 14 | it("keeps concurrent background work active until every lease is released", () => { |
| 15 | const first = acquireBrowserSurfaceActivity("background-browser"); |
| 16 | const second = acquireBrowserSurfaceActivity("background-browser"); |
| 17 | |
| 18 | first(); |
| 19 | expect(useBrowserSurfaceStore.getState().activityByTabId["background-browser"]).toBe(1); |
| 20 | |
| 21 | second(); |
| 22 | expect(useBrowserSurfaceStore.getState().activityByTabId["background-browser"]).toBeUndefined(); |
| 23 | }); |
| 24 | |
| 25 | it("freezes the source content dimensions for a fitted presentation", () => { |
| 26 | const tabId = "fitted-browser-surface"; |
| 27 | const sourceOwner = Symbol("source"); |
| 28 | const sourceContent = { |
| 29 | x: 10, |
| 30 | y: 20, |
| 31 | width: 1_280, |
| 32 | height: 720, |
| 33 | scale: 1, |
| 34 | scrollLeft: 0, |
| 35 | scrollTop: 0, |
| 36 | }; |
| 37 | useBrowserSurfaceStore.getState().claim(tabId, sourceOwner, false); |
| 38 | useBrowserSurfaceStore.getState().presentContent(tabId, sourceContent); |
| 39 | |
| 40 | const fittedLease = acquireBrowserSurface(tabId, true); |
| 41 | useBrowserSurfaceStore.getState().presentContent(tabId, { |
| 42 | ...sourceContent, |
| 43 | width: 360, |
| 44 | height: 203, |
| 45 | scale: 0.28125, |
| 46 | }); |
| 47 | |
| 48 | expect(useBrowserSurfaceStore.getState().byTabId[tabId]?.fittedSourceContent).toEqual( |
| 49 | sourceContent, |
| 50 | ); |
| 51 | fittedLease.release(); |
| 52 | }); |
| 53 | |
| 54 | it("ignores updates and releases from a stale surface lease", () => { |
| 55 | const tabId = "leased-browser-surface"; |
| 56 | const staleRect = { x: 0, y: 0, width: 500, height: 700 }; |
| 57 | const liveRect = { x: 10, y: 20, width: 900, height: 640 }; |
| 58 | const staleLease = acquireBrowserSurface(tabId); |
| 59 | staleLease.present(staleRect, true); |
| 60 | |
| 61 | const liveLease = acquireBrowserSurface(tabId); |
| 62 | liveLease.present(liveRect, true); |
| 63 | expect(staleLease.present(staleRect, true)).toBe(false); |
| 64 | staleLease.release(); |
| 65 | |
| 66 | expect(useBrowserSurfaceStore.getState().byTabId[tabId]).toMatchObject({ |
| 67 | rect: liveRect, |
| 68 | visible: true, |
| 69 | }); |
| 70 | }); |
| 71 | }); |