lifecycle-chrome.e2e.ts 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. // Web e2e scenarios: lifecycle & chrome — the workspace-aware first-send
  2. // flow over the real wire, reload recovery, and the dark-mode token cascade.
  3. // One tiny recorded turn (text-only) drives the whole spec: the empty-state
  4. // hero materializes a real Workspace + Session on first send (the jsdom
  5. // workspace-flow suite pins the object-layer state machine over the fixture
  6. // client; THIS spec pins the same flow through HTTP RPC + WebSocket + the host
  7. // gateway), reload replays everything from the log (zero further model
  8. // calls), and the theme scenario proves the shipped dark palette actually
  9. // cascades: attribute -> alias token flip -> painted surface change. No
  10. // theme/layout golden: aria snapshots are color-blind (lane scope: the
  11. // browser-e2e-lane Agent Note); the hero's waiting state gets the one golden
  12. // here.
  13. import { readFile } from 'node:fs/promises'
  14. import { fileURLToPath } from 'node:url'
  15. import { join } from 'node:path'
  16. import type { Browser, Page, WebSocketRoute } from 'playwright'
  17. import { chromium } from 'playwright'
  18. import { afterAll, beforeAll, describe, expect, it, onTestFailed } from 'vitest'
  19. import type { SessionEvent } from '@deepseek-ai/dsh-session'
  20. import {
  21. acknowledgeReloadConnectionLoss, assertFixtureInventory, captureExpandedTurnProcessAria,
  22. captureStableAria, compareOrRefreshGolden, fixtureUserPrompts,
  23. launchWebScaffold, recordFixture, watchConsole, webSnapshotMode, type WebScaffold,
  24. } from './scaffold.ts'
  25. import {
  26. connectFreshWorkspace, newEnglishPage, saveFailureShot, writeComposerDraft,
  27. } from './support.ts'
  28. const SNAPSHOT_DIR = fileURLToPath(new URL('../../../snapshots/web/lifecycle-chrome', import.meta.url))
  29. const FIXTURE = join(SNAPSHOT_DIR, 'session.v2.jsonl')
  30. const REPLAY_OVERRIDE = join(SNAPSHOT_DIR, 'replay.override.json')
  31. const HERO_EXPECTED = join(SNAPSHOT_DIR, 'hero.expected.md')
  32. const COMMAND_MENU_EXPECTED = join(SNAPSHOT_DIR, 'command-menu.expected.md')
  33. const FUZZY_COMMAND_MENU_EXPECTED = join(SNAPSHOT_DIR, 'command-menu-fuzzy.expected.md')
  34. const PLAN_ACTIVE_EXPECTED = join(SNAPSHOT_DIR, 'plan-active.expected.md')
  35. const CONNECTION_ERROR_EXPECTED = join(SNAPSHOT_DIR, 'connection-error.expected.md')
  36. // Post-reload golden: the same settled conversation rebuilt purely from
  37. // persistence + history — byte-equal rendering is exactly the recovery claim.
  38. const RELOADED_EXPECTED = join(SNAPSHOT_DIR, 'reloaded.expected.md')
  39. const RELOADED_EXPANDED_EXPECTED = join(SNAPSHOT_DIR, 'reloaded-expanded.expected.md')
  40. const MODE = webSnapshotMode()
  41. const PROMPT = 'Reply with the single word LIGHTHOUSE and stop.'
  42. const REPLAY_PACE_MS = 100
  43. describe('web e2e: lifecycle & chrome (workspace flow / reload / dark mode)', () => {
  44. let scaffold: WebScaffold
  45. let browser: Browser
  46. let page: Page
  47. let tripwire: ReturnType<typeof watchConsole>
  48. const sessionEvents: SessionEvent[] = []
  49. beforeAll(async () => {
  50. scaffold = await launchWebScaffold(MODE === 'record'
  51. ? {}
  52. : { replayFixture: FIXTURE, replayOverride: REPLAY_OVERRIDE, paceMs: REPLAY_PACE_MS })
  53. scaffold.ctx.on('session/event', (_session, event: SessionEvent) => { sessionEvents.push(event) })
  54. browser = await chromium.launch()
  55. page = await newEnglishPage(browser)
  56. tripwire = watchConsole(page)
  57. await page.goto(scaffold.authenticatedUrl, { waitUntil: 'load' })
  58. await page.waitForSelector('[class*="frame"]', { timeout: 30_000 })
  59. // Fresh world: connect a Workspace so the composer scenarios start live.
  60. await connectFreshWorkspace(page, scaffold.workspaceCwd)
  61. }, 120_000)
  62. afterAll(async () => {
  63. await browser?.close()
  64. await scaffold?.close()
  65. })
  66. it.skipIf(MODE === 'record')('opens the shared slash menu from plus with only Command candidates', async () => {
  67. onTestFailed(() => saveFailureShot(page, 'web-e2e-command-menu-launcher'))
  68. const launcher = page.getByRole('button', { name: 'Commands' })
  69. await launcher.click()
  70. const menu = page.getByRole('listbox', { name: 'Trigger suggestions' })
  71. await menu.waitFor({ timeout: 10_000 })
  72. const snapshot = await captureStableAria(page, '[role="listbox"]', scaffold.workspaceCwd)
  73. await compareOrRefreshGolden(COMMAND_MENU_EXPECTED, snapshot, MODE)
  74. expect(snapshot).toContain('text: Commands')
  75. expect(snapshot).not.toContain('text: Skills')
  76. expect(snapshot).not.toContain('text: Subagents')
  77. const launchedBox = await menu.boundingBox()
  78. await page.locator('[data-composer-input]').first().press('Escape')
  79. await expect.poll(() => menu.count()).toBe(0)
  80. const input = page.locator('[data-composer-input]').first()
  81. await writeComposerDraft(page, input, '/')
  82. await menu.waitFor({ timeout: 10_000 })
  83. const typedBox = await menu.boundingBox()
  84. expect(launchedBox).not.toBeNull()
  85. expect(typedBox).not.toBeNull()
  86. expect(Math.abs(launchedBox!.x - typedBox!.x)).toBeLessThan(1)
  87. expect(Math.abs(
  88. launchedBox!.y + launchedBox!.height - typedBox!.y - typedBox!.height,
  89. )).toBeLessThan(1)
  90. await writeComposerDraft(page, input, '/cpt')
  91. await expect.poll(() => menu.getByRole('option').allTextContents()).toEqual([
  92. 'compactCompact older conversation history',
  93. ])
  94. const fuzzySnapshot = await captureStableAria(page, '[role="listbox"]', scaffold.workspaceCwd)
  95. await compareOrRefreshGolden(FUZZY_COMMAND_MENU_EXPECTED, fuzzySnapshot, MODE)
  96. await writeComposerDraft(page, input, '')
  97. await expect.poll(() => menu.count()).toBe(0)
  98. })
  99. it.skipIf(MODE === 'record')('shows active Plan as the warn-state status action', async () => {
  100. const activeScaffold = await launchWebScaffold()
  101. const activePage = await newEnglishPage(browser)
  102. const activeTripwire = watchConsole(activePage)
  103. try {
  104. await activePage.goto(activeScaffold.authenticatedUrl, { waitUntil: 'load' })
  105. await activePage.waitForSelector('[class*="frame"]', { timeout: 30_000 })
  106. await connectFreshWorkspace(activePage, activeScaffold.workspaceCwd)
  107. const input = activePage.locator('[data-composer-input]').first()
  108. await activePage.getByRole('button', { name: 'Commands' }).click()
  109. const menu = activePage.getByRole('listbox', { name: 'Trigger suggestions' })
  110. await menu.waitFor({ timeout: 10_000 })
  111. await menu.getByRole('option', { name: 'plan Enter or leave plan mode' }).click()
  112. await expect.poll(() => input.textContent()).toBe('/plan ')
  113. await input.press('Enter')
  114. const planButton = activePage.getByRole('button', { name: 'Plan mode on, press to turn off' })
  115. await planButton.waitFor({ timeout: 10_000 })
  116. // The golden encodes an empty composer, and the button arriving does not
  117. // mean the submitted text is gone yet: under load the capture can catch
  118. // a textbox still holding `/plan`.
  119. await expect.poll(() => input.textContent(), { timeout: 10_000 }).toBe('')
  120. const planSnapshot = await captureStableAria(activePage, '[class*="frame"]', activeScaffold.workspaceCwd)
  121. await compareOrRefreshGolden(PLAN_ACTIVE_EXPECTED, planSnapshot, MODE)
  122. const planStyle = await planButton.evaluate((element) => {
  123. const probe = document.createElement('span')
  124. probe.style.color = 'var(--dsw-alias-state-warn-label)'
  125. probe.style.backgroundColor = 'var(--dsw-alias-state-warn-tertiary)'
  126. document.body.append(probe)
  127. const actual = getComputedStyle(element)
  128. const reference = getComputedStyle(probe)
  129. const result = {
  130. color: actual.color,
  131. backgroundColor: actual.backgroundColor,
  132. borderRadius: actual.borderRadius,
  133. fontSize: actual.fontSize,
  134. referenceColor: reference.color,
  135. referenceBackgroundColor: reference.backgroundColor,
  136. }
  137. probe.remove()
  138. return result
  139. })
  140. expect(planStyle.color).toBe(planStyle.referenceColor)
  141. expect(planStyle.backgroundColor).toBe(planStyle.referenceBackgroundColor)
  142. expect(planStyle.borderRadius).toBe('999px')
  143. expect(planStyle.fontSize).toBe('13px')
  144. await planButton.click()
  145. await expect.poll(() => planButton.count()).toBe(0)
  146. expect(activeTripwire.pageErrors).toEqual([])
  147. expect(activeTripwire.warnings).toEqual([])
  148. } catch (error) {
  149. await saveFailureShot(activePage, 'web-e2e-plan-active').catch(() => undefined)
  150. throw error
  151. } finally {
  152. await activePage.close()
  153. await activeScaffold.close()
  154. }
  155. })
  156. it('sends the first prompt from the empty-state hero (all modes)', async () => {
  157. onTestFailed(() => saveFailureShot(page, 'web-e2e-lifecycle-send'))
  158. if (MODE !== 'record') {
  159. expect(fixtureUserPrompts(await readFile(FIXTURE, 'utf8'))).toEqual([PROMPT])
  160. }
  161. // The blank frame renders the hero, not the resident composer: the
  162. // headline plus the guidance placeholder are the empty state's anchors.
  163. await expect.poll(() => page.getByText('Into the Unknown', { exact: false }).count(), { timeout: 15_000 }).toBe(1)
  164. const input = page.locator('[data-composer-input]').first()
  165. await input.waitFor({ timeout: 10_000 })
  166. if (MODE !== 'record') {
  167. await page.getByText('Into the Unknown', { exact: false }).hover()
  168. await expect.poll(() => page.getByRole('tooltip').count()).toBe(0)
  169. // Golden of the hero's stable waiting state (captured before any send;
  170. // the conversation-region goldens belong to the other scenarios).
  171. const snapshot = await captureStableAria(page, '[class*="frame"]', scaffold.workspaceCwd)
  172. await compareOrRefreshGolden(HERO_EXPECTED, snapshot, MODE)
  173. }
  174. const settled = scaffold.whenTurnSettled()
  175. await writeComposerDraft(page, input, PROMPT)
  176. const observeTurn = async () => {
  177. const originalViewport = page.viewportSize() ?? { width: 1680, height: 1000 }
  178. if (MODE !== 'record') await page.setViewportSize({ width: 480, height: 1000 })
  179. try {
  180. await input.press('Enter')
  181. if (MODE !== 'record') {
  182. const liveTail = page.locator('[data-variant="think"][data-state="running"] [data-follow-end]')
  183. await expect.poll(async () => {
  184. if (await liveTail.count() !== 1) return false
  185. return await liveTail.evaluate((element) => {
  186. const text = element.firstElementChild
  187. if (!(text instanceof HTMLElement)) return false
  188. const viewport = element.getBoundingClientRect()
  189. const content = text.getBoundingClientRect()
  190. return content.width > viewport.width && Math.abs(content.right - viewport.right) <= 1
  191. })
  192. }, { timeout: 10_000, interval: 10 }).toBe(true)
  193. }
  194. return await settled
  195. } finally {
  196. if (MODE !== 'record') await page.setViewportSize(originalViewport)
  197. }
  198. }
  199. const sessionId = await observeTurn()
  200. if (MODE === 'record') {
  201. await recordFixture(scaffold, sessionId, FIXTURE)
  202. }
  203. }, 200_000)
  204. it.skipIf(MODE === 'record')('materialized a real Workspace and Session over the wire', async () => {
  205. onTestFailed(() => saveFailureShot(page, 'web-e2e-lifecycle-materialize'))
  206. // Browser: the sidebar tree now carries the auto-created workspace group
  207. // with its one session, and the opened session is the selected row. The
  208. // compact layout dropped group session counts, so the group row itself is
  209. // the barrier.
  210. await expect.poll(
  211. () => page.locator('[role="treeitem"][aria-expanded]').filter({ hasText: 'workspace' }).count(),
  212. { timeout: 15_000 },
  213. ).toBeGreaterThanOrEqual(1)
  214. await expect.poll(() => page.locator('[role="treeitem"][aria-selected="true"]').count(), { timeout: 10_000 }).toBe(1)
  215. await expect.poll(() => page.getByText('LIGHTHOUSE', { exact: true }).count(), { timeout: 15_000 }).toBeGreaterThanOrEqual(1)
  216. await expect.poll(() => page.getByText('Cache hit 99.5%', { exact: true }).count(), { timeout: 15_000 }).toBe(1)
  217. // Host: the session's durable header cwd is the folder the workspace
  218. // flow created and adopted (<workspaceCwd>/workspace) — the proof the
  219. // send went through workspace materialization rather than a bare
  220. // default-cwd session.
  221. const cwds = scaffold.ctx.sessions.list().map(session => session.header.cwd)
  222. expect(cwds).toEqual([join(scaffold.workspaceCwd, 'workspace')])
  223. const turnEnds = sessionEvents.filter(e => e.type === 'turn/end')
  224. expect(turnEnds).toHaveLength(1)
  225. expect((turnEnds[0] as SessionEvent & { data: { reason: { kind: string } } }).data.reason.kind).toBe('completed')
  226. }, 60_000)
  227. it.skipIf(MODE === 'record')('recovers the whole surface across a reload from the log alone', async () => {
  228. onTestFailed(() => saveFailureShot(page, 'web-e2e-lifecycle-reload'))
  229. const warningStart = tripwire.warnings.length
  230. await page.reload({ waitUntil: 'load' })
  231. await page.waitForSelector('[class*="frame"]', { timeout: 30_000 })
  232. acknowledgeReloadConnectionLoss(tripwire, warningStart)
  233. // Selection persisted (dsh.sessions.current) and history replayed: the
  234. // recorded turn re-renders from a Session Controller page with zero model calls —
  235. // the replay cursor was fully consumed before the reload, so any stray
  236. // request would fail the scenario loudly at close().
  237. await expect.poll(() => page.getByText('LIGHTHOUSE', { exact: true }).count(), { timeout: 15_000 }).toBeGreaterThanOrEqual(1)
  238. await expect.poll(() => page.locator('[role="treeitem"][aria-selected="true"]').count(), { timeout: 10_000 }).toBe(1)
  239. // Golden of the recovered conversation region: rebuilt from the log, it
  240. // must render the same settled transcript the live turn produced.
  241. const snapshot = await captureStableAria(page, '[class*="centerCol"]', scaffold.workspaceCwd)
  242. await compareOrRefreshGolden(RELOADED_EXPECTED, snapshot, MODE)
  243. const expanded = await captureExpandedTurnProcessAria(
  244. page,
  245. '[class*="centerCol"]',
  246. scaffold.workspaceCwd,
  247. )
  248. await compareOrRefreshGolden(RELOADED_EXPANDED_EXPECTED, expanded, MODE)
  249. expect(tripwire.pageErrors).toEqual([])
  250. }, 90_000)
  251. it.skipIf(MODE === 'record')('cascades the dark theme from the body attribute to painted surfaces', async () => {
  252. onTestFailed(() => saveFailureShot(page, 'web-e2e-lifecycle-dark'))
  253. // This scenario pins the ThemeRuntime's DOM contract directly (the
  254. // body[data-ds-dark-theme] attribute -> stylesheet cascade); the REAL
  255. // user gesture above it (Settings -> Appearance cubes) is owned by
  256. // settings-chrome.e2e.ts. Driving the attribute here keeps the cascade
  257. // pinned independently of the settings surface's own lifecycle.
  258. const sample = async (): Promise<{ token: string; sidebarBg: string; bodyBg: string }> =>
  259. await page.evaluate(() => {
  260. const sidebar = document.querySelector('[class*="sidebar"], [class*="rail"]') ?? document.body
  261. return {
  262. token: getComputedStyle(document.body).getPropertyValue('--dsw-alias-bg-base').trim(),
  263. sidebarBg: getComputedStyle(sidebar).backgroundColor,
  264. bodyBg: getComputedStyle(document.body).backgroundColor,
  265. }
  266. })
  267. const light = await sample()
  268. await page.evaluate(() => { document.body.setAttribute('data-ds-dark-theme', '') })
  269. const dark = await sample()
  270. // The alias token itself must flip — the cascade's root fact.
  271. expect(dark.token).not.toBe(light.token)
  272. // And a real painted surface must consume it (not just variables in a
  273. // void): at least one of the sampled backgrounds repaints.
  274. expect(dark.sidebarBg !== light.sidebarBg || dark.bodyBg !== light.bodyBg).toBe(true)
  275. // Removing the attribute restores the light values exactly (the palettes
  276. // live in one stylesheet; activation is attribute-only by design).
  277. await page.evaluate(() => { document.body.removeAttribute('data-ds-dark-theme') })
  278. const restored = await sample()
  279. expect(restored).toEqual(light)
  280. expect(tripwire.pageErrors).toEqual([])
  281. }, 60_000)
  282. it.skipIf(MODE === 'record')('shows automatic and user-requested connection recovery beside Settings', async () => {
  283. const recoveryPage = await newEnglishPage(browser)
  284. const recoveryTripwire = watchConsole(recoveryPage)
  285. const sockets: WebSocketRoute[] = []
  286. let rejectConnections = false
  287. await recoveryPage.routeWebSocket('**/api/remote.mux', (route) => {
  288. sockets.push(route)
  289. if (rejectConnections) {
  290. void route.close({ code: 4001, reason: 'connection recovery test' })
  291. return
  292. }
  293. route.connectToServer()
  294. })
  295. onTestFailed(() => saveFailureShot(recoveryPage, 'web-e2e-connection-recovery'))
  296. try {
  297. await recoveryPage.goto(scaffold.authenticatedUrl, { waitUntil: 'load' })
  298. await recoveryPage.waitForSelector('[class*="frame"]', { timeout: 30_000 })
  299. await expect.poll(() => sockets.length).toBe(1)
  300. rejectConnections = true
  301. await recoveryPage.context().setOffline(true)
  302. await expect.poll(() => recoveryPage.evaluate(() => navigator.onLine)).toBe(false)
  303. const offline = recoveryPage.getByRole('button', {
  304. name: 'Disconnected, reconnect now', exact: true,
  305. })
  306. await offline.waitFor({ timeout: 2_000 })
  307. await recoveryPage.waitForTimeout(750)
  308. expect(sockets).toHaveLength(1)
  309. await recoveryPage.context().setOffline(false)
  310. await expect.poll(() => recoveryPage.evaluate(() => navigator.onLine)).toBe(true)
  311. const connecting = recoveryPage.getByRole('button', {
  312. name: 'Connecting, restart now', exact: true,
  313. })
  314. await connecting.waitFor({ timeout: 10_000 })
  315. expect(await connecting.innerText()).toMatch(/^Connecting\.{1,3}$/)
  316. const connectingGeometry = await connectionIndicatorGeometry(connecting)
  317. expect(await connectionIndicatorTextAlignment(connecting)).toBe('left')
  318. await connecting.hover()
  319. expect(await connecting.innerText()).toBe('Reconnect now')
  320. expect(await connectionIndicatorGeometry(connecting)).toEqual(connectingGeometry)
  321. await recoveryPage.mouse.move(0, 0)
  322. await expect.poll(() => sockets.length, { timeout: 40_000 }).toBe(7)
  323. const indicator = recoveryPage.getByRole('button', {
  324. name: 'Disconnected, reconnect now', exact: true,
  325. })
  326. await indicator.waitFor({ timeout: 10_000 })
  327. expect(await connectionIndicatorGeometry(indicator)).toEqual(connectingGeometry)
  328. expect(await connectionIndicatorTextAlignment(indicator)).toBe('left')
  329. const snapshot = await captureStableAria(recoveryPage, '[class*="footArea"]', scaffold.workspaceCwd)
  330. await compareOrRefreshGolden(CONNECTION_ERROR_EXPECTED, snapshot, MODE)
  331. const style = await indicator.evaluate((element) => {
  332. const probe = document.createElement('span')
  333. probe.style.color = 'var(--dsw-alias-state-warn-label)'
  334. probe.style.backgroundColor = 'var(--dsw-alias-state-warn-tertiary)'
  335. document.body.append(probe)
  336. const actual = getComputedStyle(element)
  337. const reference = getComputedStyle(probe)
  338. const result = {
  339. background: actual.backgroundColor,
  340. color: actual.color,
  341. referenceBackground: reference.backgroundColor,
  342. referenceColor: reference.color,
  343. }
  344. probe.remove()
  345. return result
  346. })
  347. expect(style.background).toBe(style.referenceBackground)
  348. expect(style.color).toBe(style.referenceColor)
  349. expect(await indicator.locator('svg').count()).toBe(1)
  350. expect(await indicator.getAttribute('title')).toBeNull()
  351. const idleBackground = await indicator.evaluate(element => getComputedStyle(element).backgroundColor)
  352. await indicator.hover()
  353. expect(await indicator.innerText()).toBe('Reconnect now')
  354. const hoverBackground = await indicator.evaluate(element => getComputedStyle(element).backgroundColor)
  355. expect(hoverBackground).toBe(idleBackground)
  356. await recoveryPage.mouse.down()
  357. await expect.poll(() => indicator.evaluate(element => getComputedStyle(element).backgroundColor))
  358. .not.toBe(hoverBackground)
  359. rejectConnections = false
  360. await recoveryPage.mouse.up()
  361. await expect.poll(() => sockets.length).toBe(8)
  362. const recovered = recoveryPage.getByRole('status')
  363. await recovered.waitFor({ timeout: 10_000 })
  364. expect(await recovered.innerText()).toBe('Connected')
  365. expect(await connectionIndicatorGeometry(recovered)).toEqual(connectingGeometry)
  366. expect(await connectionIndicatorTextAlignment(recovered)).toBe('left')
  367. await recovered.waitFor({ state: 'detached', timeout: 5_000 })
  368. expect(recoveryTripwire.pageErrors).toEqual([])
  369. expect(recoveryTripwire.warnings.filter(warning => /connection lost, retry #[1-6]/i.test(warning)))
  370. .toHaveLength(7)
  371. } finally {
  372. await recoveryPage.close()
  373. }
  374. }, 60_000)
  375. it.skipIf(MODE === 'record')('keeps the fixture inventory closed', async () => {
  376. expect(tripwire.warnings).toEqual([])
  377. await assertFixtureInventory(SNAPSHOT_DIR, [
  378. 'session.v2.jsonl', 'replay.override.json', 'command-menu.expected.md',
  379. 'command-menu-fuzzy.expected.md', 'connection-error.expected.md', 'hero.expected.md', 'plan-active.expected.md',
  380. 'reloaded.expected.md', 'reloaded-expanded.expected.md',
  381. ])
  382. })
  383. })
  384. async function connectionIndicatorGeometry(locator: ReturnType<Page['getByRole']>): Promise<{
  385. readonly outer: readonly number[]
  386. readonly icon: readonly number[]
  387. readonly label: readonly number[]
  388. }> {
  389. return await locator.evaluate((element) => {
  390. const outer = element.getBoundingClientRect()
  391. const icon = element.children.item(0)?.getBoundingClientRect()
  392. const label = element.children.item(1)?.getBoundingClientRect()
  393. if (icon === undefined || label === undefined) throw new Error('connection indicator children missing')
  394. const rounded = (values: readonly number[]): readonly number[] => values.map(value => Math.round(value * 100) / 100)
  395. return {
  396. outer: rounded([outer.x, outer.y, outer.width, outer.height]),
  397. icon: rounded([icon.x - outer.x, icon.y - outer.y, icon.width, icon.height]),
  398. label: rounded([label.x - outer.x, label.y - outer.y, label.width, label.height]),
  399. }
  400. })
  401. }
  402. async function connectionIndicatorTextAlignment(
  403. locator: ReturnType<Page['getByRole']>,
  404. ): Promise<string> {
  405. return await locator.evaluate((element) => {
  406. const label = element.children.item(1)
  407. if (label === null) throw new Error('connection indicator label missing')
  408. return getComputedStyle(label).textAlign
  409. })
  410. }