|
| 1 | +/** |
| 2 | + * Acceptance test for "Go to path" (⌘G): open the dialog via the command |
| 3 | + * system, type a path, confirm with Enter, and verify the focused pane |
| 4 | + * navigated. Covers the two outcomes worth exercising end-to-end: |
| 5 | + * 1. Existing directory → the focused pane navigates into it. |
| 6 | + * 2. Non-existent path → the pane lands on the nearest existing ancestor and |
| 7 | + * an INFO toast appears. |
| 8 | + * |
| 9 | + * The clipboard-prefill and digit-jump flows are covered by unit tests |
| 10 | + * (`lib/go-to-path/*.test.ts`) and the manual smoke list — clipboard perms make |
| 11 | + * them brittle in E2E. See `lib/go-to-path/CLAUDE.md` for the full contract. |
| 12 | + */ |
| 13 | + |
| 14 | +import { test, expect } from './fixtures.js' |
| 15 | +import { ensureAppReady, dispatchMenuCommand, pressKey, getFixtureRoot, expectAndDismissToast } from './helpers.js' |
| 16 | +import { ensureMcpClient, mcpReadResource } from '../e2e-shared/mcp-client.js' |
| 17 | +import type { TauriPage, BrowserPageAdapter } from '@srsholmes/tauri-playwright' |
| 18 | + |
| 19 | +type PageLike = TauriPage | BrowserPageAdapter |
| 20 | + |
| 21 | +const GO_TO_PATH_DIALOG = '[data-dialog-id="go-to-path"]' |
| 22 | +const GO_TO_PATH_INPUT = `${GO_TO_PATH_DIALOG} input[aria-label="Path to go to"]` |
| 23 | + |
| 24 | +/** Opens the Go-to-path dialog through the same command path ⌘G and the menu use. */ |
| 25 | +async function openGoToPathDialog(tauriPage: PageLike): Promise<void> { |
| 26 | + await dispatchMenuCommand(tauriPage, 'nav.goToPath') |
| 27 | + await tauriPage.waitForSelector(GO_TO_PATH_INPUT, 3000) |
| 28 | +} |
| 29 | + |
| 30 | +/** |
| 31 | + * Reads the focused pane's active-tab path from the MCP `cmdr://state` |
| 32 | + * resource. We first read the top-level `focused:` field, then parse that |
| 33 | + * pane's `[active]` tab line, which carries the path in parentheses: |
| 34 | + * `- i:N id:... [active] ... (<path>)`. This is the same active-tab line |
| 35 | + * `search-open-in-pane.spec.ts` parses; it's synced independently of the |
| 36 | + * (sometimes-stale) `volume:` field. |
| 37 | + */ |
| 38 | +async function getFocusedPaneActiveTabPath(): Promise<string | null> { |
| 39 | + const state = await mcpReadResource('cmdr://state?compact=true') |
| 40 | + const focusedMatch = /^focused:\s*(left|right)/m.exec(state) |
| 41 | + if (focusedMatch === null) return null |
| 42 | + const pane = focusedMatch[1] |
| 43 | + const marker = `\n${pane}:\n` |
| 44 | + const idx = state.indexOf(marker) |
| 45 | + if (idx === -1) return null |
| 46 | + // The pane block runs until the next top-level YAML key (no leading spaces). |
| 47 | + const block = state.slice(idx + marker.length) |
| 48 | + const endIdx = block.search(/\n[a-z]/) |
| 49 | + const scoped = endIdx === -1 ? block : block.slice(0, endIdx) |
| 50 | + const m = /^\s+- i:\d+ id:\S+ \[active\][^\n]*\(([^)\n]+)\)\s*$/m.exec(scoped) |
| 51 | + return m?.[1] ?? null |
| 52 | +} |
| 53 | + |
| 54 | +/** Sets the dialog input value and fires `input` so the bound state updates. */ |
| 55 | +async function typeIntoGoToPath(tauriPage: PageLike, value: string): Promise<void> { |
| 56 | + await tauriPage.evaluate(`(function(){ |
| 57 | + var el = document.querySelector(${JSON.stringify(GO_TO_PATH_INPUT)}); |
| 58 | + if (!el) return; |
| 59 | + el.focus(); |
| 60 | + el.value = ${JSON.stringify(value)}; |
| 61 | + el.dispatchEvent(new Event('input', { bubbles: true })); |
| 62 | + })()`) |
| 63 | +} |
| 64 | + |
| 65 | +test.describe('Go to path (⌘G)', () => { |
| 66 | + test('typing an existing directory navigates the focused pane into it', async ({ tauriPage }) => { |
| 67 | + await ensureAppReady(tauriPage) |
| 68 | + await ensureMcpClient(tauriPage) |
| 69 | + |
| 70 | + // `ensureAppReady` leaves the left pane focused on `<fixtureRoot>/left`. |
| 71 | + // `left/sub-dir` is a real directory in the fixture tree. |
| 72 | + const targetDir = `${getFixtureRoot()}/left/sub-dir` |
| 73 | + |
| 74 | + await openGoToPathDialog(tauriPage) |
| 75 | + await typeIntoGoToPath(tauriPage, targetDir) |
| 76 | + // Enter on the input confirms the jump and closes the dialog. |
| 77 | + await pressKey(tauriPage, 'Enter') |
| 78 | + |
| 79 | + // The dialog closes on a successful (non-invalid) jump. |
| 80 | + await expect.poll(async () => (await tauriPage.count(GO_TO_PATH_DIALOG)) === 0, { timeout: 3000 }).toBeTruthy() |
| 81 | + // The focused pane is now inside the typed directory. |
| 82 | + await expect.poll(async () => getFocusedPaneActiveTabPath(), { timeout: 3000 }).toBe(targetDir) |
| 83 | + }) |
| 84 | + |
| 85 | + test('a non-existent path lands on the nearest ancestor and shows an INFO toast', async ({ tauriPage }) => { |
| 86 | + await ensureAppReady(tauriPage) |
| 87 | + await ensureMcpClient(tauriPage) |
| 88 | + |
| 89 | + const ancestor = `${getFixtureRoot()}/left` |
| 90 | + const nonExistent = `${ancestor}/nope-go-to-path-e2e/deeper/x.txt` |
| 91 | + |
| 92 | + await openGoToPathDialog(tauriPage) |
| 93 | + await typeIntoGoToPath(tauriPage, nonExistent) |
| 94 | + await pressKey(tauriPage, 'Enter') |
| 95 | + |
| 96 | + await expect.poll(async () => (await tauriPage.count(GO_TO_PATH_DIALOG)) === 0, { timeout: 3000 }).toBeTruthy() |
| 97 | + // The pane jumps to the nearest existing ancestor (the fixture's `left/`). |
| 98 | + await expect.poll(async () => getFocusedPaneActiveTabPath(), { timeout: 3000 }).toBe(ancestor) |
| 99 | + // The nearest-ancestor INFO toast appears. The wording is the user-facing |
| 100 | + // contract (see `GoToPathAncestorToastContent.svelte`). |
| 101 | + await expectAndDismissToast(tauriPage, 'so we took you to') |
| 102 | + }) |
| 103 | +}) |
0 commit comments