mirror of
https://github.com/stablyai/orca.git
synced 2026-11-19 04:23:57 +00:00
* fix(native-chat): hide activity while awaiting input * fix(native-chat): keep approval turns cancellable * test(native-chat): satisfy split PR quality gate * fix(native-chat): catalog approval cancellation label * fix(native-chat): include approval cancellation runtime label * fix(codex): settle prompts when cancelled turns complete * fix(codex): settle prompt registry fallbacks * test(native-chat): cover pending interaction fallbacks * test(native-chat): split prompt state coverage * test(native-chat): keep prompt state isolated * fix(native-chat): bound prompt turn backfill * refactor(codex): centralize prompt registry bounds * fix(native-chat): cancel pending prompts precisely * fix(native-chat): consolidate capability imports * fix(native-chat): harden precise prompt cancellation * fix claude cancellation teardown races * retry claude prompt lifecycle admission * bound claude prompt cancellation retry work * fix(codex): bound prompt turn identity on registration * fix(native-chat): route rejected late dispatch settlements * fix(codex): retain exact cancellable prompt turn ids --------- Co-authored-by: Merge Sim <sim@local>
131 lines
4.0 KiB
TypeScript
131 lines
4.0 KiB
TypeScript
import { createElement } from 'react'
|
|
import { act, create, type ReactTestRenderer } from 'react-test-renderer'
|
|
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
import { MobileNativeChatQuestion } from './MobileNativeChatQuestion'
|
|
|
|
vi.mock('react-native', () => ({
|
|
Pressable: 'Pressable',
|
|
StyleSheet: { create: (styles: unknown) => styles, hairlineWidth: 1 },
|
|
Text: 'Text',
|
|
TextInput: 'TextInput',
|
|
View: 'View'
|
|
}))
|
|
|
|
vi.mock('lucide-react-native', () => ({
|
|
ArrowUp: 'ArrowUp',
|
|
Check: 'Check',
|
|
CircleHelp: 'CircleHelp',
|
|
X: 'X'
|
|
}))
|
|
|
|
describe('MobileNativeChatQuestion', () => {
|
|
let renderer: ReactTestRenderer | null = null
|
|
|
|
afterEach(() => {
|
|
act(() => renderer?.unmount())
|
|
renderer = null
|
|
})
|
|
|
|
it('submits the selected duplicate-label row by position', async () => {
|
|
const onAnswer = vi.fn(async () => true)
|
|
|
|
await act(async () => {
|
|
renderer = create(
|
|
createElement(MobileNativeChatQuestion, {
|
|
question: {
|
|
question: 'Pick regions',
|
|
options: ['Region', 'Region'],
|
|
multiSelect: true,
|
|
allowOther: false,
|
|
optionTokens: ['first-token', 'second-token']
|
|
},
|
|
onAnswer
|
|
})
|
|
)
|
|
})
|
|
|
|
const choices = renderer.root.findAllByProps({ accessibilityRole: 'checkbox' })
|
|
await act(async () => choices[1]!.props.onPress())
|
|
const submit = renderer.root.findByProps({ accessibilityLabel: 'Submit selected options' })
|
|
await act(async () => submit.props.onPress())
|
|
|
|
expect(onAnswer).toHaveBeenCalledWith('second-token')
|
|
})
|
|
|
|
it('submits a tokenless duplicate-label row by position', async () => {
|
|
const onAnswer = vi.fn(async () => true)
|
|
|
|
await act(async () => {
|
|
renderer = create(
|
|
createElement(MobileNativeChatQuestion, {
|
|
question: {
|
|
question: 'Pick one',
|
|
options: ['Choice', 'Choice'],
|
|
multiSelect: false,
|
|
allowOther: false,
|
|
optionTokens: ['first-token', null]
|
|
},
|
|
onAnswer
|
|
})
|
|
)
|
|
})
|
|
|
|
const choices = renderer.root.findAllByProps({ accessibilityRole: 'button' })
|
|
await act(async () => choices[1]!.props.onPress())
|
|
|
|
expect(onAnswer).toHaveBeenCalledWith('Choice')
|
|
})
|
|
|
|
it('submits structured multi-select choices together with other text', async () => {
|
|
const onAnswer = vi.fn(async () => true)
|
|
|
|
await act(async () => {
|
|
renderer = create(
|
|
createElement(MobileNativeChatQuestion, {
|
|
question: {
|
|
question: 'Pick regions',
|
|
options: ['us-east', 'eu-west'],
|
|
multiSelect: true,
|
|
allowOther: true,
|
|
optionTokens: ['east-token', 'west-token'],
|
|
freeTextToken: 'other-token'
|
|
},
|
|
onAnswer
|
|
})
|
|
)
|
|
})
|
|
|
|
const choices = renderer.root.findAllByProps({ accessibilityRole: 'checkbox' })
|
|
await act(async () => choices[0]!.props.onPress())
|
|
const input = renderer.root.findByType('TextInput')
|
|
await act(async () => input.props.onChangeText('ap-south'))
|
|
const submit = renderer.root.findByProps({ accessibilityLabel: 'Submit selected options' })
|
|
await act(async () => submit.props.onPress())
|
|
|
|
expect(onAnswer).toHaveBeenCalledWith('east-token, other-token:ap-south')
|
|
})
|
|
|
|
it('passes the rendered prompt identity to cancel', async () => {
|
|
const onCancel = vi.fn(async () => true)
|
|
await act(async () => {
|
|
renderer = create(
|
|
createElement(MobileNativeChatQuestion, {
|
|
question: {
|
|
question: 'Pick one',
|
|
prompt: { itemId: 'question-1', expectedRevision: 7 },
|
|
options: ['Choice'],
|
|
multiSelect: false,
|
|
allowOther: false,
|
|
optionTokens: ['choice-token']
|
|
},
|
|
onAnswer: vi.fn(async () => true),
|
|
onCancel
|
|
})
|
|
)
|
|
})
|
|
const cancel = renderer.root.findByProps({ accessibilityLabel: 'Cancel' })
|
|
await act(async () => cancel.props.onPress())
|
|
expect(onCancel).toHaveBeenCalledWith({ itemId: 'question-1', expectedRevision: 7 })
|
|
})
|
|
})
|