:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
import '@testing-library/jest-dom'
import { cleanup, render, screen } from '@testing-library/react'
import { Provider } from 'kea'
import { initKeaTests } from '~/test/init'
import { llmEvaluationsLogic } from '../evaluations/llmEvaluationsLogic'
import { EvaluationConfig } from '../evaluations/types'
import { EvaluationDisplay } from './EvaluationDisplay'
const detectorEvaluation: EvaluationConfig = {
id: 'eval-detector',
name: 'Detects struggle',
enabled: true,
status: 'active',
status_reason: null,
status_reason_detail: null,
evaluation_type: 'hog',
evaluation_config: { source: 'return true' },
output_type: 'boolean',
output_config: { true_is_failure: true },
conditions: [{ id: 'cond-1', rollout_percentage: 100, properties: [] }],
target: 'generation',
target_config: {},
model_configuration: null,
created_at: '2024-01-01T00:00:00Z',
updated_at: '2024-01-01T00:00:00Z',
}
describe('EvaluationDisplay', () => {
beforeEach(() => {
initKeaTests()
})
afterEach(() => {
cleanup()
})
it('renders sentiment value instead of a boolean result', () => {
render(
<Provider>
<EvaluationDisplay
eventProperties={{
$ai_evaluation_runtime: 'sentiment',
$ai_sentiment_label: 'positive',
$ai_sentiment_score: 0.91,
}}
/>
</Provider>
)
expect(screen.getByText('Positive')).toBeInTheDocument()
expect(screen.queryByText('False')).not.toBeInTheDocument()
})
it('does not coerce absent boolean results to false', () => {
render(
<Provider>
<EvaluationDisplay eventProperties={{}} />
</Provider>
)
expect(screen.getByText('N/A')).toBeInTheDocument()
expect(screen.queryByText('False')).not.toBeInTheDocument()
})
test.each([true, 'true'])('renders a skipped categorical run before N/A (%s)', (skipped) => {
render(
<Provider>
<EvaluationDisplay
eventProperties={{
$ai_evaluation_result_type: 'categorical',
$ai_evaluation_applicable: false,
$ai_evaluation_allows_na: false,
$ai_evaluation_skipped: skipped,
}}
/>
</Provider>
)
expect(screen.getByText('Skipped')).toBeInTheDocument()
expect(screen.queryByText('N/A')).not.toBeInTheDocument()
})
it('colors a detector true result as danger, matching the badges elsewhere on the page', () => {
const evaluationsLogic = llmEvaluationsLogic()
evaluationsLogic.mount()
evaluationsLogic.actions.loadEvaluationsSuccess([detectorEvaluation])
render(
<Provider>
<EvaluationDisplay
eventProperties={{ $ai_evaluation_id: 'eval-detector', $ai_evaluation_result: true }}
/>
</Provider>
)
expect(screen.getByText('True')).toBeInTheDocument()
expect(document.querySelector('.LemonTag--danger')).toBeInTheDocument()
expect(document.querySelector('.LemonTag--success')).not.toBeInTheDocument()
evaluationsLogic.unmount()
})
})