181 lines
5.9 KiB
TypeScript
181 lines
5.9 KiB
TypeScript
import { App } from '@inertiajs/react';
|
|
import type { Page } from '@inertiajs/core';
|
|
import type { ComponentProps } from 'react';
|
|
import { renderToString } from 'react-dom/server';
|
|
import { expect, test } from 'vitest';
|
|
import { QuotationCommercialTerms } from '@/components/quotation-commercial-terms';
|
|
import { QuotationExchangePanel } from '@/components/quotation-exchange-panel';
|
|
import Comparison from '@/pages/quotations/show';
|
|
import { money } from '@/types/procurement';
|
|
|
|
const rate = {
|
|
id: 7,
|
|
currency: 'USD',
|
|
rate: '60.1234567890',
|
|
quoted_on: '2026-11-21',
|
|
source: 'Fonte sintética <script>ignorar</script>',
|
|
recorded_by: 12,
|
|
};
|
|
const policy = {
|
|
revision: 1,
|
|
configured: true,
|
|
minimum_proposals: 3,
|
|
minimum_evaluators: 2,
|
|
weights: { price: 40, quality: 20, delivery: 15, history: 15, payment: 10 },
|
|
};
|
|
function render(
|
|
Component: ComponentProps<typeof App>['initialComponent'],
|
|
props: Record<string, unknown>,
|
|
) {
|
|
const page = {
|
|
component: 'test',
|
|
url: '/teste',
|
|
version: null,
|
|
props: { errors: {}, ...props },
|
|
clearHistory: false,
|
|
encryptHistory: true,
|
|
} satisfies Page;
|
|
return renderToString(
|
|
<App initialPage={page} initialComponent={Component} />,
|
|
);
|
|
}
|
|
|
|
test.each([true, false])(
|
|
'related quotation stages remain grouped and preserve conditional urgency access (%s)',
|
|
(urgent) => {
|
|
const html = render(Comparison, {
|
|
requisition: {
|
|
id: 42,
|
|
number: 'REQ-42',
|
|
justification: 'Synthetic navigation QA',
|
|
items: [],
|
|
},
|
|
suppliers: [],
|
|
quotations: [],
|
|
canCreate: false,
|
|
canEvaluate: false,
|
|
ready: false,
|
|
topIds: [],
|
|
comparisonPolicy: {
|
|
...policy,
|
|
...(urgent ? { urgent_minimum_proposals: 1 } : {}),
|
|
},
|
|
urgentQuotationReady: urgent,
|
|
});
|
|
const group = html.match(
|
|
/<details[^>]*>[\s\S]*?Outras etapas e documentos do processo[\s\S]*?<\/details>/,
|
|
)?.[0];
|
|
expect(group).toBeDefined();
|
|
expect(group).not.toMatch(/<details[^>]*\bopen\b/);
|
|
expect(group).toContain(
|
|
'aria-label="Etapas e documentos relacionados"',
|
|
);
|
|
expect(group).toContain('grid gap-3 sm:grid-cols-2');
|
|
for (const path of [
|
|
'abertura',
|
|
'qualificacao',
|
|
'admissao',
|
|
'recomendacao',
|
|
'relatorio',
|
|
]) {
|
|
expect(group).toContain(`/requisicoes/42/${path}`);
|
|
}
|
|
expect(group).toContain('href="/requisicoes/42"');
|
|
expect(group).toContain('href="/conflitos"');
|
|
expect(group?.includes('/requisicoes/42/urgencia-stock')).toBe(urgent);
|
|
expect(html).toContain('href="/requisicoes/42/adjudicacao"');
|
|
expect(html).toContain('Comparação ainda incompleta.');
|
|
},
|
|
);
|
|
|
|
test.each([true, false])(
|
|
'process rates retain provenance and restrict the finance form (%s)',
|
|
(canRecord) => {
|
|
const html = render(QuotationExchangePanel, {
|
|
requisitionId: 42,
|
|
rates: [rate],
|
|
canRecord,
|
|
});
|
|
expect(html).toContain('60.1234567890');
|
|
expect(html).toContain('Fonte sintética <script>');
|
|
expect(html).not.toContain('<script>ignorar');
|
|
expect(html.includes('Registar e congelar taxa')).toBe(canRecord);
|
|
expect(html).toContain('duas casas decimais');
|
|
},
|
|
);
|
|
|
|
test('quotation matrix shows original currency alongside its separate mzn comparison reference', () => {
|
|
const html = render(Comparison, {
|
|
requisition: {
|
|
id: 42,
|
|
number: 'REQ-42',
|
|
justification: 'Teste',
|
|
items: [],
|
|
},
|
|
suppliers: [],
|
|
canCreate: false,
|
|
canEvaluate: false,
|
|
ready: false,
|
|
topIds: [],
|
|
comparisonPolicy: policy,
|
|
exchangeRates: [rate],
|
|
exchangeAvailable: true,
|
|
canRecordExchange: false,
|
|
quotations: [
|
|
{
|
|
id: 1,
|
|
reference: 'USD-ORIGINAL',
|
|
supplier: { name: 'Fornecedor sintético' },
|
|
currency: 'USD',
|
|
subtotal_minor: 100,
|
|
tax_minor: 0,
|
|
total_minor: 100,
|
|
exchange_basis: rate,
|
|
reference_amounts: {
|
|
subtotal_minor: 6012,
|
|
tax_minor: 0,
|
|
total_minor: 6012,
|
|
},
|
|
delivery_days: 5,
|
|
valid_until: '2026-12-01',
|
|
payment_terms: '30 dias',
|
|
evaluations: [],
|
|
evaluation_count: 0,
|
|
eligible: true,
|
|
conflict_blocked: false,
|
|
score: null,
|
|
items: [],
|
|
ineligibility_reasons: [],
|
|
commercial_terms: null,
|
|
},
|
|
],
|
|
});
|
|
expect(html).toContain('USD-ORIGINAL');
|
|
expect(html).toContain('Referência:');
|
|
expect(html).toContain('60.1234567890');
|
|
expect(html).not.toContain('Registar e congelar taxa');
|
|
});
|
|
|
|
test('foreign discount evidence uses its own currency and legacy amounts continue to default to mzn', () => {
|
|
const html = renderToString(
|
|
<QuotationCommercialTerms
|
|
currency="USD"
|
|
terms={{
|
|
lines: [
|
|
{
|
|
requisition_item_id: 1,
|
|
gross_unit_minor: 100,
|
|
discount_type: 'amount',
|
|
discount_value: '0.10',
|
|
net_unit_minor: 90,
|
|
},
|
|
],
|
|
}}
|
|
/>,
|
|
);
|
|
expect(html).toContain('USD/unidade');
|
|
expect(html).not.toContain('MZN/unidade');
|
|
expect(money(100)).toBe(money(100, 'MZN'));
|
|
expect(money(100, 'USD')).not.toBe(money(100));
|
|
});
|