test(desktop): cover settled clarify answer rendering

This commit is contained in:
Brooklyn Nicholson 2026-07-12 05:27:52 -04:00
parent 9e7fe2dd01
commit 192ce05d05

View file

@ -0,0 +1,98 @@
import { cleanup, render, screen } from '@testing-library/react'
import type { ReactNode } from 'react'
import { afterEach, describe, expect, it } from 'vitest'
import { I18nProvider } from '@/i18n'
import { ClarifyTool, readClarifyResult } from './clarify-tool'
afterEach(() => {
cleanup()
})
function renderClarify(ui: ReactNode) {
return render(
<I18nProvider configClient={null} initialLocale="en">
{ui}
</I18nProvider>
)
}
describe('readClarifyResult', () => {
it('reads question + user_response from the tool JSON payload', () => {
expect(
readClarifyResult({
question: 'Which target?',
choices_offered: ['staging', 'prod'],
user_response: 'staging'
})
).toEqual({
question: 'Which target?',
answer: 'staging',
error: undefined
})
})
it('parses a JSON string result the same way as an object', () => {
expect(
readClarifyResult(
JSON.stringify({
question: 'Ship it?',
user_response: 'yes'
})
)
).toEqual({
question: 'Ship it?',
answer: 'yes',
error: undefined
})
})
it('keeps an empty user_response so Skip can render as skipped', () => {
expect(readClarifyResult({ question: 'Ok?', user_response: '' })).toEqual({
question: 'Ok?',
answer: '',
error: undefined
})
})
})
describe('ClarifyTool settled view', () => {
it('keeps the question and answer visible after the tool completes', () => {
renderClarify(
<ClarifyTool
args={{ question: 'Which deployment target?', choices: ['staging', 'prod'] }}
isError={false}
result={{
question: 'Which deployment target?',
choices_offered: ['staging', 'prod'],
user_response: 'staging'
}}
toolCallId="clarify-1"
toolName="clarify"
type="tool-call"
/>
)
expect(screen.getByText('Which deployment target?')).toBeTruthy()
expect(screen.getByText('staging')).toBeTruthy()
expect(document.querySelector('[data-clarify-settled]')).toBeTruthy()
expect(document.querySelector('[data-clarify-answer]')?.textContent).toBe('staging')
})
it('labels an empty response as Skipped', () => {
renderClarify(
<ClarifyTool
args={{ question: 'Anything else?' }}
isError={false}
result={{ question: 'Anything else?', user_response: '' }}
toolCallId="clarify-2"
toolName="clarify"
type="tool-call"
/>
)
expect(screen.getByText('Anything else?')).toBeTruthy()
expect(screen.getByText('Skipped')).toBeTruthy()
})
})