Skip to content

Commit 3a768fc

Browse files
committed
Go to path: E2E spec and ancestor-toast a11y test
- Add `GoToPathAncestorToastContent.a11y.test.ts` (tier-3), closing the `a11y-coverage` gap that was failing the suite. - Add one Playwright E2E spec `go-to-path.spec.ts`: opens the dialog via the command path, asserts an existing directory navigates the focused pane into it, and asserts a non-existent path lands on the nearest existing ancestor with the INFO toast.
1 parent 6b3e941 commit 3a768fc

2 files changed

Lines changed: 132 additions & 0 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { describe, it } from 'vitest'
2+
import { mount, tick } from 'svelte'
3+
import { expectNoA11yViolations } from '$lib/test-a11y'
4+
5+
import GoToPathAncestorToastContent from './GoToPathAncestorToastContent.svelte'
6+
7+
describe('GoToPathAncestorToastContent a11y', () => {
8+
it('renders with no a11y violations (with back-shortcut hint)', async () => {
9+
const target = document.createElement('div')
10+
document.body.appendChild(target)
11+
mount(GoToPathAncestorToastContent, {
12+
target,
13+
props: { requested: '/tmp/nope/a.txt', landed: '/tmp', backShortcut: '⌘[' },
14+
})
15+
await tick()
16+
await expectNoA11yViolations(target)
17+
})
18+
19+
it('renders with no a11y violations (no back-shortcut hint)', async () => {
20+
const target = document.createElement('div')
21+
document.body.appendChild(target)
22+
mount(GoToPathAncestorToastContent, {
23+
target,
24+
props: { requested: '/x/y', landed: '/', backShortcut: '' },
25+
})
26+
await tick()
27+
await expectNoA11yViolations(target)
28+
})
29+
})
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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

Comments
 (0)