import { act, cleanup, fireEvent, render, screen } from '@testing-library/react' import type { ReactNode, TextareaHTMLAttributes } from 'react' import { useRef, useState } from 'react' import { afterEach, describe, expect, it, vi } from 'vitest' import { I18nProvider } from '@/lib/i18n-context' import type { PendingSchedule } from '@/components/AssistantChat/ScheduleTimePicker' import type { ComposerSendIntent } from '@/lib/messageDelivery' import type { ComposerToolbarLayout } from '@/hooks/useComposerToolbarLayout' import { HappyComposer } from './HappyComposer' /** * Focused harness for the generic model/effort value buttons and the * settings-sheet section order. Reuses the assistant-ui mock strategy from * HappyComposer.sendError.test.tsx but keeps ComposerButtons unmocked so the * new value buttons are exercised for real. */ type FakeAttachment = { id: string; status: { type: 'complete' } } type MockComposerInputProps = TextareaHTMLAttributes & { asChild?: boolean maxRows?: number submitOnEnter?: boolean cancelOnEscape?: boolean } type FakeRuntimeState = { composer: { text: string; attachments: FakeAttachment[] } thread: { isRunning: boolean; isDisabled: boolean } } const runtime = vi.hoisted(() => ({ snapshot: { composer: { text: '', attachments: [] as FakeAttachment[] }, thread: { isRunning: false, isDisabled: false }, } as FakeRuntimeState, setSnapshot: null as null | ((updater: (current: FakeRuntimeState) => FakeRuntimeState) => void), pendingSendIntentRef: { current: 'default' }, sentIntents: [] as ComposerSendIntent[], narrowViewport: false, toolbarLayout: null as ComposerToolbarLayout | null, cancelRun: vi.fn(), })) vi.mock('@assistant-ui/react', async () => { const React = await import('react') return { useAui: () => ({ composer: () => ({ setText: (text: string) => { runtime.setSnapshot!((current) => ({ ...current, composer: { ...current.composer, text }, })) }, send: () => { const intent = runtime.pendingSendIntentRef?.current ?? 'default' runtime.sentIntents.push(intent as ComposerSendIntent) if (runtime.pendingSendIntentRef) runtime.pendingSendIntentRef.current = 'default' runtime.setSnapshot!((current) => ({ ...current, composer: { text: '', attachments: [] }, })) }, addAttachment: async () => {}, }), thread: () => ({ cancelRun: runtime.cancelRun }), }), useAuiState: (selector: (state: typeof runtime.snapshot) => unknown) => selector(runtime.snapshot), ComposerPrimitive: { Root: ({ children, onSubmit }: { children: ReactNode; onSubmit?: () => void }) => (
{children}
), AddAttachment: ({ children }: { children: ReactNode }) => <>{children}, Input: React.forwardRef( ({ asChild: _asChild, onChange, maxRows: _maxRows, submitOnEnter: _submitOnEnter, cancelOnEscape: _cancelOnEscape, ...props }, ref) => (