Skip to content

Commit 501f0bb

Browse files
committed
fix(vscode): target the Only Direct Neighbors menu item by its real role
The lineage settings entry is rendered by Headless UI as `<button role="menuitem">`, and an explicit role replaces the implicit one in the accessibility tree, so `getByRole('button')` never matched it and the toggle timed out. `findLineageFrame` also swept the page's iframes once. Webviews attach asynchronously, so a sweep that ran before the lineage webview existed returned null and failed the frame assertion outright. Waiting for the restored node count instead of a fixed 250ms replaces the last timing assumption in the test. Signed-off-by: Adegbite Ayoade <tripleaceme@gmail.com>
1 parent f513706 commit 501f0bb

1 file changed

Lines changed: 43 additions & 24 deletions

File tree

‎vscode/extension/tests/lineage_settings.spec.ts‎

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,39 @@ import { createPythonInterpreterSettingsSpecifier } from './utils_code_server'
1212
/**
1313
* Find the iframe that hosts the lineage UI (the one containing the
1414
* Settings cog button). Returns null if it can't be located.
15+
*
16+
* The webview iframes attach asynchronously, so a single sweep can run before
17+
* the lineage one exists and find nothing. The sweep is repeated until the
18+
* Settings button answers from one of them or `timeout` elapses.
1519
*/
16-
async function findLineageFrame(page: Page): Promise<FrameLocator | null> {
17-
const iframes = page.locator('iframe')
18-
const iframeCount = await iframes.count()
19-
20-
for (let i = 0; i < iframeCount; i++) {
21-
const contentFrame = iframes.nth(i).contentFrame()
22-
if (!contentFrame) continue
23-
const activeFrame = contentFrame.locator('#active-frame').contentFrame()
24-
if (!activeFrame) continue
25-
try {
26-
await activeFrame
27-
.getByRole('button', { name: 'Settings' })
28-
.waitFor({ timeout: 1000 })
29-
return activeFrame
30-
} catch {
31-
continue
20+
async function findLineageFrame(
21+
page: Page,
22+
timeout = 60_000,
23+
): Promise<FrameLocator | null> {
24+
const deadline = Date.now() + timeout
25+
26+
while (Date.now() < deadline) {
27+
const iframes = page.locator('iframe')
28+
const iframeCount = await iframes.count()
29+
30+
for (let i = 0; i < iframeCount; i++) {
31+
const contentFrame = iframes.nth(i).contentFrame()
32+
if (!contentFrame) continue
33+
const activeFrame = contentFrame.locator('#active-frame').contentFrame()
34+
if (!activeFrame) continue
35+
try {
36+
await activeFrame
37+
.getByRole('button', { name: 'Settings' })
38+
.waitFor({ timeout: 1000 })
39+
return activeFrame
40+
} catch {
41+
continue
42+
}
3243
}
44+
45+
// Nothing answered this time round; give the next webview a chance to
46+
// attach instead of spinning when the page has no iframes yet.
47+
await page.waitForTimeout(250)
3348
}
3449
return null
3550
}
@@ -97,9 +112,11 @@ test('Only Direct Neighbors toggle filters the lineage graph', async ({
97112
const nodesBefore = await lineageFrame.locator('.react-flow__node').count()
98113
expect(nodesBefore).toBeGreaterThan(0)
99114

100-
// Open the settings menu and toggle "Only Direct Neighbors"
115+
// Open the settings menu and toggle "Only Direct Neighbors". Headless UI
116+
// renders the entry as `<button role="menuitem">`, and the explicit role is
117+
// the one the accessibility tree reports.
101118
await lineageFrame.getByRole('button', { name: 'Settings' }).click()
102-
const toggle = lineageFrame.getByRole('button', {
119+
const toggle = lineageFrame.getByRole('menuitem', {
103120
name: 'Only Direct Neighbors',
104121
})
105122
await toggle.waitFor()
@@ -115,10 +132,12 @@ test('Only Direct Neighbors toggle filters the lineage graph', async ({
115132

116133
// Toggle off → graph returns to the full size
117134
await lineageFrame.getByRole('button', { name: 'Settings' }).click()
118-
await lineageFrame
119-
.getByRole('button', { name: 'Only Direct Neighbors' })
120-
.click()
121-
await page.waitForTimeout(250)
122-
const nodesRestored = await lineageFrame.locator('.react-flow__node').count()
123-
expect(nodesRestored).toBe(nodesBefore)
135+
const toggleOff = lineageFrame.getByRole('menuitem', {
136+
name: 'Only Direct Neighbors',
137+
})
138+
await toggleOff.waitFor()
139+
await toggleOff.click()
140+
await expect(lineageFrame.locator('.react-flow__node')).toHaveCount(
141+
nodesBefore,
142+
)
124143
})

0 commit comments

Comments
 (0)