Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion mobile/src/session/MobileNativeChatMessage.paced-reveal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import {
MobileNativeChatReplyRevealsContext,
type MobileNativeChatReplyReveals
} from './mobile-native-chat-reply-reveals'
import {
createMobileNativeChatGrowthHold,
MobileNativeChatGrowthHoldContext
} from './mobile-native-chat-growth-hold'

vi.mock('react-native', () => ({
Image: 'Image',
Expand Down Expand Up @@ -39,6 +43,8 @@ const second = first + 'more '.repeat(40)
describe('a growing reply on the phone', () => {
let renderer: ReactTestRenderer | undefined
let chat: MobileNativeChatReplyReveals
// The page's hold on growth, as a reader who scrolled up moves.
let growth = createMobileNativeChatGrowthHold()

function render(text: string | string[], working = true, runningTool = false): void {
const message: NativeChatMessage = {
Expand All @@ -59,7 +65,16 @@ describe('a growing reply on the phone', () => {
mayStillGrow: working,
activeTurnIsWorking: true
})
const tree = createElement(MobileNativeChatReplyRevealsContext.Provider, { value: chat }, row)
const revealing = createElement(
MobileNativeChatReplyRevealsContext.Provider,
{ value: chat },
row
)
const tree = createElement(
MobileNativeChatGrowthHoldContext.Provider,
{ value: growth },
revealing
)
act(() => {
if (renderer) {
renderer.update(tree)
Expand Down Expand Up @@ -101,6 +116,7 @@ describe('a growing reply on the phone', () => {
afterEach(() => {
act(() => renderer?.unmount())
renderer = undefined
growth = createMobileNativeChatGrowthHold()
vi.unstubAllGlobals()
vi.restoreAllMocks()
vi.useRealTimers()
Expand Down Expand Up @@ -128,6 +144,17 @@ describe('a growing reply on the phone', () => {
expect(drawn()).toBe(second.length)
})

it('waits while the page holds growth, then catches up in one step', () => {
growth.set(true)
render(first)
const shown = drawn()
advance(DELAY * 2)
expect(drawn()).toBe(shown)
act(() => growth.set(false))
advance(16)
expect(drawn()).toBe(first.length)
})

it.each([false, true])('paces a second prose block after the first caught up: %s', (caughtUp) => {
render(first)
advance(caughtUp ? DELAY : DELAY / 2)
Expand Down
2 changes: 1 addition & 1 deletion mobile/src/session/MobileNativeChatMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
MobileNativeChatGroupedThought,
MobileNativeChatReasoningRow
} from './MobileNativeChatReasoningRow'
import { mobileNativeChatRowId } from './MobileNativeChatScrollHold'
import { mobileNativeChatRowId } from './mobile-native-chat-reading-place'
import { nativeChatWorkRunEntries } from '../../../src/shared/native-chat-work-run'
import { nativeChatReasoningDisclosureKey } from '../../../src/shared/native-chat-reasoning-row'
import { MobileNativeChatTurnStatus } from './MobileNativeChatTurnStatus'
Expand Down
Loading
Loading