105 lines
3.7 KiB
TypeScript
105 lines
3.7 KiB
TypeScript
import { App } from '@inertiajs/react';
|
|
import type { Page } from '@inertiajs/core';
|
|
import { renderToString } from 'react-dom/server';
|
|
import { expect, test } from 'vitest';
|
|
import { AiPlanSettings } from '@/components/ai-plan-settings';
|
|
import { AiPreparationPreview } from '@/components/ai-preparation-preview';
|
|
import type { AiPreparation } from '@/components/ai-preparation-preview';
|
|
|
|
const page = {
|
|
component: 'company/parameters',
|
|
url: '/administracao/parametrizacao',
|
|
version: 'ai-plan',
|
|
props: { errors: {} },
|
|
clearHistory: false,
|
|
encryptHistory: true,
|
|
} satisfies Page;
|
|
|
|
test.each([true, false])(
|
|
'AI preparation settings clearly save a plan rather than activate a provider (%s)',
|
|
(ready) => {
|
|
function Screen() {
|
|
return (
|
|
<AiPlanSettings
|
|
ready={ready}
|
|
version={3}
|
|
domains={{
|
|
procurement: 'Compras',
|
|
people: 'Pessoas e contratações',
|
|
}}
|
|
scopes={{ process_state: 'Estado do processo' }}
|
|
plan={{
|
|
state: 'draft',
|
|
provider: 'none',
|
|
model: '',
|
|
domains: [],
|
|
data_scopes: [],
|
|
monthly_budget_usd: '0.00',
|
|
monthly_requests: 0,
|
|
max_input_bytes: 4500,
|
|
max_output_tokens: 1000,
|
|
}}
|
|
/>
|
|
);
|
|
}
|
|
const html = renderToString(
|
|
<App initialPage={page} initialComponent={Screen} />,
|
|
);
|
|
expect(html.includes('<form')).toBe(ready);
|
|
expect(html).toContain('não envia dados nem activa chamadas externas');
|
|
if (ready) {
|
|
expect(html).toContain('Guardar plano para pré-visualização');
|
|
expect(html).toContain('ainda não existe contador mensal');
|
|
expect(html).toContain('Orçamento mensal planeado (USD)');
|
|
}
|
|
expect(html).not.toContain('type="password"');
|
|
},
|
|
);
|
|
|
|
test.each([
|
|
'not_configured',
|
|
'outside_scope',
|
|
'no_permitted_facts',
|
|
'input_exceeds_limit',
|
|
'draft',
|
|
] as const)(
|
|
'AI preview handles %s without exposing an external execution action',
|
|
(status) => {
|
|
const data: AiPreparation = {
|
|
status,
|
|
external_execution_enabled: false,
|
|
usage_checked: false,
|
|
policy_revision: 2,
|
|
provider: 'openai',
|
|
model: 'gpt-5.6-terra',
|
|
max_input_bytes: 4500,
|
|
max_output_tokens: 1000,
|
|
input_bytes: 123,
|
|
facts:
|
|
status === 'draft'
|
|
? [
|
|
{
|
|
id: 'request',
|
|
text: 'Pedido em aprovação.',
|
|
source: {
|
|
href: '#report-request',
|
|
label: 'Identificação do pedido',
|
|
pointer: 'requisition.status',
|
|
},
|
|
},
|
|
]
|
|
: [],
|
|
};
|
|
const html = renderToString(<AiPreparationPreview data={data} />);
|
|
if (status === 'not_configured') expect(html).toBe('');
|
|
else {
|
|
expect(html).toContain('O plano não autoriza execução externa');
|
|
expect(html).not.toContain('<form');
|
|
expect(html).not.toContain('<button');
|
|
if (status === 'draft')
|
|
expect(html).toContain('href="#report-request"');
|
|
else expect(html).not.toContain('Pedido em aprovação.');
|
|
}
|
|
},
|
|
);
|