commit melhorias compras1
tests / ci (push) Waiting to run

This commit is contained in:
2026-11-21 21:04:40 +02:00
parent 976271f948
commit 12dd6df28a
108 changed files with 4391 additions and 408 deletions
+131
View File
@@ -0,0 +1,131 @@
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 &lt;script&gt;');
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));
});
@@ -0,0 +1,36 @@
import { renderToStaticMarkup } from 'react-dom/server';
import { expect, test } from 'vitest';
import {
ReceiptConversionFields,
convertedQuantity,
} from '@/components/receipt-conversion';
test('converted quantity display preserves exact millesimals beyond floating point precision', () => {
expect(convertedQuantity('24000')).toBe('24,000');
expect(convertedQuantity('1')).toBe('0,001');
expect(convertedQuantity('999999999999999999')).toBe('999999999999999,999');
expect(convertedQuantity('')).toBe('Não disponível');
});
test('receipt conversion identifies both units and requires an explicit rational factor and documentary source', () => {
const html = renderToStaticMarkup(
<ReceiptConversionFields
documentUnit="cx"
stockUnit="un"
value={{
numerator: '12',
denominator: '1',
source: 'Embalagem sintética',
version: 'QA-1',
}}
onChange={() => {}}
/>,
);
expect(html).toContain('Conversão de cx para un');
expect(html).toContain('A compra conserva cx');
expect(html).toContain('O stock e os lotes usam un');
expect(html).toContain('Não há arredondamento automático');
expect(html).toContain('Fonte do factor');
expect(html).toContain('Versão da fonte');
expect(html.match(/required=""/g)).toHaveLength(4);
});
@@ -0,0 +1,158 @@
import { App } from '@inertiajs/react';
import type { Page } from '@inertiajs/core';
import { renderToString } from 'react-dom/server';
import { expect, test } from 'vitest';
import Bank from '@/pages/suppliers/bank';
import Payments from '@/pages/payments/index';
const key = 'c1111111-1111-4111-8111-111111111111';
const accounts = [
{
id: 1,
key: null,
revision: 1,
label: 'Banco anterior · MZN',
state: 'approved',
},
{
id: 2,
key,
revision: 2,
label: 'Banco independente · USD',
state: 'pending',
},
];
function render(
Component: typeof Bank | typeof Payments,
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('supplier bank account links preserve the selected logical account and the independent creation action', () => {
const html = render(Bank, {
supplier: { id: 8, name: 'Fornecedor sintético' },
current: null,
currentId: 0,
state: 'missing',
history: [],
reviews: [],
canPropose: true,
canReview: false,
accounts,
accountKey: null,
multiAccountsAvailable: true,
actorId: 12,
});
expect(html).toContain(`/fornecedores/8/dados-bancarios?account=${key}`);
expect(html).toContain('Adicionar conta independente');
expect(html).toContain('não substitui nem reactiva versões anteriores');
});
test('legacy schema does not offer independent accounts or infer additional authority', () => {
const html = render(Bank, {
supplier: { id: 8, name: 'Fornecedor sintético' },
current: null,
currentId: 0,
state: 'missing',
history: [],
reviews: [],
canPropose: false,
canReview: false,
multiAccountsAvailable: false,
actorId: 12,
});
expect(html).not.toContain('Adicionar conta independente');
expect(html).not.toContain('Conferência independente');
});
test('payment form leaves the deliberate choice empty when two approved same-currency accounts exist', () => {
const html = render(Payments, {
canManage: true,
focusInvoiceId: 42,
payments: {
data: [],
current_page: 1,
last_page: 1,
total: 0,
per_page: 15,
links: [],
},
invoices: [
{
id: 42,
number: 'FT-42',
currency: 'MZN',
supplier_id: 8,
supplier_name: 'Fornecedor sintético',
total_minor: 100,
outstanding_minor: 100,
bank_id: 0,
bank_revision: 0,
bank_state: 'approved',
banks: [
{
id: 1,
revision: 1,
currency: 'MZN',
label: 'Conta A',
state: 'approved',
},
{
id: 2,
revision: 2,
currency: 'MZN',
label: 'Conta B',
state: 'approved',
},
],
},
],
});
expect(html).toContain('Conta bancária na moeda da factura');
expect(html).toContain('Conta A');
expect(html).toContain('Conta B');
expect(html).toContain('value="" selected=""');
expect(html).toContain('Por seleccionar');
});
test('bank identities and labels remain hidden when administration has no payment-management authority', () => {
const html = render(Payments, {
canManage: false,
payments: {
data: [],
current_page: 1,
last_page: 1,
total: 0,
per_page: 15,
links: [],
},
invoices: [
{
id: 42,
number: 'FT-42',
currency: 'MZN',
supplier_id: 8,
supplier_name: 'Fornecedor sintético',
total_minor: 100,
outstanding_minor: 100,
bank_id: 0,
bank_revision: 0,
bank_state: 'approved',
banks: [],
},
],
});
expect(html).not.toContain('Conta bancária na moeda da factura');
expect(html).not.toContain('Seleccione uma conta validada');
});