Skip to content
Merged
35 changes: 23 additions & 12 deletions tests/e2e/tabs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,22 @@ function tabLocator(page: Page, tabId: string) {
return page.locator(`${SORTABLE_TAB}[data-tab-id="${tabId}"]`).first()
}

async function closeTabFromTabBar(page: Page, tabId: string): Promise<void> {
const tab = tabLocator(page, tabId)
await tab.hover()
await tab.getByRole('button', { name: /^Close tab /i }).click()
const confirmation = page.getByRole('dialog', { name: 'Stop running command?' })

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This hardcodes the command copy variant, whereas the sibling specs (terminal-tab-close-running-confirm.spec.ts, terminal-tab-close-running-confirm-mouse.spec.ts) match both Stop running command?|Stop this agent? via a closeDialogTitle regex. Correct for the two call sites here (both create plain terminal tabs), but a future agent-tab close routed through this helper would time out rather than match. Consider matching the canonical regex.

// A shell still starting under load may require the running-command confirmation.
await expect
.poll(async () => (await confirmation.isVisible()) || (await tab.count()) === 0, {
timeout: 5_000
})
.toBe(true)
if (await confirmation.isVisible()) {
await confirmation.getByRole('button', { name: 'Stop and Close', exact: true }).click()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Wait for tab removal after the confirmation click.

When the confirmation is visible, the poll stops before the tab is removed. After Stop and Close is clicked, this helper returns without waiting for tab.count() === 0. The callers can then measure stale tab state during the close animation. Add a second poll after the confirmation click.

Proposed fix
   if (await confirmation.isVisible()) {
     await confirmation.getByRole('button', { name: 'Stop and Close', exact: true }).click()
   }
+  await expect.poll(async () => (await tab.count()) === 0, {
+    timeout: 5_000,
+  }).toBe(true)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
await confirmation.getByRole('button', { name: 'Stop and Close', exact: true }).click()
await confirmation.getByRole('button', { name: 'Stop and Close', exact: true }).click()
}
await expect.poll(async () => (await tab.count()) === 0, {
timeout: 5_000,
}).toBe(true)

}
}

/** Count rendered tabs in the tab bar (user-visible, not store-level). */
async function countRenderedTabs(page: Page): Promise<number> {
return page.locator(SORTABLE_TAB).count()
Expand Down Expand Up @@ -73,6 +89,8 @@ test.describe('Tabs', () => {
await waitForStartupWorktreeRefresh(orcaPage)
await waitForActiveWorktree(orcaPage)
await ensureTerminalVisible(orcaPage)
const initialTabId = (await getActiveTabId(orcaPage))!
await expect(tabLocator(orcaPage, initialTabId)).toBeVisible()
})

/**
Expand All @@ -94,7 +112,7 @@ test.describe('Tabs', () => {
// Why: the "+" dropdown uses Radix <DropdownMenuItem>, which exposes the
// label text as the accessible name once the menu is open.
const newTerminalMenuItem = orcaPage.getByRole('menuitem', { name: /New Terminal/i }).first()
await newTerminalMenuItem.click({ force: true })
await newTerminalMenuItem.click()
await expect(newTerminalMenuItem).toBeHidden({ timeout: 3_000 })

// Final assertion is on the rendered tab count — the tab bar itself must
Expand Down Expand Up @@ -138,8 +156,7 @@ test.describe('Tabs', () => {

await orcaPage.getByRole('button', { name: 'New tab' }).click({ force: true })
const newMarkdownMenuItem = orcaPage.getByRole('menuitem', { name: /New Markdown/i }).first()
await newMarkdownMenuItem.click({ force: true })
await expect(newMarkdownMenuItem).toBeHidden({ timeout: 3_000 })
await newMarkdownMenuItem.click()

// Why: require an id that did not exist before the click, so an already-open
// Markdown file can't satisfy the assertions (or be deleted by cleanup), and
Expand All @@ -161,6 +178,7 @@ test.describe('Tabs', () => {

const editor = orcaPage.locator('.rich-markdown-editor')
await expect(editor).toBeVisible({ timeout: 25_000 })
await expect(newMarkdownMenuItem).toBeHidden({ timeout: 3_000 })

await expect
.poll(() => editor.evaluate((element) => document.activeElement === element), {
Expand Down Expand Up @@ -519,12 +537,7 @@ test.describe('Tabs', () => {
const tabsBefore = await countRenderedTabs(orcaPage)
const activeId = await getActiveTabId(orcaPage)
expect(activeId).not.toBeNull()
const activeTab = tabLocator(orcaPage, activeId!)
// Why: hover the tab first so the close button reveals its hover style.
// The button is interactive regardless but hovering matches real user
// behaviour and keeps click coordinates stable.
await activeTab.hover()
await activeTab.getByRole('button', { name: /^Close tab /i }).click()
await closeTabFromTabBar(orcaPage, activeId!)

await expect
.poll(() => countRenderedTabs(orcaPage), {
Expand Down Expand Up @@ -562,9 +575,7 @@ test.describe('Tabs', () => {
const activeTabBefore = await getActiveTabId(orcaPage)
expect(activeTabBefore).not.toBeNull()

const activeTab = tabLocator(orcaPage, activeTabBefore!)
await activeTab.hover()
await activeTab.getByRole('button', { name: /^Close tab /i }).click()
await closeTabFromTabBar(orcaPage, activeTabBefore!)

// Final DOM assertion: some *other* tab element now carries data-active.
await expect
Expand Down
Loading