chore(tests): namespace browser test hooks
- Move test-only write-count, mock-handle, and saved-open globals under window.openPencil.test - Keep external Tauri and Vite injected globals separate from app-owned browser bridge hooks - Validate check plus autosave and chat E2E coverage
This commit is contained in:
parent
8719274cc9
commit
f7b20a8f38
|
|
@ -2,10 +2,17 @@ import type { ChatTransport, UIMessage } from 'ai'
|
|||
|
||||
import type { EditorStore } from '@/app/editor/session/create'
|
||||
|
||||
export interface OpenPencilTestHooks {
|
||||
writeCount?: () => number
|
||||
mockHandle?: FileSystemFileHandle
|
||||
savedOpen?: Window['open']
|
||||
}
|
||||
|
||||
export interface OpenPencilWindowAPI {
|
||||
store?: EditorStore
|
||||
setChatTransport?: (factory: () => ChatTransport<UIMessage>) => void
|
||||
openFile?: (path: string) => Promise<void>
|
||||
test?: OpenPencilTestHooks
|
||||
}
|
||||
|
||||
declare global {
|
||||
|
|
|
|||
3
src/global.d.ts
vendored
3
src/global.d.ts
vendored
|
|
@ -38,9 +38,6 @@ declare global {
|
|||
blob(): Promise<Blob>
|
||||
}[]
|
||||
>
|
||||
__TEST_WRITE_COUNT__?(): number
|
||||
__TEST_MOCK_HANDLE__?: FileSystemFileHandle
|
||||
__savedOpen?: Window['open']
|
||||
mockWindowOpen?(url: string): void
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,8 +31,8 @@ test('autosave triggers after scene changes with a file handle', async () => {
|
|||
createWritable: async () => mockWritable
|
||||
} as FileSystemFileHandle
|
||||
|
||||
window.__TEST_WRITE_COUNT__ = () => writes
|
||||
window.__TEST_MOCK_HANDLE__ = mockHandle
|
||||
window.openPencil ??= {}
|
||||
window.openPencil.test = { writeCount: () => writes, mockHandle }
|
||||
|
||||
return writes
|
||||
})
|
||||
|
|
|
|||
|
|
@ -244,7 +244,8 @@ test('"Get API key" link opens external URL via window.open', async () => {
|
|||
const openedUrls: string[] = []
|
||||
await page.exposeFunction('mockWindowOpen', (url: string) => openedUrls.push(url))
|
||||
await page.evaluate(() => {
|
||||
window.__savedOpen = window.open
|
||||
window.openPencil ??= {}
|
||||
window.openPencil.test = { ...window.openPencil.test, savedOpen: window.open }
|
||||
window.open = (url: string | URL) => {
|
||||
window.mockWindowOpen?.(String(url))
|
||||
return null
|
||||
|
|
@ -260,6 +261,7 @@ test('"Get API key" link opens external URL via window.open', async () => {
|
|||
|
||||
// Restore
|
||||
await page.evaluate(() => {
|
||||
if (window.__savedOpen) window.open = window.__savedOpen
|
||||
const savedOpen = window.openPencil?.test?.savedOpen
|
||||
if (savedOpen) window.open = savedOpen
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in a new issue