diff --git a/mobile/src/session/native-chat/input/MobileNativeChatQueuedMessages.test.tsx b/mobile/src/session/native-chat/input/MobileNativeChatQueuedMessages.test.tsx deleted file mode 100644 index 095cb498a17..00000000000 --- a/mobile/src/session/native-chat/input/MobileNativeChatQueuedMessages.test.tsx +++ /dev/null @@ -1,719 +0,0 @@ -// @vitest-environment happy-dom -import { activateMobileUiLocale } from '../../../i18n/mobile-i18n' -import type { MobileQueuedMessageCard } from './mobile-structured-queued-message-cards' - -import { createElement, type ReactElement } from 'react' - -import { act, create, type ReactTestRenderer } from 'react-test-renderer' -import { afterEach, describe, expect, it, vi } from 'vitest' - -import { MobileNativeChatQueuedMessages } from './MobileNativeChatQueuedMessages' -import type { ActionSheetAction } from '../../../components/ActionSheetModal' -import { MobileNativeChatQueueAbovePromptContext } from '../mobile-native-chat-lower-region-context' -import { createMobileQueuedHeadLight } from './mobile-queued-head-light' -import { QUEUED_ROW_SHOW_SETTLE_MS } from './mobile-queued-row-frame' -import { queuedMessageStyles as styles } from './mobile-native-chat-queued-message-styles' -import { pressedStyle } from '../../../theme/mobile-theme' - -let fontScale = 1 -let windowWidth = 390 -vi.mock('../../../components/DragReorderList', () => ({ DragReorderList: 'DragReorderList' })) -vi.mock('react-native-reanimated', async () => { - const { useRef } = await import('react') - return { - default: { ScrollView: 'ScrollView' }, - useAnimatedRef: () => useRef(null), - useSharedValue: (value: unknown) => useRef({ value }).current - } -}) - -vi.mock('react-native', () => ({ - useWindowDimensions: () => ({ fontScale, width: windowWidth }), - ActivityIndicator: 'ActivityIndicator', - Platform: { OS: 'ios' }, - Pressable: 'Pressable', - ScrollView: 'ScrollView', - StyleSheet: { create: (styles: unknown) => styles, hairlineWidth: 1 }, - Text: 'Text', - TextInput: 'TextInput', - View: 'View' -})) - -vi.mock('lucide-react-native', () => ({ - Image: 'Image', - AlertCircle: 'AlertCircle', - ArrowUpRight: 'ArrowUpRight', - Check: 'Check', - ChevronDown: 'ChevronDown', - ChevronUp: 'ChevronUp', - CornerDownRight: 'CornerDownRight', - ListEnd: 'ListEnd', - MoreHorizontal: 'MoreHorizontal', - Pencil: 'Pencil', - Play: 'Play', - Send: 'Send', - Trash2: 'Trash2', - X: 'X' -})) - -vi.mock('../../../components/ActionSheetModal', () => ({ ActionSheetModal: 'ActionSheetModal' })) -vi.mock('./MobileNativeChatBackgroundTasks', () => ({ - MobileNativeChatBackgroundTasks: 'BackgroundTasks' -})) -vi.mock('./MobileNativeChatDockedTaskList', () => ({ - MobileNativeChatDockedTaskList: 'DockedTaskList' -})) - -vi.mock('./MobileQueuedMessageComposer', () => ({ - MobileQueuedMessageComposer: 'QueuedMessageComposer' -})) - -function card( - overrides: Partial & { messageId: string } -): MobileQueuedMessageCard { - const text = overrides.text ?? `text of ${overrides.messageId}` - return { - position: 1, - text, - line: text, - state: 'waiting', - hold: overrides.state === 'returned' ? 'returned' : 'turn', - needsAttention: false, - caption: null, - ...overrides - } -} - -describe('MobileNativeChatQueuedMessages', () => { - let renderer: ReactTestRenderer | null = null - - afterEach(async () => { - vi.restoreAllMocks() - windowWidth = 390 - act(() => renderer?.unmount()) - renderer = null - await activateMobileUiLocale('en') - }) - - type Props = Parameters[0] - - function element(props: Props, abovePrompt = false): ReactElement { - return createElement( - MobileNativeChatQueueAbovePromptContext, - { value: abovePrompt }, - createElement(MobileNativeChatQueuedMessages, props) - ) - } - - async function mount(props: Props, abovePrompt = false): Promise { - const mounted = create(createElement('View')) - renderer = mounted - await act(async () => { - mounted.update(element(props, abovePrompt)) - }) - return mounted - } - - function rows(mounted: ReactTestRenderer) { - return mounted.root.findAll( - (node) => typeof node.type === 'string' && node.props.testID === 'queued-card-row' - ) - } - - function foldToggle(mounted: ReactTestRenderer) { - return mounted.root.find( - (node) => typeof node.type === 'string' && node.props.testID === 'queued-fold-toggle' - ) - } - - function menuAction(mounted: ReactTestRenderer, id: string) { - const actions: ActionSheetAction[] = sheet(mounted).props.actions - return actions.find((action) => action.id === id) - } - - function dragList(mounted: ReactTestRenderer) { - return mounted.root.findAll((node) => String(node.type) === 'DragReorderList') - } - - const three = () => [card({ messageId: 'a' }), card({ messageId: 'b' }), card({ messageId: 'c' })] - - function control(mounted: ReactTestRenderer, label: string, index = 0) { - return mounted.root.findAll( - (node) => typeof node.type === 'string' && node.props.accessibilityLabel === label - )[index]! - } - - function sheet(mounted: ReactTestRenderer) { - return mounted.root.find((node) => String(node.type) === 'ActionSheetModal') - } - - it("closes a card's menu for good once the card leaves, even if it comes back", async () => { - const mounted = await mount({ cards: [card({ messageId: 'a' }), card({ messageId: 'b' })] }) - await act(async () => - mounted.root.findAllByProps({ accessibilityLabel: 'More actions' })[0]!.props.onPress() - ) - expect(sheet(mounted).props.visible).toBe(true) - await act(async () => { - mounted.update(element({ cards: [card({ messageId: 'b' })] })) - }) - expect(sheet(mounted).props.visible).toBe(false) - await act(async () => { - mounted.update(element({ cards: [card({ messageId: 'a' }), card({ messageId: 'b' })] })) - }) - expect(sheet(mounted).props.visible).toBe(false) - }) - - it('runs one action per card at a time, however fast its controls are tapped', async () => { - let answer: (done: boolean) => void = () => undefined - const onSend = vi.fn(() => new Promise((resolve) => (answer = resolve))) - const onDelete = vi.fn(async () => true) - const mounted = await mount({ cards: [card({ messageId: 'w' })], onSend, onDelete }) - await act(async () => control(mounted, 'More actions').props.onPress()) - // Tap all actions before disabled state renders to expose same-frame duplication. - await act(async () => { - control(mounted, 'Send this message').props.onPress() - control(mounted, 'Send this message').props.onPress() - menuAction(mounted, 'deleteMessage')!.onPress() - }) - expect(onSend).toHaveBeenCalledTimes(1) - expect(onDelete).not.toHaveBeenCalled() - expect(control(mounted, 'More actions').props.disabled).toBe(true) - expect(menuAction(mounted, 'deleteMessage')!.disabled).toBe(true) - await act(async () => answer(true)) - expect(control(mounted, 'Send this message').props.disabled).toBe(false) - }) - - it('folds to the first message above a prompt card and opens from the more row', async () => { - const mounted = await mount({ cards: three() }, true) - expect(rows(mounted)).toHaveLength(1) - expect(foldToggle(mounted).props.accessibilityState).toEqual({ expanded: false }) - await act(async () => foldToggle(mounted).props.onPress()) - expect(rows(mounted)).toHaveLength(3) - expect(foldToggle(mounted).props.accessibilityState).toEqual({ expanded: true }) - await act(async () => foldToggle(mounted).props.onPress()) - expect(rows(mounted)).toHaveLength(1) - }) - - it.each([390, 320])( - 'lets the open list, not the fold row, give up height on a short %ipt screen', - async (width) => { - windowWidth = width - const mounted = await mount({ cards: three() }, true) - await act(async () => foldToggle(mounted).props.onPress()) - const flat = (style: unknown): Record => - Object.assign({}, ...[style].flat(Infinity).filter(Boolean)) - const box = mounted.root.find( - (node) => typeof node.type === 'string' && node.props.testID === 'queued-box' - ) - const scroll = mounted.root.find((node) => String(node.type) === 'ScrollView') - // The box shrinks under a height limit; the list scrolls so Show less below it stays whole. - expect(flat(box.props.style)).toMatchObject({ flexShrink: 1, minHeight: 0 }) - expect(flat(scroll.parent!.props.style)).toMatchObject({ flexShrink: 1, minHeight: 0 }) - expect(flat(scroll.props.style)).toMatchObject({ - maxHeight: width < 340 ? 264 : 212, - flexShrink: 1, - minHeight: 0 - }) - expect(flat(foldToggle(mounted).props.style({ pressed: false })).flexShrink).toBeUndefined() - } - ) - - it('opens by default above the composer, and folds again when a prompt card arrives', async () => { - const mounted = await mount({ cards: three() }) - expect(rows(mounted)).toHaveLength(3) - await act(async () => mounted.update(element({ cards: three() }, true))) - expect(rows(mounted)).toHaveLength(1) - }) - - it('folds again for a later prompt after the person opened the list above an earlier one', async () => { - const mounted = await mount({ cards: three() }, true) - await act(async () => foldToggle(mounted).props.onPress()) - expect(rows(mounted)).toHaveLength(3) - await act(async () => mounted.update(element({ cards: three() }))) - await act(async () => mounted.update(element({ cards: three() }, true))) - expect(rows(mounted)).toHaveLength(1) - }) - - it('opens for a message queued in the same render a prompt arrives', async () => { - const mounted = await mount({ cards: three() }) - // Folded by hand above the composer, then a prompt and a new own message arrive together. - await act(async () => foldToggle(mounted).props.onPress()) - expect(rows(mounted)).toHaveLength(1) - await act(async () => - mounted.update(element({ cards: [...three(), card({ messageId: 'd' })] }, true)) - ) - expect(rows(mounted)).toHaveLength(4) - }) - - it('scrolls a message the person queues into a folded list into view', async () => { - const scrollTo = vi.fn() - const mounted = create(createElement('View'), { - createNodeMock: (node) => - node.type === 'ScrollView' - ? { scrollTo, scrollToEnd: vi.fn(), flashScrollIndicators: vi.fn() } - : null - }) - renderer = mounted - await act(async () => mounted.update(element({ cards: three() }, true))) - await act(async () => - mounted.update(element({ cards: [...three(), card({ messageId: 'd' })] }, true)) - ) - expect(rows(mounted)).toHaveLength(4) - const scroll = mounted.root.find((node) => String(node.type) === 'ScrollView') - await act(async () => { - rows(mounted).forEach((row) => - row.props.onLayout({ nativeEvent: { layout: { height: 60 } } }) - ) - scroll.props.onLayout({ nativeEvent: { layout: { height: 100 } } }) - scroll.props.onContentSizeChange(0, 240) - }) - // The new last row spans 180–240 of a 100pt list. - expect(scrollTo).toHaveBeenLastCalledWith({ y: 140, animated: false }) - }) - - it("opens a folded list for a message the person queues, not for an agent's or a delete", async () => { - const mounted = await mount({ cards: three() }, true) - await act(async () => - mounted.update( - element( - { - cards: [ - ...three(), - card({ messageId: 'x', from: { kind: 'agent', senders: [], orchestration: null } }) - ] - }, - true - ) - ) - ) - expect(rows(mounted)).toHaveLength(1) - await act(async () => mounted.update(element({ cards: three().slice(0, 2) }, true))) - expect(rows(mounted)).toHaveLength(1) - await act(async () => - mounted.update(element({ cards: [...three().slice(0, 2), card({ messageId: 'd' })] }, true)) - ) - expect(rows(mounted)).toHaveLength(3) - }) - - it('opens a folded list for a failed message behind the fold, with its Send in reach', async () => { - const foldText = (mounted: ReactTestRenderer) => - foldToggle(mounted) - .findAll((node) => String(node.type) === 'Text') - .flatMap((node) => node.props.children) - .join('') - const failed = (messageId: string) => - card({ messageId, needsAttention: true, caption: "Couldn't send" }) - const mounted = await mount( - { - cards: [card({ messageId: 'a' }), failed('b'), card({ messageId: 'c' })], - agentWorking: true - }, - true - ) - expect(rows(mounted)).toHaveLength(3) - // Mid-turn the others steer, but the failed card offers its retry, Send. - const pills = mounted.root.findAll( - (node) => - typeof node.type === 'string' && - typeof node.props.accessibilityLabel === 'string' && - node.props.hitSlop !== undefined - ) - expect(pills.map((node) => node.props.accessibilityLabel)).toEqual([ - 'Submit without interrupting the model', - 'Send this message', - 'Submit without interrupting the model' - ]) - expect(pills[1]!.props.disabled).toBe(false) - expect(foldText(mounted)).not.toContain("Couldn't send") - // Folding is still the person's call, and the fold row only counts. - await act(async () => foldToggle(mounted).props.onPress()) - expect(rows(mounted)).toHaveLength(1) - expect(foldText(mounted)).toBe('2 more') - expect( - foldToggle(mounted).findAll((node) => String(node.type) === 'Text')[0]!.props - .accessibilityLabel - ).toBe('2 more, a message needs attention') - // An agent's new message does not reopen it for a failure the person already folded away. - await act(async () => - mounted.update( - element( - { - cards: [ - card({ messageId: 'a' }), - failed('b'), - card({ messageId: 'c' }), - card({ messageId: 'z', from: { kind: 'agent', senders: [], orchestration: null } }) - ] - }, - true - ) - ) - ) - expect(rows(mounted)).toHaveLength(1) - // A second card failing later opens it again. - await act(async () => - mounted.update(element({ cards: [card({ messageId: 'a' }), failed('b'), failed('c')] }, true)) - ) - expect(rows(mounted)).toHaveLength(3) - }) - - it('scrolls a failure that opens a short list into view', async () => { - const scrollTo = vi.fn() - const mounted = create(createElement('View'), { - createNodeMock: (node) => - node.type === 'ScrollView' - ? { scrollTo, scrollToEnd: vi.fn(), flashScrollIndicators: vi.fn() } - : null - }) - renderer = mounted - await act(async () => mounted.update(element({ cards: three() }, true))) - const failedThird = [ - card({ messageId: 'a' }), - card({ messageId: 'b' }), - card({ messageId: 'c', needsAttention: true, caption: "Couldn't send" }) - ] - await act(async () => mounted.update(element({ cards: failedThird }, true))) - expect(rows(mounted)).toHaveLength(3) - // Rows report before the list knows its own size, as when it has just opened. - await act(async () => { - rows(mounted).forEach((row, index) => - row.props.onLayout({ nativeEvent: { layout: { height: index === 2 ? 80 : 60 } } }) - ) - }) - expect(scrollTo).not.toHaveBeenCalled() - const scroll = mounted.root.find((node) => String(node.type) === 'ScrollView') - await act(async () => { - scroll.props.onLayout({ nativeEvent: { layout: { height: 100 } } }) - scroll.props.onContentSizeChange(0, 200) - }) - // The failed row spans 120–200 of a 100pt list, so the list scrolls to its end. - expect(scrollTo).toHaveBeenCalledWith({ y: 100, animated: false }) - }) - - it('places a failed row by the current order after a reorder that lays nothing out', async () => { - vi.useFakeTimers() - try { - const scrollTo = vi.fn() - const mounted = create(createElement('View'), { - createNodeMock: (node) => - node.type === 'ScrollView' - ? { scrollTo, scrollToEnd: vi.fn(), flashScrollIndicators: vi.fn() } - : null - }) - renderer = mounted - const ids = (order: string) => [...order].map((messageId) => card({ messageId })) - await act(async () => mounted.update(element({ cards: ids('abcd') }))) - const scroll = mounted.root.find((node) => String(node.type) === 'ScrollView') - await act(async () => { - scroll.props.onLayout({ nativeEvent: { layout: { height: 100 } } }) - scroll.props.onContentSizeChange(0, 240) - rows(mounted).forEach((row) => - row.props.onLayout({ nativeEvent: { layout: { height: 60 } } }) - ) - }) - // Equal-height rows reordered by transform: no row lays out again. - await act(async () => mounted.update(element({ cards: ids('bcda') }))) - scrollTo.mockClear() - await act(async () => - mounted.update( - element({ - cards: [...ids('bcd'), card({ messageId: 'a', needsAttention: true })] - }) - ) - ) - await act(async () => { - vi.advanceTimersByTime(QUEUED_ROW_SHOW_SETTLE_MS) - }) - // a is now last, spanning 180–240 of a 100pt list, not first. - expect(scrollTo).toHaveBeenCalledWith({ y: 140, animated: false }) - } finally { - vi.useRealTimers() - } - }) - - it('places a failed row by the height a returning message lays out at, not the one it left with', async () => { - const scrollTo = vi.fn() - const mounted = create(createElement('View'), { - createNodeMock: (node) => - node.type === 'ScrollView' - ? { scrollTo, scrollToEnd: vi.fn(), flashScrollIndicators: vi.fn() } - : null - }) - renderer = mounted - // Rows render in queue order. - const layRow = async (index: number, height: number) => { - const row = rows(mounted)[index]! - await act(async () => row.props.onLayout({ nativeEvent: { layout: { height } } })) - } - await act(async () => - mounted.update( - element({ - cards: [card({ messageId: 'a' }), card({ messageId: 'b' }), card({ messageId: 'c' })] - }) - ) - ) - const scroll = mounted.root.find((node) => String(node.type) === 'ScrollView') - await act(async () => { - scroll.props.onLayout({ nativeEvent: { layout: { height: 100 } } }) - scroll.props.onContentSizeChange(0, 300) - }) - // b leaves tall (an open editor or expanded text), then comes back as a plain 60pt row. - await layRow(0, 60) - await layRow(1, 180) - await layRow(2, 60) - await act(async () => - mounted.update(element({ cards: [card({ messageId: 'a' }), card({ messageId: 'c' })] })) - ) - scrollTo.mockClear() - await act(async () => - mounted.update( - element({ - cards: [ - card({ messageId: 'a' }), - card({ messageId: 'b' }), - card({ messageId: 'c', needsAttention: true, caption: "Couldn't send" }) - ] - }) - ) - ) - // The failed row reports before b does; b's old height must not place it. - await layRow(2, 60) - expect(scrollTo).not.toHaveBeenCalled() - await layRow(1, 60) - // c spans 120–180 of a 100pt list: the nearest scroll that shows it, clear of the edge fade. - expect(scrollTo).toHaveBeenCalledTimes(1) - expect(scrollTo).toHaveBeenCalledWith({ y: 96, animated: false }) - }) - - it('scrolls to a failure the list mounts open for, and settles when no row lays out again', async () => { - vi.useFakeTimers() - try { - const scrollTo = vi.fn() - const mounted = create(createElement('View'), { - createNodeMock: (node) => - node.type === 'ScrollView' - ? { scrollTo, scrollToEnd: vi.fn(), flashScrollIndicators: vi.fn() } - : null - }) - renderer = mounted - const failed = (messageId: string) => - card({ messageId, needsAttention: true, caption: "Couldn't send" }) - const lay = async (heights: number[]) => { - const scroll = mounted.root.find((node) => String(node.type) === 'ScrollView') - await act(async () => { - scroll.props.onLayout({ nativeEvent: { layout: { height: 100 } } }) - scroll.props.onContentSizeChange(0, 200) - rows(mounted).forEach((row, index) => - row.props.onLayout({ nativeEvent: { layout: { height: heights[index] } } }) - ) - }) - } - // Mounted above a prompt with a failure behind the fold: open, and its row is shown. - const opened = [card({ messageId: 'a' }), card({ messageId: 'b' }), failed('c')] - await act(async () => mounted.update(element({ cards: opened }, true))) - expect(rows(mounted)).toHaveLength(3) - await lay([60, 60, 80]) - expect(scrollTo).toHaveBeenLastCalledWith({ y: 100, animated: false }) - // Open above the composer, a row fails without changing height: no row lays out again, - // so the request settles on the heights the list already has. - await act(async () => - mounted.update( - element({ - cards: [card({ messageId: 'p' }), card({ messageId: 'q' }), card({ messageId: 'r' })] - }) - ) - ) - await lay([60, 60, 80]) - scrollTo.mockClear() - await act(async () => - mounted.update( - element({ cards: [card({ messageId: 'p' }), card({ messageId: 'q' }), failed('r')] }) - ) - ) - expect(scrollTo).not.toHaveBeenCalled() - await act(async () => { - vi.advanceTimersByTime(QUEUED_ROW_SHOW_SETTLE_MS) - }) - expect(scrollTo).toHaveBeenCalledWith({ y: 100, animated: false }) - } finally { - vi.useRealTimers() - } - }) - - it("places a failed row below an open inline editor at the editor's height", async () => { - const scrollTo = vi.fn() - const mounted = create(createElement('View'), { - createNodeMock: (node) => - node.type === 'ScrollView' - ? { scrollTo, scrollToEnd: vi.fn(), flashScrollIndicators: vi.fn() } - : null - }) - renderer = mounted - // oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: only messageId is read; the editor composer is mocked, so the RPC client is never touched. - const editor = { messageId: 'a' } as unknown as Props['editor'] - const cards = [card({ messageId: 'a' }), card({ messageId: 'b' }), card({ messageId: 'c' })] - await act(async () => mounted.update(element({ cards, editor }))) - await act(async () => - mounted.update( - element({ - cards: [cards[0]!, cards[1]!, card({ messageId: 'c', needsAttention: true })], - editor - }) - ) - ) - const scroll = mounted.root.find((node) => String(node.type) === 'ScrollView') - await act(async () => { - // The editor row is 200pt tall; the compact rows 60pt. - rows(mounted).forEach((row, index) => - row.props.onLayout({ - nativeEvent: { layout: { x: 0, y: 0, width: 0, height: index === 0 ? 200 : 60 } } - }) - ) - scroll.props.onLayout({ nativeEvent: { layout: { height: 100 } } }) - scroll.props.onContentSizeChange(0, 320) - }) - // The failed row spans 260–320, past the editor. - expect(scrollTo).toHaveBeenLastCalledWith({ y: 220, animated: false }) - }) - - it("fills the head's Steer pill while the composer previews Steer queued", async () => { - const headLight = createMobileQueuedHeadLight() - const mounted = await mount({ cards: three(), agentWorking: true, headLight }) - const pills = () => - mounted.root.findAll( - (node) => - typeof node.type === 'string' && - node.props.accessibilityLabel === 'Submit without interrupting the model' - ) - const label = (pill: ReturnType[number]) => - pill.find((node) => String(node.type) === 'Text').props.style - expect(pills()[0]!.props.style({ pressed: false })).not.toContain(styles.litAction) - await act(async () => headLight.set(true)) - const [head, second] = pills() - expect(head!.props.style({ pressed: false })).toContain(styles.litAction) - expect(label(head!)).toContain(styles.litActionLabel) - // A press still dims the filled pill. - const pressed = head!.props.style({ pressed: true }) - expect(pressed.indexOf(pressedStyle)).toBeGreaterThan(pressed.indexOf(styles.litAction)) - expect(second!.props.style({ pressed: false })).not.toContain(styles.litAction) - }) - - it('keeps a folded list folded when a whole new queue replaces it', async () => { - const mounted = await mount({ cards: three() }, true) - await act(async () => - mounted.update(element({ cards: [card({ messageId: 'p' }), card({ messageId: 'q' })] }, true)) - ) - expect(rows(mounted)).toHaveLength(1) - }) - - it('leads the first row with Queued and the spoken count, but not on a returned head', async () => { - const lead = (mounted: ReactTestRenderer) => - mounted.root.findAll( - (node) => typeof node.type === 'string' && node.props.accessibilityLiveRegion === 'polite' - ) - const mounted = await mount({ cards: three() }) - const [label] = lead(mounted) - expect(label!.props.accessibilityLabel).toBe('3 queued messages') - expect(label!.props.children).toBe('Queued') - await act(async () => mounted.update(element({ cards: [card({ messageId: 'a' })] }))) - expect(lead(mounted)[0]!.props.accessibilityLabel).toBe('1 queued message') - await act(async () => - mounted.update( - element({ cards: [card({ messageId: 'a', state: 'returned', caption: 'Returned' })] }) - ) - ) - expect(lead(mounted).some((node) => node.props.children === 'Queued')).toBe(false) - }) - - it('keeps an expanded message open across a fold and back', async () => { - const mounted = await mount({ cards: three() }) - const text = () => - mounted.root.findAll( - (node) => typeof node.type === 'function' && node.type.name === 'MobileQueuedCardText' - ) - await act(async () => text()[0]!.props.onToggle()) - expect(text()[0]!.props.expanded).toBe(true) - await act(async () => foldToggle(mounted).props.onPress()) - await act(async () => foldToggle(mounted).props.onPress()) - expect(text().map((node) => node.props.expanded)).toEqual([true, false, false]) - }) - - it('draws one message as a single row with no fold row', async () => { - const mounted = await mount({ cards: [card({ messageId: 'a' })] }, true) - expect(rows(mounted)).toHaveLength(1) - expect(mounted.root.findAll((node) => node.props.testID === 'queued-fold-toggle')).toHaveLength( - 0 - ) - }) - - it('offers drag only while two or more messages are open', async () => { - const onMove = vi.fn(async () => true) - const one = await mount({ cards: [card({ messageId: 'a' })], onMove }) - expect(dragList(one)).toHaveLength(0) - act(() => one.unmount()) - const folded = await mount({ cards: three(), onMove }, true) - expect(dragList(folded)).toHaveLength(0) - await act(async () => foldToggle(folded).props.onPress()) - expect(dragList(folded)).toHaveLength(1) - }) - - it("moves Delete into the row's menu and keeps Edit off a goal", async () => { - const onDelete = vi.fn(async () => true) - const onEdit = vi.fn(async () => true) - const mounted = await mount({ - cards: [card({ messageId: 'goal', command: true }), card({ messageId: 'text' })], - onDelete, - onEdit - }) - await act(async () => control(mounted, 'More actions', 0).props.onPress()) - expect(menuAction(mounted, 'editMessage')).toBeUndefined() - await act(async () => menuAction(mounted, 'deleteMessage')!.onPress()) - expect(onDelete).toHaveBeenCalledWith('goal') - await act(async () => control(mounted, 'More actions', 1).props.onPress()) - await act(async () => menuAction(mounted, 'editMessage')!.onPress()) - expect(onEdit).toHaveBeenCalledWith('text') - }) - - it('offers Clear all in the menu of a queue that still sends on its own', async () => { - const onClearAll = vi.fn(async () => true) - const mounted = await mount({ cards: three(), onClearAll, clearable: true }) - await act(async () => control(mounted, 'More actions').props.onPress()) - await act(async () => menuAction(mounted, 'clearAll')!.onPress()) - expect(onClearAll).toHaveBeenCalledWith(['a', 'b', 'c']) - }) - - describe('a paused queue', () => { - const waiting = card({ messageId: 'waiting-1', text: 'next' }) - - async function mountPaused( - props: Partial[0]> - ): Promise { - return mount({ - cards: [waiting], - onSend: vi.fn(async () => true), - onClearAll: vi.fn(async () => true), - ...props - }) - } - - function resumeButton(mounted: ReactTestRenderer) { - return control(mounted, 'Resume sending the queued messages') - } - - it('Resume admits one press at a time and releases a lost answer for retry', async () => { - let answer: (resumed: boolean) => void = () => undefined - const onResume = vi.fn(() => new Promise((resolve) => (answer = resolve))) - const mounted = await mountPaused({ pause: { reason: 'stopped' }, onResume }) - await act(async () => { - resumeButton(mounted).props.onPress() - resumeButton(mounted).props.onPress() - }) - expect(onResume).toHaveBeenCalledOnce() - expect(resumeButton(mounted).props.disabled).toBe(true) - await act(async () => answer(false)) - expect(resumeButton(mounted).props.disabled).toBe(false) - await act(async () => resumeButton(mounted).props.onPress()) - expect(onResume).toHaveBeenCalledTimes(2) - }) - }) -}) diff --git a/mobile/src/transport/connection/client-authority-epoch.test.ts b/mobile/src/transport/connection/client-authority-epoch.test.ts deleted file mode 100644 index 90693582755..00000000000 --- a/mobile/src/transport/connection/client-authority-epoch.test.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { describe, expect, it } from 'vitest' -import { createClientAuthorityEpoch } from './client-authority-epoch' - -describe('createClientAuthorityEpoch', () => { - it('expires a token when the client generation moves without a new update', () => { - const epoch = createClientAuthorityEpoch() - let generation = 1 - epoch.update({ - client: { getGeneration: () => generation }, - hostId: 'host-a', - executionHost: undefined, - worktreeId: 'wt-1' - }) - const token = epoch.token() - - generation = 2 - - expect(epoch.isCurrent(token)).toBe(false) - }) -})