test(client): cover effective menu shortcuts across browser platforms

This commit is contained in:
zhc committed 2026-10-23 19:40:08 +08:00
1 parent dc34d986b0
commit 722a694c30
2 files changed
+8 -6

No files matched your search

+7 -5
View File
@@ -34,7 +34,7 @@ function fixture(title: string): string {
...session.snapshotEvents().map(event => JSON.stringify({ ...event, time: 1_000 + event.seq * 1_000 })), ''].join('\n')
}
describe('web context menus', () => {
describe.each(['MacIntel', 'Win32', 'Linux x86_64'])('web context menus on %s', (platform) => {
let scaffold: WebScaffold, browser: Browser, page: Page
let tripwire: ReturnType<typeof watchConsole>
beforeAll(async () => {
@@ -48,6 +48,7 @@ describe('web context menus', () => {
await seedSession(scaffold, fixture('Menu background'), 'context-menu-other')
browser = await chromium.launch()
const context = await browser.newContext({ viewport: { width: 1680, height: 1000 }, locale: 'en-US', timezoneId: 'Asia/Shanghai' })
await context.addInitScript((value) => { Object.defineProperty(navigator, 'platform', { value }) }, platform)
page = await context.newPage()
await page.setViewportSize({ width: 1291, height: 768 })
tripwire = watchConsole(page)
@@ -123,11 +124,12 @@ describe('web context menus', () => {
const initial = await item.getAttribute('aria-keyshortcuts')
await other.evaluate((key) => {
localStorage.setItem(key, JSON.stringify({ schemaVersion: 2, profiles: {
'web:macos': { 'session.rename': { code: 'KeyJ', modifiers: ['primary', 'alt', 'shift'] } },
'web:windows': { 'session.rename': { code: 'KeyJ', modifiers: ['primary', 'alt', 'shift'] } },
'web:macos': { 'session.rename': { code: 'Comma', modifiers: ['primary', 'shift'] } },
'web:windows': { 'session.rename': { code: 'Comma', modifiers: ['primary', 'shift'] } },
'web:linux': { 'session.rename': { code: 'Comma', modifiers: ['primary', 'shift'] } },
} }))
}, key)
await expect.poll(() => item.getAttribute('aria-keyshortcuts')).toMatch(/J$/)
await expect.poll(() => item.getAttribute('aria-keyshortcuts')).toBe(platform === 'MacIntel' ? 'Shift+Meta+,' : 'Control+Shift+,')
expect(await item.getAttribute('aria-keyshortcuts')).not.toBe(initial)
expect(await popup!.evaluate(element => element.isConnected)).toBe(true)
expect(await background.getAttribute('aria-selected')).toBe('false')
@@ -140,7 +142,7 @@ describe('web context menus', () => {
await item.waitFor()
await other.evaluate((key) => {
localStorage.setItem(key, JSON.stringify({ schemaVersion: 2, profiles: {
'web:macos': { 'session.rename': null }, 'web:windows': { 'session.rename': null },
'web:macos': { 'session.rename': null }, 'web:windows': { 'session.rename': null }, 'web:linux': { 'session.rename': null },
} }))
}, key)
await expect.poll(() => item.getAttribute('aria-keyshortcuts')).toBeNull()
+1 -1
View File
@@ -254,7 +254,7 @@ describe.skipIf(process.platform === 'win32')('Web sidebar shortcuts', () => {
await menuTab.click({ button: 'right' })
await page.getByRole('menu').waitFor()
expect(await page.getByRole('tooltip').count()).toBe(0)
expect(await page.getByRole('menuitem', { name: 'Close', exact: true }).getAttribute('aria-keyshortcuts')).toBeNull()
expect(await page.getByRole('menuitem', { name: 'Close', exact: true }).getAttribute('aria-keyshortcuts')).toBe(aria)
if (attempt === 0) {
await compareOrRefreshGolden(join(expected, 'tab-menu.expected.md'),
await captureStableAria(page, '[data-context-menu][role="menu"]', scaffold.workspaceCwd), mode)