mirror of
https://github.com/stablyai/orca.git
synced 2026-11-19 04:23:57 +00:00
31 lines
1.2 KiB
TypeScript
31 lines
1.2 KiB
TypeScript
// @vitest-environment happy-dom
|
|
|
|
import { describe, expect, it } from 'vitest'
|
|
import { buildPluginPanelShellHtml } from './plugin-panel-shell'
|
|
|
|
describe('buildPluginPanelShellHtml', () => {
|
|
it('cancels anchor and form default navigation in the fallback path', () => {
|
|
const html = buildPluginPanelShellHtml('<main>Plugin</main>')
|
|
const script = html.match(/<script>\n([\s\S]*?)<\/script>/)?.[1]
|
|
expect(script).toBeTruthy()
|
|
// Keep the happy-dom override removable for teardown; disposable production iframes use non-configurable globals.
|
|
window.eval(script!.replace('configurable: false', 'configurable: true'))
|
|
|
|
const anchor = document.createElement('a')
|
|
anchor.href = 'https://example.com/'
|
|
document.body.appendChild(anchor)
|
|
const clickAccepted = anchor.dispatchEvent(
|
|
new MouseEvent('click', { bubbles: true, cancelable: true })
|
|
)
|
|
const form = document.createElement('form')
|
|
document.body.appendChild(form)
|
|
const submitAccepted = form.dispatchEvent(
|
|
new Event('submit', { bubbles: true, cancelable: true })
|
|
)
|
|
|
|
expect(clickAccepted).toBe(false)
|
|
expect(submitAccepted).toBe(false)
|
|
expect(window.open('https://example.com/')).toBeNull()
|
|
})
|
|
})
|