|
| 1 | +import { test, expect } from './fixtures/server' |
| 2 | + |
| 3 | +// docs/goals/0015-summon-quick-invoke.md's inline-hotkey-hint remainder: |
| 4 | +// the tab-overflow dropdown (app/WorkTabShell.tsx) now shows each |
| 5 | +// bindable item's live shortcut (app/HotkeyHint.tsx, data-testid |
| 6 | +// "hotkey-hint") next to it -- Chrome's own "Search Tabs" pattern, the |
| 7 | +// owner's explicit ask -- and "Close other tabs"/"Close all tabs" carry |
| 8 | +// REAL default bindings (⌘⌥W / ⌘⇧W, shared/commands.ts's |
| 9 | +// tab.closeOthers/tab.closeAll), not just a display-only label. |
| 10 | + |
| 11 | +async function openTwoNewWorkflowTabs(page: import('@playwright/test').Page) { |
| 12 | + await page.goto('/') |
| 13 | + await page.getByRole('link', { name: 'Workflows' }).click() |
| 14 | + // Meta+n (workflow.new), not clicking the page's own "new-workflow" |
| 15 | + // button twice -- the first click opens a workflow-new tab that |
| 16 | + // covers the Workflows list panel (and its button) entirely, so a |
| 17 | + // second click on the same locator would hang waiting for an element |
| 18 | + // that's no longer visible. Cmd+N still works from inside an already- |
| 19 | + // open workflow-new tab (shared/commands.ts's isWorkflowsArea also |
| 20 | + // treats an active workflow-edit/-new tab as "in the Workflows area"), |
| 21 | + // matching e2e/keymap.spec.ts's own "Ctrl+Tab / Ctrl+Shift+Tab" test. |
| 22 | + await page.keyboard.press('Meta+n') |
| 23 | + await page.keyboard.press('Meta+n') |
| 24 | + await expect(page.getByRole('tab', { name: 'New workflow' })).toHaveCount(2) |
| 25 | +} |
| 26 | + |
| 27 | +test('the tab-overflow dropdown shows Close-other/Close-all inline hints, and Cmd+Shift+W actually closes every open tab', async ({ page }) => { |
| 28 | + await openTwoNewWorkflowTabs(page) |
| 29 | + |
| 30 | + const overflow = page.getByTestId('work-tab-overflow') |
| 31 | + await overflow.click() |
| 32 | + |
| 33 | + const closeOthersItem = page.getByRole('menuitem', { name: 'Close other tabs' }) |
| 34 | + const closeAllItem = page.getByRole('menuitem', { name: 'Close all tabs' }) |
| 35 | + await expect(closeOthersItem).toBeVisible() |
| 36 | + await expect(closeAllItem).toBeVisible() |
| 37 | + // shared/keybinding.ts's formatCombo output for each command's real |
| 38 | + // default binding -- read live off shared/commands.ts + the store's |
| 39 | + // keybindingOverrides via app/HotkeyHint.tsx, not a hardcoded label. |
| 40 | + await expect(closeOthersItem.getByTestId('hotkey-hint')).toHaveText('⌘⌥W') |
| 41 | + await expect(closeAllItem.getByTestId('hotkey-hint')).toHaveText('⌘⇧W') |
| 42 | + |
| 43 | + await page.keyboard.press('Escape') |
| 44 | + await expect(page.getByRole('menu')).toHaveCount(0) |
| 45 | + |
| 46 | + // The shortcut is real, not just displayed: Cmd+Shift+W (tab.closeAll) |
| 47 | + // drops every open work tab, back to just the pinned Workflows page |
| 48 | + // tab -- the overflow button itself disappears too (shown only at 2+ |
| 49 | + // work tabs). |
| 50 | + await page.keyboard.press('Meta+Shift+w') |
| 51 | + await expect(page.getByRole('tab')).toHaveCount(1) |
| 52 | + await expect(page.getByRole('tab', { name: 'Workflows' })).toBeVisible() |
| 53 | + await expect(overflow).toHaveCount(0) |
| 54 | +}) |
| 55 | + |
| 56 | +test('Cmd+Option+W (tab.closeOthers) closes every tab except the active one', async ({ page }) => { |
| 57 | + await openTwoNewWorkflowTabs(page) |
| 58 | + |
| 59 | + // The second 'New workflow' tab opened is the active one (store.ts's |
| 60 | + // sameWorkTarget never reuses a workflow-new tab, matching keymap.spec.ts's |
| 61 | + // own "Ctrl+Tab / Ctrl+Shift+Tab" test) -- tab.closeOthers keeps it and |
| 62 | + // drops the first. |
| 63 | + await page.keyboard.press('Meta+Alt+w') |
| 64 | + await expect(page.getByRole('tab', { name: 'New workflow' })).toHaveCount(1) |
| 65 | + await expect(page.getByRole('tab', { name: 'New workflow' })).toHaveAttribute('aria-selected', 'true') |
| 66 | + |
| 67 | + // Cleanup. |
| 68 | + await page.getByRole('button', { name: 'Close tab' }).click() |
| 69 | + await expect(page.getByRole('tab', { name: 'New workflow' })).toHaveCount(0) |
| 70 | +}) |
| 71 | + |
| 72 | +test('Settings: rebinding Close other tabs updates the SAME inline hint the tab-overflow dropdown renders (O(1) single source of truth)', async ({ page }) => { |
| 73 | + await openTwoNewWorkflowTabs(page) |
| 74 | + |
| 75 | + const overflow = page.getByTestId('work-tab-overflow') |
| 76 | + await overflow.click() |
| 77 | + const closeOthersItem = page.getByRole('menuitem', { name: 'Close other tabs' }) |
| 78 | + await expect(closeOthersItem.getByTestId('hotkey-hint')).toHaveText('⌘⌥W') |
| 79 | + await page.keyboard.press('Escape') |
| 80 | + |
| 81 | + // Rebind tab.closeOthers off its ⌘⌥W default onto Ctrl+Shift+O (no |
| 82 | + // collision with any other command's default or a RESERVED_COMBOS |
| 83 | + // entry, shared/keybinding.ts). |
| 84 | + await page.getByRole('button', { name: 'Settings' }).click() |
| 85 | + const row = page.locator('[data-testid="keymap-row"][data-command-id="tab.closeOthers"]') |
| 86 | + await expect(row.getByTestId('keymap-row-combo')).toHaveText('⌘⌥W') |
| 87 | + await row.getByTestId('keymap-row-combo').click() |
| 88 | + await page.keyboard.press('Control+Shift+O') |
| 89 | + await expect(row.getByTestId('keymap-row-combo')).toHaveText('⌃⇧O') |
| 90 | + |
| 91 | + // Back on Workflows, the tab-overflow dropdown's hint -- reading off |
| 92 | + // the exact same shared/store.ts keybindingOverrides Settings just |
| 93 | + // wrote -- reflects the new combo without any code path re-deriving |
| 94 | + // it independently. |
| 95 | + await page.getByRole('link', { name: 'Workflows' }).click() |
| 96 | + // Navigating via the sidebar resets activeWorkTabKey to null |
| 97 | + // (shared/store.ts's setView -- switching sections always drops back |
| 98 | + // to the pinned page tab) -- click into one of the still-open work |
| 99 | + // tabs to have a real "active" tab again, the same precondition |
| 100 | + // WorkTabShell's own "Close other tabs" item requires (its |
| 101 | + // `disabled={activeWorkTabKey === null}`). |
| 102 | + await page.getByRole('tab', { name: 'New workflow' }).first().click() |
| 103 | + await overflow.click() |
| 104 | + await expect(closeOthersItem.getByTestId('hotkey-hint')).toHaveText('⌃⇧O') |
| 105 | + await page.keyboard.press('Escape') |
| 106 | + |
| 107 | + // And the rebound combo is the one that's actually live now -- not |
| 108 | + // just displayed -- while the old default no longer does anything. |
| 109 | + await page.keyboard.press('Control+Shift+O') |
| 110 | + await expect(page.getByRole('tab', { name: 'New workflow' })).toHaveCount(1) |
| 111 | + |
| 112 | + // Cleanup: reset the override and close the remaining tab, so this |
| 113 | + // doesn't leak into any other spec sharing this worker's settings file |
| 114 | + // (.claude/rules/testing.md's within-file/within-worker discipline). |
| 115 | + await page.getByRole('button', { name: 'Settings' }).click() |
| 116 | + const rowAgain = page.locator('[data-testid="keymap-row"][data-command-id="tab.closeOthers"]') |
| 117 | + await rowAgain.getByTestId('keymap-row-reset').click() |
| 118 | + await expect(rowAgain.getByTestId('keymap-row-combo')).toHaveText('⌘⌥W') |
| 119 | + |
| 120 | + await page.getByRole('link', { name: 'Workflows' }).click() |
| 121 | + await page.getByRole('button', { name: 'Close tab' }).click() |
| 122 | + await expect(page.getByRole('tab', { name: 'New workflow' })).toHaveCount(0) |
| 123 | +}) |
0 commit comments