mirror of
https://github.com/stablyai/orca.git
synced 2026-11-18 03:45:08 +00:00
test: remove low-value display and mock-request test variants (#43260)
Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
This commit is contained in:
@@ -32,7 +32,6 @@
|
||||
"config/scripts/static-analysis/ratchets/renderer-state/check-focus-read-ratchet.test.mjs": 79,
|
||||
"config/scripts/node-runtime/pin-policy/check-node-runtime-pin.test.mjs": 640,
|
||||
"config/scripts/static-analysis/repository-layout/check-root-directory-entries.test.mjs": 936,
|
||||
"config/scripts/static-analysis/process-boundaries/check-runtime-electron-ratchet-graph.test.mjs": 160,
|
||||
"config/scripts/static-analysis/process-boundaries/check-runtime-electron-ratchet.test.mjs": 3540,
|
||||
"config/scripts/ci/unit-selection/check-test-file-runners.test.mjs": 267,
|
||||
"config/scripts/ci/workflow-contracts/ci-closed-pr-cancellation.test.mjs": 112,
|
||||
|
||||
-70
@@ -1,70 +0,0 @@
|
||||
import { afterEach, describe, expect, it } from 'vitest'
|
||||
import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
|
||||
import { tmpdir } from 'node:os'
|
||||
import path from 'node:path'
|
||||
import { collectElectronImporters } from './check-runtime-electron-ratchet.mjs'
|
||||
|
||||
const roots = []
|
||||
afterEach(() => {
|
||||
for (const root of roots.splice(0)) {
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
}
|
||||
})
|
||||
|
||||
function fixture(files) {
|
||||
const root = mkdtempSync(path.join(tmpdir(), 'orca-electron-ratchet-graph-'))
|
||||
roots.push(root)
|
||||
for (const [file, source] of Object.entries(files)) {
|
||||
const absolute = path.join(root, file)
|
||||
mkdirSync(path.dirname(absolute), { recursive: true })
|
||||
writeFileSync(absolute, source)
|
||||
}
|
||||
return root
|
||||
}
|
||||
|
||||
describe('the runtime Electron import graph', () => {
|
||||
it('finds Electron importers across CommonJS, conditional exports and dynamic imports', async () => {
|
||||
const root = fixture({
|
||||
'entry.mjs': `
|
||||
export { value } from './shared.cjs'
|
||||
export { value as imported } from 'conditional-package'
|
||||
export const load = () => import('./dynamic.mjs')
|
||||
`,
|
||||
'future.cjs': `
|
||||
module.exports = {
|
||||
value: require('conditional-package').value,
|
||||
addon: () => require('./missing.node'),
|
||||
desktop: () => require('desktop-package')
|
||||
}
|
||||
`,
|
||||
'shared.cjs': 'exports.value = 42',
|
||||
'dynamic.mjs': "import 'electron/renderer'; export const value = 1",
|
||||
'node_modules/conditional-package/package.json': JSON.stringify({
|
||||
exports: { '.': { import: './import.mjs', require: './require.cjs' } }
|
||||
}),
|
||||
'node_modules/conditional-package/import.mjs': "import 'electron'; export const value = 2",
|
||||
'node_modules/conditional-package/require.cjs': "require('electron/main'); exports.value = 3",
|
||||
'node_modules/desktop-package/package.json': '{"main":"index.cjs"}',
|
||||
'node_modules/desktop-package/index.cjs': "require('electron'); exports.value = 4"
|
||||
})
|
||||
const injectElectron = {
|
||||
name: 'inject-future-electron-import',
|
||||
setup(pluginBuild) {
|
||||
pluginBuild.onLoad({ filter: /future\.cjs$/ }, (args) => ({
|
||||
contents: `require('electron/utility')\n${readFileSync(args.path, 'utf8')}`,
|
||||
loader: 'js'
|
||||
}))
|
||||
}
|
||||
}
|
||||
const entries = ['entry.mjs', 'future.cjs', 'shared.cjs'].map((file) => path.join(root, file))
|
||||
const importers = await collectElectronImporters(entries, { plugins: [injectElectron] })
|
||||
|
||||
expect(importers.map((file) => file.slice(file.indexOf(path.basename(root))))).toEqual([
|
||||
`${path.basename(root)}/dynamic.mjs`,
|
||||
`${path.basename(root)}/future.cjs`,
|
||||
`${path.basename(root)}/node_modules/conditional-package/import.mjs`,
|
||||
`${path.basename(root)}/node_modules/conditional-package/require.cjs`,
|
||||
`${path.basename(root)}/node_modules/desktop-package/index.cjs`
|
||||
])
|
||||
})
|
||||
})
|
||||
-32
@@ -30,38 +30,6 @@ describe('Kitty virtual placement lifecycle', () => {
|
||||
}
|
||||
})
|
||||
|
||||
it('can create a prototype from an encoded image after its physical bitmap is evicted', async () => {
|
||||
const h = createPlaceholderTerminal()
|
||||
try {
|
||||
await writeKitty(h.terminal, 'a=T,f=100,i=7,C=1', PNG)
|
||||
h.storage._pixelLimit = 200
|
||||
await writeKitty(h.terminal, 'a=T,f=100,i=8,U=1,c=2,r=2', PNG)
|
||||
expect(h.kitty.getImage(7)).toBeDefined()
|
||||
await writeKitty(h.terminal, 'a=p,U=1,i=7,c=2,r=2')
|
||||
await write(h.terminal, placeholderCells(7))
|
||||
expect(render(h)).toHaveLength(2)
|
||||
} finally {
|
||||
h.terminal.dispose()
|
||||
}
|
||||
})
|
||||
|
||||
it('deletes physical placements while preserving a prototype of the same image on d=A', async () => {
|
||||
const h = createPlaceholderTerminal()
|
||||
try {
|
||||
await writeKitty(h.terminal, 'a=T,f=100,i=7,U=1,c=2,r=2', PNG)
|
||||
await writeKitty(h.terminal, 'a=p,i=7,C=1')
|
||||
expect(h.kitty.kittyIdToStorageId.size).toBe(1)
|
||||
await writeKitty(h.terminal, 'a=d,d=A,q=2')
|
||||
expect(h.kitty.kittyIdToStorageId.size).toBe(0)
|
||||
expect(h.storage._images.size).toBe(1)
|
||||
expect(h.bitmaps[1].close).toHaveBeenCalledOnce()
|
||||
await write(h.terminal, placeholderCells(7))
|
||||
expect(render(h)).toHaveLength(2)
|
||||
} finally {
|
||||
h.terminal.dispose()
|
||||
}
|
||||
})
|
||||
|
||||
it('discards a virtual decode completing after disposal', async () => {
|
||||
const h = createPlaceholderTerminal()
|
||||
try {
|
||||
|
||||
-14
@@ -25,20 +25,6 @@ async function prepared() {
|
||||
}
|
||||
|
||||
describe('placeholder replacement publication boundaries', () => {
|
||||
it('keeps the existing picture until its replacement finishes decoding', async () => {
|
||||
const { h, first, pending } = await prepared()
|
||||
const writing = writeKitty(h.terminal, 'a=T,f=100,i=7,U=1,p=10,c=2,r=2', PNG)
|
||||
try {
|
||||
await vi.waitFor(() => expect(pending).toHaveLength(1))
|
||||
expect(render(h).map((call) => call[0])).toEqual([first, first])
|
||||
expect(first.close).not.toHaveBeenCalled()
|
||||
} finally {
|
||||
pending[0]?.resolve(new TrackedBitmap())
|
||||
await writing
|
||||
h.terminal.dispose()
|
||||
}
|
||||
})
|
||||
|
||||
it('publishes no stale replacement after an addon reset during decoding', async () => {
|
||||
const { h, first, pending } = await prepared()
|
||||
const writing = writeKitty(h.terminal, 'a=T,f=100,i=7,U=1,p=10,c=2,r=2', PNG)
|
||||
|
||||
@@ -55,50 +55,6 @@ afterEach(() => {
|
||||
act(() => renderer?.unmount())
|
||||
})
|
||||
describe('shared settings screen state', () => {
|
||||
it('flips the Voice switch before the desktop replies and surfaces a rejected save', async () => {
|
||||
const loaded = {
|
||||
enabled: true,
|
||||
dictationMode: 'toggle',
|
||||
selectedModelId: '',
|
||||
models: []
|
||||
}
|
||||
let rejectConfigure: (error: Error) => void = () => {}
|
||||
const operations = {
|
||||
// Why: the reconcile read stays pending so the optimistic value and the
|
||||
// rejection message are both observable, as they are on a slow desktop.
|
||||
load: vi
|
||||
.fn()
|
||||
.mockResolvedValueOnce(loaded)
|
||||
.mockImplementation(() => new Promise(() => {})),
|
||||
configure: vi.fn().mockImplementation(
|
||||
() =>
|
||||
new Promise((_resolve, reject) => {
|
||||
rejectConfigure = reject
|
||||
})
|
||||
),
|
||||
download: vi.fn(),
|
||||
delete: vi.fn()
|
||||
} as VoiceSettingsOperations
|
||||
await act(async () => {
|
||||
renderer = create(
|
||||
createElement(VoiceSettingsScreen, { operations, focused: true, onBack: vi.fn() })
|
||||
)
|
||||
})
|
||||
const switchProps = () => renderer.root.findByProps({ testID: 'voice-enabled' }).props
|
||||
expect(switchProps().value).toBe(true)
|
||||
|
||||
await act(async () => {
|
||||
switchProps().onValueChange(false)
|
||||
})
|
||||
// The switch moves on tap, before the desktop has answered.
|
||||
expect(switchProps().value).toBe(false)
|
||||
|
||||
await act(async () => {
|
||||
rejectConfigure(new Error('Desktop unavailable'))
|
||||
await Promise.resolve()
|
||||
})
|
||||
expect(JSON.stringify(renderer.toJSON())).toContain('Desktop unavailable')
|
||||
})
|
||||
it('drops a poll that resolves after a toggle instead of clobbering it', async () => {
|
||||
const loaded = {
|
||||
enabled: true,
|
||||
|
||||
@@ -158,51 +158,6 @@ describe('useFolderCreateFlow', () => {
|
||||
expect(composer().folderLaunch?.repoId).toBe(b.target.repoId)
|
||||
})
|
||||
|
||||
async function openComposer(flow: { current: Flow | null }, repo = repoIn()) {
|
||||
const refusal = replying({ id: '1', ok: false, error: { code: 'x', message: TAKEN } })
|
||||
const opening = flow.current!.onCreate(repo.repo, repo.target, refusal.client, 'payments')
|
||||
refusal.answer()
|
||||
await act(() => opening)
|
||||
return composer()
|
||||
}
|
||||
|
||||
it('gives the repository back when the screen is left with an unsent form', async () => {
|
||||
const { flow } = mountFlow(() => {})
|
||||
const repo = repoIn()
|
||||
await openComposer(flow, repo)
|
||||
expect(isFolderRepoCreateBusy(repo.target)).toBe(true)
|
||||
|
||||
act(() => renderer?.unmount())
|
||||
renderer = null
|
||||
expect(isFolderRepoCreateBusy(repo.target)).toBe(false)
|
||||
})
|
||||
it('resends an unconfirmed create without setup once the user agrees', async () => {
|
||||
vi.useFakeTimers({ toFake: ['setTimeout'] })
|
||||
const { flow } = mountFlow(() => {})
|
||||
const a = repoIn()
|
||||
const lost = new FakeSession('connected')
|
||||
lost.sendRequest.mockRejectedValueOnce(markRpcDeliveryUnknown(new Error('connection lost')))
|
||||
await act(() => flow.current!.onCreate(a.repo, a.target, lost, 'payments'))
|
||||
vi.advanceTimersByTime(60_000)
|
||||
|
||||
const retry = new FakeSession('connected')
|
||||
retry.sendRequest
|
||||
.mockResolvedValueOnce({
|
||||
id: '1',
|
||||
ok: false,
|
||||
error: { code: 'x', message: 'Setup decision required for this repository' }
|
||||
})
|
||||
.mockResolvedValueOnce(CREATED)
|
||||
await act(() => flow.current!.onCreate(a.repo, a.target, retry, 'payments'))
|
||||
expect(seen.confirm?.visible).toBe(true)
|
||||
|
||||
await act(async () => seen.confirm?.onConfirm?.())
|
||||
expect(retry.sendRequest.mock.calls[1]?.[1]).toMatchObject({
|
||||
name: 'payments',
|
||||
branchIntent: 'create-exact',
|
||||
setupDecision: 'skip'
|
||||
})
|
||||
})
|
||||
async function setupRefusedRetry(flow: { current: Flow | null }) {
|
||||
const a = repoIn()
|
||||
const lost = new FakeSession('connected')
|
||||
|
||||
-228
@@ -1,228 +0,0 @@
|
||||
// @vitest-environment happy-dom
|
||||
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import { cleanup, renderHook } from '@testing-library/react'
|
||||
import { createProgrammaticScrollMarks } from '@/hooks/programmatic-scroll-marks'
|
||||
import type { NativeChatToolRunRow } from './native-chat-tool-run-rows'
|
||||
import { ROW_KEY_ATTRIBUTE } from './use-native-chat-tool-run-pins'
|
||||
import {
|
||||
claimNativeChatToolRunReveal,
|
||||
useNativeChatToolRunReaderPosition
|
||||
} from './use-native-chat-tool-run-reader-position'
|
||||
import type { NativeChatToolRunVirtualizer } from './use-native-chat-tool-run-window'
|
||||
|
||||
// The window's size model, deliberately stale: the edit row is still its cached 78 px while the page has it far
|
||||
// taller. Rows after it follow the cached height.
|
||||
const MODEL_ROWS = [
|
||||
'call:before',
|
||||
'edit:patch',
|
||||
'call:after-1',
|
||||
'call:after-2',
|
||||
'call:after-3',
|
||||
'call:after-4',
|
||||
'call:after-5',
|
||||
'call:after-6',
|
||||
'call:after-7',
|
||||
'call:after-8',
|
||||
'call:after-9',
|
||||
'call:after-10'
|
||||
]
|
||||
const MODEL_STARTS = [
|
||||
0, 1_000, 1_078, 1_118, 1_158, 1_198, 1_238, 1_278, 1_318, 1_358, 1_398, 1_438
|
||||
]
|
||||
|
||||
// Rows that draw something; the owner reads only their keys and whether they draw.
|
||||
const rows: NativeChatToolRunRow[] = MODEL_ROWS.map((key) => ({
|
||||
kind: 'aside',
|
||||
key,
|
||||
focusable: true,
|
||||
element: <span />
|
||||
}))
|
||||
const rowIndexByKey = new Map(MODEL_ROWS.map((key, index) => [key, index]))
|
||||
const measurementsCache = MODEL_STARTS.map((start, index) => {
|
||||
const size = (MODEL_STARTS[index + 1] ?? start + 40) - start
|
||||
return { index, start, size, end: start + size, key: MODEL_ROWS[index]!, lane: 0 }
|
||||
})
|
||||
// oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: the owner reads only measurementsCache, scrollOffset and getVirtualItemForOffset, all supplied here; a full TanStack instance is not needed to give it a fixed model.
|
||||
const staleModel = {
|
||||
measurementsCache,
|
||||
scrollOffset: 0,
|
||||
getVirtualItemForOffset: (offset: number) =>
|
||||
measurementsCache.findLast((item) => item.start <= offset)
|
||||
} as unknown as NativeChatToolRunVirtualizer
|
||||
|
||||
function setClientHeight(element: Element, height: number): void {
|
||||
Object.defineProperty(element, 'clientHeight', { configurable: true, value: height })
|
||||
}
|
||||
|
||||
function setRect(element: Element, top: number, height: number): void {
|
||||
Object.defineProperty(element, 'getBoundingClientRect', {
|
||||
configurable: true,
|
||||
value: () => DOMRect.fromRect({ x: 0, y: top, width: 300, height })
|
||||
})
|
||||
}
|
||||
|
||||
/** A run box whose drawn children sit at literal page positions relative to a 288 px box at the page top. */
|
||||
function runBox(
|
||||
children: { key?: string; top: number; height: number }[],
|
||||
boxHeight = 288
|
||||
): {
|
||||
scroller: HTMLDivElement
|
||||
rowsByKey: Map<string, HTMLDivElement>
|
||||
} {
|
||||
const scroller = document.createElement('div')
|
||||
const content = document.createElement('div')
|
||||
scroller.append(content)
|
||||
document.body.append(scroller)
|
||||
setRect(scroller, 0, boxHeight)
|
||||
setClientHeight(scroller, boxHeight)
|
||||
const rowsByKey = new Map<string, HTMLDivElement>()
|
||||
for (const child of children) {
|
||||
const element = document.createElement('div')
|
||||
if (child.key) {
|
||||
element.setAttribute(ROW_KEY_ATTRIBUTE, child.key)
|
||||
rowsByKey.set(child.key, element)
|
||||
}
|
||||
setRect(element, child.top, child.height)
|
||||
content.append(element)
|
||||
}
|
||||
return { scroller, rowsByKey }
|
||||
}
|
||||
|
||||
function moveChildren(
|
||||
rowsByKey: Map<string, HTMLDivElement>,
|
||||
positions: Record<string, [number, number]>
|
||||
): void {
|
||||
for (const [key, [top, height]] of Object.entries(positions)) {
|
||||
setRect(rowsByKey.get(key)!, top, height)
|
||||
}
|
||||
}
|
||||
|
||||
function owner(scroller: HTMLDivElement) {
|
||||
return renderHook(
|
||||
({ isVisible }: { isVisible: boolean }) =>
|
||||
useNativeChatToolRunReaderPosition({
|
||||
scrollerRef: { current: scroller },
|
||||
virtualizer: staleModel,
|
||||
rows,
|
||||
rowIndexByKey,
|
||||
isVisible,
|
||||
followsEndRef: { current: false },
|
||||
marks: createProgrammaticScrollMarks(),
|
||||
totalSize: 1_478,
|
||||
initial: undefined,
|
||||
setHeldRowKey: vi.fn(),
|
||||
onRevealed: vi.fn()
|
||||
}),
|
||||
{ initialProps: { isVisible: true } }
|
||||
)
|
||||
}
|
||||
|
||||
/** A card inside a drawn row scrolls itself to the box top and claims the place. */
|
||||
function revealCardIn(scroller: HTMLDivElement, row: HTMLDivElement): void {
|
||||
const card = document.createElement('div')
|
||||
row.append(card)
|
||||
claimNativeChatToolRunReveal(scroller, card)
|
||||
}
|
||||
|
||||
describe('tool-run reader position with a stale size model', () => {
|
||||
afterEach(() => {
|
||||
cleanup()
|
||||
document.body.replaceChildren()
|
||||
})
|
||||
|
||||
it("keeps a revealed file's place through its own scroll report and a hide", () => {
|
||||
// Box at 1,400: the edit really starts at 1,000 and is 600 tall; the next row starts at 1,600.
|
||||
const { scroller, rowsByKey } = runBox([
|
||||
{ top: -1_400, height: 1_000 },
|
||||
{ key: 'edit:patch', top: -400, height: 600 },
|
||||
{ key: 'call:after-1', top: 200, height: 40 }
|
||||
])
|
||||
const { result, rerender } = owner(scroller)
|
||||
revealCardIn(scroller, rowsByKey.get('edit:patch')!)
|
||||
expect(result.current.current()).toEqual({ key: 'edit:patch', offset: 400 })
|
||||
|
||||
// The reveal's own native scroll report, before the edit's new height reaches the model.
|
||||
result.current.onScrolled(1_400, true)
|
||||
expect(result.current.current()).toEqual({ key: 'edit:patch', offset: 400 })
|
||||
|
||||
rerender({ isVisible: false })
|
||||
expect(result.current.current()).toEqual({ key: 'edit:patch', offset: 400 })
|
||||
})
|
||||
|
||||
it('follows the reader inside the tall row and across its edge before the model catches up', () => {
|
||||
const { scroller, rowsByKey } = runBox([
|
||||
{ top: -1_400, height: 1_000 },
|
||||
{ key: 'edit:patch', top: -400, height: 600 },
|
||||
{ key: 'call:after-1', top: 200, height: 40 }
|
||||
])
|
||||
const { result } = owner(scroller)
|
||||
revealCardIn(scroller, rowsByKey.get('edit:patch')!)
|
||||
|
||||
moveChildren(rowsByKey, { 'edit:patch': [-420, 600], 'call:after-1': [180, 40] })
|
||||
result.current.onScrolled(1_420, true)
|
||||
expect(result.current.current()).toEqual({ key: 'edit:patch', offset: 420 })
|
||||
|
||||
moveChildren(rowsByKey, { 'edit:patch': [-610, 600], 'call:after-1': [-10, 40] })
|
||||
result.current.onScrolled(1_610, true)
|
||||
expect(result.current.current()).toEqual({ key: 'call:after-1', offset: 10 })
|
||||
})
|
||||
|
||||
it('takes the next drawn row across a blank row and a card margin', () => {
|
||||
// Edit bottom at 1,600, a blank thought at 1,600, the next call at 1,604 (the card's margin); box at 1,602.
|
||||
const { scroller } = runBox([
|
||||
{ top: -1_602, height: 1_000 },
|
||||
{ key: 'edit:patch', top: -602, height: 600 },
|
||||
{ key: 'call:before', top: -2, height: 0 },
|
||||
{ key: 'call:after-1', top: 2, height: 40 }
|
||||
])
|
||||
const { result } = owner(scroller)
|
||||
result.current.onScrolled(1_602, true)
|
||||
expect(result.current.current()).toEqual({ key: 'call:after-1', offset: 0 })
|
||||
})
|
||||
|
||||
it('keeps the place when the box has no geometry, even where the model has an answer', () => {
|
||||
const { scroller, rowsByKey } = runBox([
|
||||
{ top: -1_400, height: 1_000 },
|
||||
{ key: 'edit:patch', top: -400, height: 600 }
|
||||
])
|
||||
const { result } = owner(scroller)
|
||||
revealCardIn(scroller, rowsByKey.get('edit:patch')!)
|
||||
setRect(scroller, 0, 0)
|
||||
setClientHeight(scroller, 0)
|
||||
result.current.onScrolled(0, true)
|
||||
expect(result.current.current()).toEqual({ key: 'edit:patch', offset: 400 })
|
||||
})
|
||||
|
||||
it('records the actual place after a clamped report and a compensation write', () => {
|
||||
const { scroller, rowsByKey } = runBox([
|
||||
{ top: -1_900, height: 1_000 },
|
||||
{ key: 'edit:patch', top: -900, height: 1_200 }
|
||||
])
|
||||
const { result } = owner(scroller)
|
||||
revealCardIn(scroller, rowsByKey.get('edit:patch')!)
|
||||
expect(result.current.current()).toEqual({ key: 'edit:patch', offset: 900 })
|
||||
|
||||
// The box could only reach 1,880.
|
||||
moveChildren(rowsByKey, { 'edit:patch': [-880, 1_200] })
|
||||
result.current.onScrolled(1_880, true)
|
||||
expect(result.current.current()).toEqual({ key: 'edit:patch', offset: 880 })
|
||||
|
||||
// The window's own compensation write (not the reader) moved it to 1,912.
|
||||
moveChildren(rowsByKey, { 'edit:patch': [-912, 1_200] })
|
||||
result.current.onScrolled(1_912, false)
|
||||
expect(result.current.current()).toEqual({ key: 'edit:patch', offset: 912 })
|
||||
expect(scroller.scrollTop).toBe(0)
|
||||
})
|
||||
|
||||
it('uses the model only where the box top lies in an undrawn gap', () => {
|
||||
// A wrapper for a row no longer in the run, then a spacer: the top is undrawn, so the model answers.
|
||||
const { scroller } = runBox([
|
||||
{ key: 'call:gone', top: -10, height: 40 },
|
||||
{ top: 30, height: 5_000 }
|
||||
])
|
||||
const { result } = owner(scroller)
|
||||
result.current.onScrolled(1_130, true)
|
||||
expect(result.current.current()).toEqual({ key: 'call:after-2', offset: 12 })
|
||||
})
|
||||
})
|
||||
-53
@@ -1,53 +0,0 @@
|
||||
// @vitest-environment happy-dom
|
||||
import { renderHook } from '@testing-library/react'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { consumePageFocusLossForTerminalIme } from './regular-terminal-focus-ownership'
|
||||
import { useRegularTerminalInputFocus } from './use-regular-terminal-input-focus'
|
||||
|
||||
function mountTerminal(): { helper: HTMLTextAreaElement; blur: ReturnType<typeof vi.spyOn> } {
|
||||
const container = document.createElement('div')
|
||||
const helper = document.createElement('textarea')
|
||||
helper.className = 'xterm-helper-textarea'
|
||||
container.appendChild(helper)
|
||||
document.body.appendChild(container)
|
||||
renderHook(() => useRegularTerminalInputFocus({ containerRef: { current: container } }))
|
||||
return { helper, blur: vi.spyOn(helper, 'blur') }
|
||||
}
|
||||
|
||||
function arriveFrom(helper: HTMLElement, relatedTarget: EventTarget | null): void {
|
||||
helper.dispatchEvent(new FocusEvent('focusin', { bubbles: true, relatedTarget }))
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
vi.spyOn(navigator, 'userAgent', 'get').mockReturnValue('Mozilla/5.0 (Macintosh)')
|
||||
vi.stubGlobal('requestAnimationFrame', () => 0)
|
||||
Object.assign(window, { api: { ui: {} } })
|
||||
consumePageFocusLossForTerminalIme()
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks()
|
||||
vi.unstubAllGlobals()
|
||||
document.body.replaceChildren()
|
||||
})
|
||||
|
||||
describe('useRegularTerminalInputFocus macOS input context rebuild', () => {
|
||||
it('rebuilds when focus returns from a browser page through the tab strip', () => {
|
||||
const { helper, blur } = mountTerminal()
|
||||
const tab = document.createElement('div')
|
||||
|
||||
window.dispatchEvent(new Event('blur'))
|
||||
arriveFrom(helper, tab)
|
||||
|
||||
expect(blur).toHaveBeenCalledOnce()
|
||||
})
|
||||
|
||||
it('rebuilds when focus comes from a renderer text field', () => {
|
||||
const { helper, blur } = mountTerminal()
|
||||
const addressBar = document.createElement('input')
|
||||
|
||||
arriveFrom(helper, addressBar)
|
||||
|
||||
expect(blur).toHaveBeenCalledOnce()
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user