mirror of
https://github.com/stablyai/orca.git
synced 2026-11-19 04:23:57 +00:00
* fix(native-chat): show the "Working for" bar while a turn runs The turn bar under the user's message only rendered once a turn settled, so a running turn had no bar, only the spinner line at the tail. The running turn now draws the same bar with a live clock, and it settles in place to "Worked for". The tail line keeps its spinner but drops the clock, so the clock is said once: activity text, else "Thinking", else "Working…". Mobile gets the same split. * fix(native-chat): keep the turn bar mounted through the settle When a turn ends without a host-recorded duration (a send folded into a running turn, or a host that stamps no start), the local duration is stamped one pass after the working flag drops. For that pass the turn status resolved to nothing, so the live "Working for" bar unmounted and remounted as "Worked for" - invisible on desktop (layout effect) but a painted blink on mobile, where the stamp runs in a passive effect. The shared selector now keeps the just-ended turn's running status until its duration lands, unless the host says it never saw the end, and mobile reads the active turn's row from that selector the way desktop does.
126 lines
4.5 KiB
TypeScript
126 lines
4.5 KiB
TypeScript
import { createElement } from 'react'
|
|
import { act, create, type ReactTestInstance, type ReactTestRenderer } from 'react-test-renderer'
|
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
vi.mock('react-native', async () => {
|
|
const React = await import('react')
|
|
const Text = ({ children, ...props }: { children?: unknown }): unknown =>
|
|
React.createElement('Text', props, children)
|
|
return {
|
|
ActivityIndicator: (props: Record<string, unknown>) =>
|
|
React.createElement('ActivityIndicator', props),
|
|
Pressable: ({ children, ...props }: { children?: unknown }) =>
|
|
React.createElement('Pressable', props, children),
|
|
Text,
|
|
View: ({ children, ...props }: { children?: unknown }) =>
|
|
React.createElement('View', props, children),
|
|
StyleSheet: { create: (styles: unknown) => styles, hairlineWidth: 1 }
|
|
}
|
|
})
|
|
vi.mock('lucide-react-native', () => ({ ChevronRight: 'ChevronRight' }))
|
|
|
|
import {
|
|
MobileNativeChatTurnActivity,
|
|
MobileNativeChatTurnStatus
|
|
} from './MobileNativeChatTurnStatus'
|
|
|
|
const labels = (node: ReactTestInstance): string[] =>
|
|
node.findAllByType('Text' as never).map((text) => String(text.children.join('')))
|
|
|
|
const spinners = (node: ReactTestInstance): ReactTestInstance[] =>
|
|
node.findAllByType('ActivityIndicator' as never)
|
|
|
|
let renderer: ReactTestRenderer | null = null
|
|
|
|
beforeEach(() => {
|
|
vi.useFakeTimers()
|
|
vi.setSystemTime(new Date('2026-09-04T00:00:00Z'))
|
|
})
|
|
|
|
afterEach(() => {
|
|
act(() => renderer?.unmount())
|
|
renderer = null
|
|
vi.useRealTimers()
|
|
})
|
|
|
|
describe('MobileNativeChatTurnStatus', () => {
|
|
function render(props: {
|
|
startedAt: number | null
|
|
workedSeconds?: number | null
|
|
expanded?: boolean
|
|
onToggleExpanded?: () => void
|
|
}): ReactTestRenderer {
|
|
act(() => {
|
|
renderer = create(createElement(MobileNativeChatTurnStatus, props))
|
|
})
|
|
return renderer!
|
|
}
|
|
|
|
it('counts up from the first second while the turn runs, with no spinner', () => {
|
|
const tree = render({ startedAt: Date.now() })
|
|
expect(labels(tree.root)).toEqual(['Working for 0s'])
|
|
act(() => {
|
|
vi.advanceTimersByTime(12_000)
|
|
})
|
|
expect(labels(tree.root)).toEqual(['Working for 12s'])
|
|
expect(spinners(tree.root)).toHaveLength(0)
|
|
})
|
|
|
|
it('settles to a tappable "Worked for" row that toggles the turn', () => {
|
|
const onToggleExpanded = vi.fn()
|
|
const tree = render({ startedAt: Date.now(), workedSeconds: 184, onToggleExpanded })
|
|
expect(labels(tree.root)).toEqual(['Worked for 3m 4s'])
|
|
const button = tree.root.findByType('Pressable' as never)
|
|
expect(button.props.accessibilityLabel).toBe('Toggle turn details')
|
|
expect(button.props.accessibilityState).toEqual({ expanded: false })
|
|
act(() => button.props.onPress())
|
|
expect(onToggleExpanded).toHaveBeenCalledOnce()
|
|
})
|
|
|
|
it('stays a plain row when the settled turn has nothing to disclose', () => {
|
|
const tree = render({ startedAt: Date.now(), workedSeconds: 5 })
|
|
expect(tree.root.findAllByType('Pressable' as never)).toHaveLength(0)
|
|
expect(labels(tree.root)).toEqual(['Worked for 5s'])
|
|
})
|
|
|
|
it('holds no interval once the turn has settled', () => {
|
|
render({ startedAt: Date.now(), workedSeconds: 5 })
|
|
expect(vi.getTimerCount()).toBe(0)
|
|
})
|
|
})
|
|
|
|
describe('MobileNativeChatTurnActivity', () => {
|
|
function render(props: { thinking: boolean; activityText?: string | null }): ReactTestRenderer {
|
|
act(() => {
|
|
renderer = create(createElement(MobileNativeChatTurnActivity, props))
|
|
})
|
|
return renderer!
|
|
}
|
|
|
|
it('reads "Thinking" beside one spinner while the turn reasons', () => {
|
|
const tree = render({ thinking: true })
|
|
expect(labels(tree.root)).toEqual(['Thinking'])
|
|
expect(spinners(tree.root)).toHaveLength(1)
|
|
})
|
|
|
|
// The bar owns the clock; the tail line never repeats it.
|
|
it('reads plain "Working…" when the turn is not reasoning, and holds no timer', () => {
|
|
const tree = render({ thinking: false })
|
|
expect(labels(tree.root)).toEqual(['Working…'])
|
|
expect(vi.getTimerCount()).toBe(0)
|
|
})
|
|
|
|
it('lets provider activity text beat both fallbacks', () => {
|
|
const tree = render({ thinking: true, activityText: 'Running pnpm test' })
|
|
expect(labels(tree.root)).toEqual(['Running pnpm test'])
|
|
expect(spinners(tree.root)).toHaveLength(1)
|
|
})
|
|
|
|
it('announces the live line to assistive tech', () => {
|
|
const tree = render({ thinking: true })
|
|
const row = tree.root.findByType('View' as never)
|
|
expect(row.props.accessibilityLiveRegion).toBe('polite')
|
|
expect(row.props.accessibilityLabel).toBe('Agent is responding')
|
|
})
|
|
})
|