78 lines · 2.4 KB · TypeScript
RawDownload
import { beforeEach, describe, expect, it } from "vite-plus/test"; import {  acquireBrowserSurface,  resolveBrowserSurfacePanelRect,  useBrowserSurfaceStore,} from "./browserSurfaceStore"; describe("browserSurfaceStore", () => {  beforeEach(() => {    useBrowserSurfaceStore.setState({ byTabId: {} });  });   it("tracks content dimensions for a browser that has never been visible", () => {    const tabId = "hidden-browser-surface-content-test";    useBrowserSurfaceStore.getState().presentContent(tabId, {      x: 0,      y: 0,      width: 393,      height: 852,      scale: 1,      scrollLeft: 0,      scrollTop: 0,    });     expect(useBrowserSurfaceStore.getState().byTabId[tabId]).toMatchObject({      rect: null,      visible: false,      content: { width: 393, height: 852 },    });  });   it("uses the live panel rect for a hidden background tab", () => {    const staleRect = { x: 0, y: 0, width: 500, height: 700 };    const liveRect = { x: 10, y: 20, width: 900, height: 640 };    expect(      resolveBrowserSurfacePanelRect(        {          hidden: { rect: staleRect, visible: false, content: null, updatedAt: 1, owner: null },          active: { rect: liveRect, visible: true, content: null, updatedAt: 2, owner: null },        },        "hidden",      ),    ).toEqual(liveRect);  });   it("ignores updates and releases from a stale surface lease", () => {    const tabId = "leased-browser-surface";    const staleRect = { x: 0, y: 0, width: 500, height: 700 };    const liveRect = { x: 10, y: 20, width: 900, height: 640 };    const staleLease = acquireBrowserSurface(tabId);    staleLease.present(staleRect, true);     const liveLease = acquireBrowserSurface(tabId);    liveLease.present(liveRect, true);    staleLease.present(staleRect, true);    staleLease.release();     expect(useBrowserSurfaceStore.getState().byTabId[tabId]).toMatchObject({      rect: liveRect,      visible: true,    });  });   it("hides a surface when its current lease is released", () => {    const tabId = "released-browser-surface";    const lease = acquireBrowserSurface(tabId);    lease.present({ x: 10, y: 20, width: 900, height: 640 }, true);     lease.release();    lease.present({ x: 0, y: 0, width: 1, height: 1 }, true);     expect(useBrowserSurfaceStore.getState().byTabId[tabId]).toMatchObject({      visible: false,      owner: null,    });  });});