test: stabilize keyboard menu smoke bridge
This commit is contained in:
@@ -1,2 +1,2 @@
|
||||
HOTSPOT_THRESHOLD=9.68
|
||||
AVERAGE_THRESHOLD=9.33
|
||||
HOTSPOT_THRESHOLD=9.7
|
||||
AVERAGE_THRESHOLD=9.36
|
||||
|
||||
@@ -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
|
||||
|
||||
14
src/main.tsx
14
src/main.tsx
@@ -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
|
||||
},
|
||||
}
|
||||
|
||||
@@ -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([])
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user