test: stabilize keyboard menu smoke bridge

This commit is contained in:
lucaronin
2026-04-11 10:59:38 +02:00
parent 974ca6148b
commit 86306dc9de
4 changed files with 39 additions and 17 deletions

View File

@@ -1,2 +1,2 @@
HOTSPOT_THRESHOLD=9.68
AVERAGE_THRESHOLD=9.33
HOTSPOT_THRESHOLD=9.7
AVERAGE_THRESHOLD=9.36

View File

@@ -2,12 +2,19 @@ import { useEffect, useRef } from 'react'
import { isTauri } from '../mock-tauri'
import {
APP_COMMAND_EVENT_NAME,
APP_MENU_EVENT_NAME,
dispatchAppCommand,
isAppCommandId,
type AppCommandHandlers,
} from './appCommandDispatcher'
declare global {
interface Window {
__laputaTest?: {
dispatchBrowserMenuCommand?: (id: string) => void
}
}
}
export interface MenuEventHandlers extends AppCommandHandlers {
activeTabPath: string | null
modifiedCount?: number
@@ -90,12 +97,20 @@ export function useMenuEvents(handlers: MenuEventHandlers) {
}, [])
useEffect(() => {
const handleMenuCommandEvent = createWindowCommandListener((detail) => {
dispatchMenuEvent(detail, ref.current)
})
const bridge = (id: string) => {
dispatchMenuEvent(id, ref.current)
}
window.addEventListener(APP_MENU_EVENT_NAME, handleMenuCommandEvent)
return () => window.removeEventListener(APP_MENU_EVENT_NAME, handleMenuCommandEvent)
window.__laputaTest = {
...window.__laputaTest,
dispatchBrowserMenuCommand: bridge,
}
return () => {
if (window.__laputaTest?.dispatchBrowserMenuCommand === bridge) {
delete window.__laputaTest.dispatchBrowserMenuCommand
}
}
}, [])
// Sync menu item enabled state when active note or git state changes

View File

@@ -5,7 +5,6 @@ import './index.css'
import App from './App.tsx'
import {
APP_COMMAND_EVENT_NAME,
APP_MENU_EVENT_NAME,
isAppCommandId,
isNativeMenuCommandId,
} from './hooks/appCommandDispatcher'
@@ -14,6 +13,7 @@ declare global {
interface Window {
__laputaTest?: {
dispatchAppCommand: (id: string) => void
dispatchBrowserMenuCommand?: (id: string) => void
triggerMenuCommand?: (id: string) => Promise<unknown>
}
}
@@ -40,11 +40,15 @@ window.__laputaTest = {
}
if ('__TAURI__' in window || '__TAURI_INTERNALS__' in window) {
const { invoke } = await import('@tauri-apps/api/core')
return invoke('trigger_menu_command', { id })
}
const { invoke } = await import('@tauri-apps/api/core')
return invoke('trigger_menu_command', { id })
}
window.dispatchEvent(new CustomEvent(APP_MENU_EVENT_NAME, { detail: id }))
if (!window.__laputaTest?.dispatchBrowserMenuCommand) {
throw new Error('Laputa test bridge is missing dispatchBrowserMenuCommand')
}
window.__laputaTest.dispatchBrowserMenuCommand(id)
return undefined
},
}

View File

@@ -1,11 +1,11 @@
import { test, expect, type Page } from '@playwright/test'
import { test, expect } from '@playwright/test'
import { triggerMenuCommand } from './testBridge'
import { createFixtureVaultCopy, openFixtureVault, removeFixtureVaultCopy } from '../helpers/fixtureVault'
let tempVaultDir: string
function untitledRow(page: Page, typeLabel: string) {
return page.getByText(new RegExp(`^Untitled ${typeLabel}(?: \\d+)?$`, 'i')).first()
function untitledNoteListMatcher(typeLabel: string) {
return new RegExp(`Untitled ${typeLabel}(?: \\d+)?`, 'i')
}
test.describe('keyboard command routing', () => {
@@ -24,7 +24,10 @@ test.describe('keyboard command routing', () => {
await openFixtureVault(page, tempVaultDir)
await triggerMenuCommand(page, 'file-new-note')
await expect(untitledRow(page, 'note')).toBeVisible({ timeout: 5_000 })
await expect(page.getByTestId('breadcrumb-filename-trigger')).toContainText(/untitled-note-\d+/i, { timeout: 5_000 })
await expect(
page.locator('[data-testid="note-list-container"]').getByText(untitledNoteListMatcher('note')).first(),
).toBeVisible({ timeout: 5_000 })
expect(errors).toEqual([])
})