|
| 1 | +import { expect, it } from "vitest"; |
| 2 | +import { |
| 3 | + controlUiBundledSettingsStorageKey, |
| 4 | + installMockGateway, |
| 5 | +} from "../test-helpers/control-ui-e2e.ts"; |
| 6 | +import { createControlUiE2eSuite } from "./control-ui-e2e-suite.test-support.ts"; |
| 7 | + |
| 8 | +const suite = createControlUiE2eSuite({ |
| 9 | + name: "Control UI dashboard side-panel selection", |
| 10 | + startServerBeforeBrowser: true, |
| 11 | +}); |
| 12 | + |
| 13 | +const sessionKey = "agent:main:dashboard"; |
| 14 | +const boardSnapshot = { |
| 15 | + sessionKey, |
| 16 | + revision: 1, |
| 17 | + tabs: [{ tabId: "main", title: "Main", position: 0, chatDock: "right" }], |
| 18 | + widgets: [], |
| 19 | +}; |
| 20 | + |
| 21 | +suite.define(() => { |
| 22 | + it("restores the previously selected side-panel tab", async () => { |
| 23 | + const context = await suite.browser.newContext({ viewport: { height: 900, width: 1280 } }); |
| 24 | + const page = await context.newPage(); |
| 25 | + const settingsKey = controlUiBundledSettingsStorageKey(suite.server.baseUrl); |
| 26 | + await page.addInitScript( |
| 27 | + ({ key, storageKey }) => { |
| 28 | + const settings = JSON.parse(localStorage.getItem(storageKey) ?? "{}") as Record< |
| 29 | + string, |
| 30 | + unknown |
| 31 | + >; |
| 32 | + settings.boardSessionViews = { [key]: { activeTabId: "main" } }; |
| 33 | + const sidebarSessionLayouts = |
| 34 | + settings.sidebarSessionLayouts && typeof settings.sidebarSessionLayouts === "object" |
| 35 | + ? (settings.sidebarSessionLayouts as Record<string, unknown>) |
| 36 | + : {}; |
| 37 | + settings.sidebarSessionLayouts = { |
| 38 | + ...sidebarSessionLayouts, |
| 39 | + [key]: sidebarSessionLayouts[key] ?? { |
| 40 | + columns: [ |
| 41 | + { |
| 42 | + id: "side-panel-column", |
| 43 | + side: "right", |
| 44 | + panels: [{ id: "terminal", slot: "terminal" }], |
| 45 | + activePanelId: "terminal", |
| 46 | + height: 360, |
| 47 | + width: 480, |
| 48 | + }, |
| 49 | + ], |
| 50 | + dock: "right", |
| 51 | + open: true, |
| 52 | + }, |
| 53 | + }; |
| 54 | + localStorage.setItem(storageKey, JSON.stringify(settings)); |
| 55 | + }, |
| 56 | + { key: sessionKey, storageKey: settingsKey }, |
| 57 | + ); |
| 58 | + await installMockGateway(page, { |
| 59 | + sessionKey, |
| 60 | + featureMethods: ["board.get", "chat.metadata", "chat.startup", "terminal.open"], |
| 61 | + methodResponses: { "board.get": boardSnapshot }, |
| 62 | + terminalEnabled: true, |
| 63 | + }); |
| 64 | + |
| 65 | + try { |
| 66 | + await page.goto(`${suite.server.baseUrl}dashboard`); |
| 67 | + await page.locator(".board-session-surface").waitFor(); |
| 68 | + const terminal = page.getByRole("tab", { name: "Terminal", exact: true }); |
| 69 | + const chat = page.getByRole("tab", { name: "Board chat", exact: true }); |
| 70 | + await expect.poll(() => terminal.getAttribute("aria-selected")).toBe("true"); |
| 71 | + |
| 72 | + await chat.click(); |
| 73 | + await expect.poll(() => chat.getAttribute("aria-selected")).toBe("true"); |
| 74 | + await page.reload(); |
| 75 | + await expect.poll(() => chat.getAttribute("aria-selected")).toBe("true"); |
| 76 | + } finally { |
| 77 | + await context.close(); |
| 78 | + } |
| 79 | + }); |
| 80 | +}); |
0 commit comments