132 lines
4.2 KiB
TypeScript
132 lines
4.2 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 { 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: typeof Comparison | typeof QuotationExchangePanel,
|
|
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])(
|
|
'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));
|
|
});
|