From 07ea4b027d9ef6db2d2ea3e46d91755eec9b0e3f Mon Sep 17 00:00:00 2001 From: Brennan Benson <79079362+brennanb2025@users.noreply.github.com> Date: Mon, 9 Nov 2026 16:58:01 -0800 Subject: [PATCH] Correct mobile preview test typing and positional page identity --- .../MobileNativeChatAsk.previews.test.tsx | 19 +++++++++++++------ .../MobileNativeChatOptionPreviewSheet.tsx | 2 +- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/mobile/src/session/native-chat/input/MobileNativeChatAsk.previews.test.tsx b/mobile/src/session/native-chat/input/MobileNativeChatAsk.previews.test.tsx index 115a33af8d1..c3c98e173d0 100644 --- a/mobile/src/session/native-chat/input/MobileNativeChatAsk.previews.test.tsx +++ b/mobile/src/session/native-chat/input/MobileNativeChatAsk.previews.test.tsx @@ -1,6 +1,6 @@ import { createElement, type ReactNode } from 'react' import { act, create, type ReactTestInstance, type ReactTestRenderer } from 'react-test-renderer' -import { afterEach, expect, it, vi } from 'vitest' +import { afterEach, expect, it, vi, type Mock } from 'vitest' import type { AskPrompt } from '../../../../../src/shared/native-chat/input/native-chat-ask-types' import { MobileNativeChatAsk } from './MobileNativeChatAsk' @@ -74,8 +74,9 @@ function textAction(label: string): ReactTestInstance { function press(node: ReactTestInstance): void { act(() => node.props.onPress()) } -function mount(value: AskPrompt): ReturnType { - const onAnswer = vi.fn(async () => true) +type Answer = Parameters[0]['onAnswer'] +function mount(value: AskPrompt): Mock { + const onAnswer = vi.fn(async () => true) act(() => { renderer = create(createElement(MobileNativeChatAsk, { prompt: value, onAnswer })) }) @@ -106,12 +107,16 @@ it('inspects every preview without choosing, and keeps the original option when .some((node) => node.children.includes(compactedPreview)) ).toBe(true) press(button('Close viewer')) - act(() => vi.runAllTimers()) + act(() => { + vi.runAllTimers() + }) expect(onAnswer).not.toHaveBeenCalled() expect(row(2).props.accessibilityState.checked).toBe(false) press(button('Last preview')) press(button('Choose this')) - act(() => vi.runAllTimers()) + act(() => { + vi.runAllTimers() + }) expect(row(2).props.accessibilityState.checked).toBe(true) expect(onAnswer).not.toHaveBeenCalled() press(button('Last preview')) @@ -142,7 +147,9 @@ it('retains automatic answer for an ordinary question and disables the viewer ch plain.questions[0]!.options = [{ label: 'Plain' }] const onAnswer = mount(plain) press(row(0)) - await act(async () => vi.runAllTimers()) + await act(async () => { + vi.runAllTimers() + }) expect(onAnswer).toHaveBeenCalledWith([{ indices: [0] }], expect.any(Function)) act(() => renderer.unmount()) act(() => { diff --git a/mobile/src/session/native-chat/input/MobileNativeChatOptionPreviewSheet.tsx b/mobile/src/session/native-chat/input/MobileNativeChatOptionPreviewSheet.tsx index 908d5c2f6b2..e746a9db5d5 100644 --- a/mobile/src/session/native-chat/input/MobileNativeChatOptionPreviewSheet.tsx +++ b/mobile/src/session/native-chat/input/MobileNativeChatOptionPreviewSheet.tsx @@ -56,7 +56,7 @@ export function MobileNativeChatOptionPreviewSheet({ })} onClose={onClose} /> - + {previews.length > 1 ? (