|
| 1 | +import type { CDPSession, Page } from '@playwright/test'; |
| 2 | +import { expect, test, COMPOSER_INPUT } from './fixtures'; |
| 3 | +import { auditAxTree } from '../../../scripts/ax-tree-audit.mjs'; |
| 4 | +import { groupedNav } from '../src/renderer/settings/settings-nav'; |
| 5 | + |
| 6 | +function exactNameWithOptionalBadge(label: string): RegExp { |
| 7 | + const escaped = label.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); |
| 8 | + return new RegExp(`^${escaped}(?: Beta)?$`); |
| 9 | +} |
| 10 | + |
| 11 | +async function assertAxHealth(cdp: CDPSession, surface: string): Promise<void> { |
| 12 | + const result = await cdp.send('Accessibility.getFullAXTree'); |
| 13 | + const audit = auditAxTree(result.nodes); |
| 14 | + expect(audit.problems, `${surface} exposes an unhealthy AX tree`).toEqual([]); |
| 15 | +} |
| 16 | + |
| 17 | +async function openSettings(page: Page): Promise<void> { |
| 18 | + const sidebarToggle = page.getByRole('button', { name: '展开侧边栏' }); |
| 19 | + if (await sidebarToggle.isVisible()) await sidebarToggle.click(); |
| 20 | + await page.getByRole('button', { name: '设置', exact: true }).click(); |
| 21 | + await expect(page.getByRole('main', { name: '设置内容' })).toBeVisible(); |
| 22 | +} |
| 23 | + |
| 24 | +test('every settings page exposes named actionable controls', async ({ window: page }) => { |
| 25 | + await openSettings(page); |
| 26 | + const cdp = await page.context().newCDPSession(page); |
| 27 | + const navigation = page.getByRole('navigation', { name: '设置分组' }); |
| 28 | + await expect(page.getByRole('main')).toHaveCount(1); |
| 29 | + const sectionLabels = (await navigation.getByRole('button').allTextContents()) |
| 30 | + .map((label) => label.trim().replace(/\s*Beta$/, '')) |
| 31 | + .filter((label) => label.length > 0 && label !== '返回应用'); |
| 32 | + const expectedSectionLabels = groupedNav('zh') |
| 33 | + .flatMap(({ items }) => items) |
| 34 | + .filter(({ enabled }) => enabled) |
| 35 | + .map(({ label }) => label); |
| 36 | + expect(sectionLabels, 'settings navigation must expose every enabled page in source order').toEqual( |
| 37 | + expectedSectionLabels, |
| 38 | + ); |
| 39 | + |
| 40 | + for (const section of sectionLabels) { |
| 41 | + const sectionButton = navigation.getByRole('button', { |
| 42 | + name: exactNameWithOptionalBadge(section), |
| 43 | + }); |
| 44 | + await sectionButton.click(); |
| 45 | + await expect(sectionButton).toHaveAttribute('aria-current', 'page'); |
| 46 | + await expect(page.getByRole('heading', { name: section, exact: true })).toBeVisible(); |
| 47 | + await assertAxHealth(cdp, `settings/${section}`); |
| 48 | + } |
| 49 | +}); |
| 50 | + |
| 51 | +test('module pages and global overlays expose named actionable controls', async ({ |
| 52 | + window: page, |
| 53 | +}) => { |
| 54 | + const cdp = await page.context().newCDPSession(page); |
| 55 | + await expect(page.getByRole('link', { name: '跳到主要内容' })).toHaveCount(1); |
| 56 | + await expect(page.getByRole('link', { name: 'Skip to content' })).toHaveCount(0); |
| 57 | + const sidebarToggle = page.getByRole('button', { name: '展开侧边栏' }); |
| 58 | + if (await sidebarToggle.isVisible()) await sidebarToggle.click(); |
| 59 | + const navigation = page.getByRole('navigation', { name: '任务列表' }); |
| 60 | + |
| 61 | + await navigation.getByRole('button', { name: '扩展', exact: true }).click(); |
| 62 | + await expect(page.getByRole('main')).toHaveCount(1); |
| 63 | + await expect(page.getByRole('region', { name: '扩展', exact: true })).toBeVisible(); |
| 64 | + const extensionsNavigation = page.getByRole('navigation', { name: /扩展内容/ }); |
| 65 | + await expect( |
| 66 | + extensionsNavigation.getByRole('button', { name: '技能', exact: true }), |
| 67 | + ).toHaveAttribute('aria-current', 'page'); |
| 68 | + await assertAxHealth(cdp, 'extensions/skills'); |
| 69 | + const mcpButton = extensionsNavigation.getByRole('button', { name: 'MCP', exact: true }); |
| 70 | + await mcpButton.click(); |
| 71 | + await expect(mcpButton).toHaveAttribute('aria-current', 'page'); |
| 72 | + await assertAxHealth(cdp, 'extensions/mcp'); |
| 73 | + |
| 74 | + await navigation.getByRole('button', { name: /定时任务/ }).click(); |
| 75 | + const automationsNavigation = page.getByRole('navigation', { name: /定时任务内容/ }); |
| 76 | + await expect( |
| 77 | + automationsNavigation.getByRole('button', { name: '定时任务', exact: true }), |
| 78 | + ).toHaveAttribute('aria-current', 'page'); |
| 79 | + await assertAxHealth(cdp, 'automations/scheduled-tasks'); |
| 80 | + const dailyReviewButton = automationsNavigation.getByRole('button', { |
| 81 | + name: '每日回顾', |
| 82 | + exact: true, |
| 83 | + }); |
| 84 | + await dailyReviewButton.click(); |
| 85 | + await expect(dailyReviewButton).toHaveAttribute('aria-current', 'page'); |
| 86 | + await assertAxHealth(cdp, 'automations/daily-review'); |
| 87 | + |
| 88 | + await page.keyboard.press('Shift+Slash'); |
| 89 | + await expect(page.getByRole('dialog')).toBeVisible(); |
| 90 | + await assertAxHealth(cdp, 'overlay/keyboard-help'); |
| 91 | + await page.keyboard.press('Escape'); |
| 92 | + |
| 93 | + await page.keyboard.press(process.platform === 'darwin' ? 'Meta+k' : 'Control+k'); |
| 94 | + await expect(page.getByRole('dialog')).toBeVisible(); |
| 95 | + await assertAxHealth(cdp, 'overlay/command-palette'); |
| 96 | + await page.keyboard.press('Escape'); |
| 97 | +}); |
| 98 | + |
| 99 | +test('composer and workbar entry points expose named actionable controls', async ({ |
| 100 | + window: page, |
| 101 | +}) => { |
| 102 | + const cdp = await page.context().newCDPSession(page); |
| 103 | + await expect(page.getByRole('main')).toHaveCount(1); |
| 104 | + await expect(page.getByRole('region', { name: '新任务对话' })).toBeVisible(); |
| 105 | + await assertAxHealth(cdp, 'conversation/new-task'); |
| 106 | + |
| 107 | + const composer = page.locator(COMPOSER_INPUT); |
| 108 | + await composer.fill('create a session for accessibility coverage'); |
| 109 | + await composer.press('Enter'); |
| 110 | + await expect(page.getByRole('main')).toHaveCount(1); |
| 111 | + await expect(page.getByRole('region', { name: /对话:/ })).toBeVisible(); |
| 112 | + await assertAxHealth(cdp, 'conversation/session'); |
| 113 | + |
| 114 | + await page.getByRole('button', { name: '展开任务工作栏' }).click(); |
| 115 | + await expect(page.getByRole('list', { name: '打开工具' })).toBeVisible(); |
| 116 | + await assertAxHealth(cdp, 'workbar/launcher'); |
| 117 | + |
| 118 | + const workbarPanels = [ |
| 119 | + '侧边对话', |
| 120 | + '变更', |
| 121 | + '终端', |
| 122 | + '浏览器', |
| 123 | + '生成文件', |
| 124 | + '待办', |
| 125 | + '追踪', |
| 126 | + ] as const; |
| 127 | + for (const panel of workbarPanels) { |
| 128 | + await page |
| 129 | + .getByRole('list', { name: '打开工具' }) |
| 130 | + .getByRole('button', { name: new RegExp(`^${panel}(?: |$)`) }) |
| 131 | + .click(); |
| 132 | + const activeTab = page.getByRole('tab', { name: new RegExp(panel) }); |
| 133 | + await expect(activeTab).toBeVisible(); |
| 134 | + await expect(activeTab).toHaveAttribute('aria-selected', 'true'); |
| 135 | + await assertAxHealth(cdp, `workbar/${panel}`); |
| 136 | + if (panel !== workbarPanels.at(-1)) { |
| 137 | + await page.getByRole('button', { name: '打开工作栏标签' }).first().click(); |
| 138 | + await expect(page.getByRole('list', { name: '打开工具' })).toBeVisible(); |
| 139 | + } |
| 140 | + } |
| 141 | +}); |
0 commit comments