@@ -0,0 +1,87 @@
|
||||
import { App } from '@inertiajs/react';
|
||||
import { renderToStaticMarkup } from 'react-dom/server';
|
||||
import { expect, test } from 'vitest';
|
||||
import Dossier from '@/pages/supply/import-dossier';
|
||||
|
||||
function renderDossier(canWrite: boolean) {
|
||||
const original = {
|
||||
id: 1,
|
||||
record_key: 'synthetic-key',
|
||||
version: 1,
|
||||
created_at: '2026-11-27',
|
||||
created_by: 3,
|
||||
current: false,
|
||||
supersedes: null,
|
||||
sha256: 'a'.repeat(64),
|
||||
reason: 'Original synthetic document.',
|
||||
data: {
|
||||
type: 'packing_list',
|
||||
reference: '<script>private reference</script>',
|
||||
issuer_reference: 'Synthetic issuer',
|
||||
issued_on: null,
|
||||
notes: null,
|
||||
},
|
||||
};
|
||||
return renderToStaticMarkup(
|
||||
<App
|
||||
initialComponent={Dossier}
|
||||
initialPage={{
|
||||
component: 'supply/import-dossier',
|
||||
url: '/compras/importacoes/4/documentos',
|
||||
version: null,
|
||||
clearHistory: false,
|
||||
encryptHistory: true,
|
||||
props: {
|
||||
errors: {},
|
||||
importRecord: {
|
||||
id: 4,
|
||||
record_key: 'import-key',
|
||||
version: 2,
|
||||
},
|
||||
order: { id: 5, number: 'OC-QA' },
|
||||
documents: {
|
||||
data: [
|
||||
{
|
||||
...original,
|
||||
id: 2,
|
||||
version: 2,
|
||||
current: true,
|
||||
supersedes: 1,
|
||||
},
|
||||
original,
|
||||
],
|
||||
prev_page_url: null,
|
||||
next_page_url:
|
||||
'/compras/importacoes/4/documentos?page=2',
|
||||
},
|
||||
types: { packing_list: 'Lista de embalagem' },
|
||||
canWrite,
|
||||
actorId: 3,
|
||||
tenantId: 2,
|
||||
},
|
||||
}}
|
||||
/>,
|
||||
);
|
||||
}
|
||||
|
||||
test('dossier reader retains version downloads and context without advertising write authority', () => {
|
||||
const html = renderDossier(false);
|
||||
expect(html).toContain('Dossiê de importação');
|
||||
expect(html).toContain('/compras/importacoes/4/documentos/1');
|
||||
expect(html).toContain('/compras/importacoes/4/documentos/2');
|
||||
expect(html).toContain('Histórica');
|
||||
expect(html).not.toContain(
|
||||
'Guardar documento privado',
|
||||
'Preparar correcção',
|
||||
);
|
||||
expect(html).toContain('<script>private reference</script>');
|
||||
expect(html).not.toContain('<script>private reference');
|
||||
});
|
||||
|
||||
test('dossier writer corrects only the current version and distinguishes evidence from execution', () => {
|
||||
const html = renderDossier(true);
|
||||
expect(html).toContain('Guardar documento privado');
|
||||
expect(html.match(/Preparar correcção/g)).toHaveLength(1);
|
||||
expect(html).toContain('não confirma pagamentos');
|
||||
expect(html).toContain('volte a seleccionar o ficheiro');
|
||||
});
|
||||
@@ -0,0 +1,45 @@
|
||||
import { App } from '@inertiajs/react';
|
||||
import { renderToStaticMarkup } from 'react-dom/server';
|
||||
import { expect, test } from 'vitest';
|
||||
import Reconciliation from '@/components/import-estimate-reconciliation';
|
||||
|
||||
test('reconciliation exposes explicit source remainder and does not select a financial allocation automatically', () => {
|
||||
const html = renderToStaticMarkup(
|
||||
<App
|
||||
initialComponent={Reconciliation}
|
||||
initialPage={{
|
||||
component: 'reconciliation',
|
||||
url: '/qa',
|
||||
version: null,
|
||||
clearHistory: false,
|
||||
encryptHistory: true,
|
||||
props: {
|
||||
errors: {},
|
||||
planId: 2,
|
||||
url: '/compras/importacoes/1/custos',
|
||||
historyKey: 'synthetic-private-key',
|
||||
financialRevision: 1,
|
||||
sources: {
|
||||
data: [
|
||||
{
|
||||
id: 4,
|
||||
version: 1,
|
||||
requisition_id: 9,
|
||||
budget_id: 6,
|
||||
revision: 2,
|
||||
reserved_minor: 12345,
|
||||
committed_minor: 0,
|
||||
},
|
||||
],
|
||||
prev_page_url: null,
|
||||
next_page_url: null,
|
||||
},
|
||||
},
|
||||
}}
|
||||
/>,
|
||||
);
|
||||
expect(html).toContain('saldo 123.45 MZN');
|
||||
expect(html).toContain('parcela que corresponde aos documentos conferidos');
|
||||
expect(html).toContain('restantes ordens');
|
||||
expect(html).toContain('disabled');
|
||||
});
|
||||
@@ -0,0 +1,72 @@
|
||||
import { App } from '@inertiajs/react';
|
||||
import { renderToStaticMarkup } from 'react-dom/server';
|
||||
import { expect, test } from 'vitest';
|
||||
import ImportEstimate from '@/pages/supply/import-estimate';
|
||||
import { estimateMinor, estimateMoney } from '@/lib/import-estimate-money';
|
||||
|
||||
test('estimate money input stays exact and invalid values reach server validation without rounding', () => {
|
||||
expect(estimateMinor('999999999999,99')).toBe(99999999999999);
|
||||
expect(estimateMinor('1.01')).toBe(101);
|
||||
expect(estimateMinor('1000000000000.00')).toBe(100000000000000);
|
||||
expect(estimateMinor('1.001')).toBe('1.001');
|
||||
expect(estimateMinor('-1')).toBe('-1');
|
||||
expect(estimateMoney(99999999999999)).toBe('999999999999.99');
|
||||
expect(estimateMoney(null)).toBe('');
|
||||
});
|
||||
|
||||
test('estimate readers see unknown cost coverage and preserved history without an editable form', () => {
|
||||
const html = renderToStaticMarkup(
|
||||
<App
|
||||
initialComponent={ImportEstimate}
|
||||
initialPage={{
|
||||
component: 'supply/import-estimate',
|
||||
url: '/requisicoes/1/estimativa-importacao',
|
||||
version: null,
|
||||
clearHistory: false,
|
||||
encryptHistory: true,
|
||||
props: {
|
||||
errors: {},
|
||||
requisition: {
|
||||
id: 1,
|
||||
number: 'QA',
|
||||
status: 'pending',
|
||||
total_minor: 10000,
|
||||
},
|
||||
actorId: 2,
|
||||
tenantId: 3,
|
||||
canPrepare: false,
|
||||
nativeChanged: true,
|
||||
budgets: {
|
||||
data: [],
|
||||
prev_page_url: null,
|
||||
next_page_url: null,
|
||||
},
|
||||
latest: {
|
||||
id: 4,
|
||||
version: 1,
|
||||
state: 'incomplete',
|
||||
reason: 'Synthetic',
|
||||
data: { budget_id: 1, components: [] },
|
||||
snapshot: {
|
||||
plan: {
|
||||
complete: false,
|
||||
budget_amount_minor: null,
|
||||
known_total_minor: 10000,
|
||||
unknown: ['duty'],
|
||||
},
|
||||
},
|
||||
},
|
||||
history: {
|
||||
data: [],
|
||||
prev_page_url: null,
|
||||
next_page_url: null,
|
||||
},
|
||||
},
|
||||
}}
|
||||
/>,
|
||||
);
|
||||
expect(html).toContain('total permanece indeterminado');
|
||||
expect(html).toContain('requisição mudou');
|
||||
expect(html).not.toContain('<form');
|
||||
expect(html).not.toContain('Guardar estimativa');
|
||||
});
|
||||
@@ -0,0 +1,91 @@
|
||||
import { App } from '@inertiajs/react';
|
||||
import { renderToStaticMarkup } from 'react-dom/server';
|
||||
import { expect, test } from 'vitest';
|
||||
import ImportPartySelection, {
|
||||
type ImportPartyWorkspace,
|
||||
} from '@/components/import-party-selection';
|
||||
|
||||
function renderParties(canSelect: boolean) {
|
||||
const selected = {
|
||||
id: 1,
|
||||
version: 2,
|
||||
data: { role: 'broker', supplier_id: 3, instruction_document_id: 4 },
|
||||
snapshot: {
|
||||
supplier: {
|
||||
name: '<script>Broker QA</script>',
|
||||
nuit: '123456789',
|
||||
version: 1,
|
||||
},
|
||||
instructions: { data: { reference: 'INSTRUCTIONS-QA' } },
|
||||
},
|
||||
reason: 'Explicit synthetic selection.',
|
||||
issues: [
|
||||
'As instruções escritas têm uma versão diferente; confira a selecção.',
|
||||
],
|
||||
};
|
||||
const workspace: ImportPartyWorkspace = {
|
||||
roles: { broker: 'Despachante aduaneiro', forwarder: 'Transitário' },
|
||||
canSelect,
|
||||
search: '',
|
||||
current: [selected],
|
||||
history: { data: [selected], prev_page_url: null, next_page_url: null },
|
||||
suppliers: {
|
||||
data: [{ id: 3, name: 'Broker QA', nuit: '123456789', version: 1 }],
|
||||
prev_page_url: null,
|
||||
next_page_url: null,
|
||||
},
|
||||
instructions: {
|
||||
data: [
|
||||
{
|
||||
id: 4,
|
||||
version: 1,
|
||||
data: {
|
||||
reference: 'INSTRUCTIONS-QA',
|
||||
issuer_reference: 'QA buyer',
|
||||
},
|
||||
},
|
||||
],
|
||||
prev_page_url: null,
|
||||
next_page_url: null,
|
||||
},
|
||||
};
|
||||
return renderToStaticMarkup(
|
||||
<App
|
||||
initialComponent={ImportPartySelection}
|
||||
initialPage={{
|
||||
component: 'supply/import-dossier',
|
||||
url: '/compras/importacoes/5/documentos',
|
||||
version: null,
|
||||
clearHistory: false,
|
||||
encryptHistory: true,
|
||||
props: {
|
||||
errors: {},
|
||||
workspace,
|
||||
importId: 5,
|
||||
importKey: 'synthetic-import',
|
||||
actorId: 6,
|
||||
tenantId: 7,
|
||||
},
|
||||
}}
|
||||
/>,
|
||||
);
|
||||
}
|
||||
|
||||
test('party reader sees preserved selection instructions and pending issues without selection commands', () => {
|
||||
const html = renderParties(false);
|
||||
expect(html).toContain('INSTRUCTIONS-QA');
|
||||
expect(html).toContain('uma versão diferente');
|
||||
expect(html).toContain('/compras/importacoes/5/documentos/4');
|
||||
expect(html).not.toContain('Confirmar entidade e instruções');
|
||||
expect(html).toContain('<script>Broker QA</script>');
|
||||
expect(html).not.toContain('<script>Broker QA');
|
||||
});
|
||||
|
||||
test('buyer selects existing sources and must personally confirm the conflict declaration', () => {
|
||||
const html = renderParties(true);
|
||||
expect(html).toContain('Escolher entidade');
|
||||
expect(html).toContain('Escolher instruções');
|
||||
expect(html).toContain('Confirmo a ausência de conflito');
|
||||
expect(html).not.toMatch(/<input[^>]+type="checkbox"[^>]*checked/);
|
||||
expect(html).toContain('Rever a selecção actual');
|
||||
});
|
||||
@@ -1,4 +1,7 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { App } from '@inertiajs/react';
|
||||
import { renderToStaticMarkup } from 'react-dom/server';
|
||||
import Parts from '@/pages/purchases/parts';
|
||||
import {
|
||||
orderPartDraftKey,
|
||||
orderPartMinor,
|
||||
@@ -52,3 +55,85 @@ describe('explicit order-part monetary input', () => {
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
it('foreign legacy adoption shows an unknown reference as pending instead of a zero amount', () => {
|
||||
const html = renderToStaticMarkup(
|
||||
<App
|
||||
initialComponent={Parts}
|
||||
initialPage={{
|
||||
component: 'purchases/parts',
|
||||
url: '/ordens/preparar',
|
||||
version: null,
|
||||
clearHistory: false,
|
||||
encryptHistory: true,
|
||||
props: {
|
||||
errors: {},
|
||||
candidates: {
|
||||
data: [],
|
||||
prev_page_url: null,
|
||||
next_page_url: null,
|
||||
},
|
||||
preview: {
|
||||
selection: {
|
||||
sources: [
|
||||
{
|
||||
award_id: 2,
|
||||
items: [
|
||||
{
|
||||
quotation_item_id: 3,
|
||||
quantity: '1.000',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
can_issue: false,
|
||||
financial: [
|
||||
{
|
||||
origin: 1,
|
||||
award_id: 2,
|
||||
requires_adoption: true,
|
||||
allocations: [],
|
||||
adoption_lines: [
|
||||
{
|
||||
line_id: 4,
|
||||
description:
|
||||
'Synthetic imported material',
|
||||
subtotal_minor: 100,
|
||||
total_minor: 100,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
prepared: {
|
||||
fingerprint: 'a'.repeat(64),
|
||||
currency: 'USD',
|
||||
subtotal_minor: 100,
|
||||
total_minor: 100,
|
||||
sources: [
|
||||
{
|
||||
requisition_id: 1,
|
||||
award_id: 2,
|
||||
currency: 'USD',
|
||||
items: [
|
||||
{
|
||||
description:
|
||||
'Synthetic imported material',
|
||||
quotation_item_id: 3,
|
||||
quantity_offset_milli: 0,
|
||||
quantity_milli: 1000,
|
||||
total_minor: 100,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
}}
|
||||
/>,
|
||||
);
|
||||
expect(html).toContain('Referência por conferir');
|
||||
expect(html).toContain('todos os artigos da proposta');
|
||||
expect(html).not.toContain('0,00');
|
||||
});
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
import { renderToStaticMarkup } from 'react-dom/server';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { ProcurementPaymentInsights } from '../../resources/js/components/procurement-payment-insights';
|
||||
|
||||
describe('confirmed payment expense', () => {
|
||||
it('keeps currencies separate and formats amounts without floating point', () => {
|
||||
const html = renderToStaticMarkup(
|
||||
<ProcurementPaymentInsights
|
||||
data={{
|
||||
from: '2026-11-01',
|
||||
to: '2026-11-27',
|
||||
coverage: {
|
||||
invoices: 3,
|
||||
indeterminate: 1,
|
||||
confirmed_payments: 2,
|
||||
},
|
||||
currencies: [
|
||||
{
|
||||
currency: 'MZN',
|
||||
count: 1,
|
||||
amount_minor: '9007199254740993',
|
||||
},
|
||||
{ currency: 'USD', count: 1, amount_minor: '1200' },
|
||||
],
|
||||
}}
|
||||
/>,
|
||||
);
|
||||
expect(html).toContain('90071992547409,93 MZN');
|
||||
expect(html).toContain('12,00 USD');
|
||||
expect(html).toContain('valores apresentados são parciais');
|
||||
expect(html).toContain('pela data de confirmação');
|
||||
});
|
||||
it('does not describe undetermined history as a zero expense', () => {
|
||||
const html = renderToStaticMarkup(
|
||||
<ProcurementPaymentInsights
|
||||
data={{
|
||||
from: null,
|
||||
to: null,
|
||||
coverage: {
|
||||
invoices: 1,
|
||||
indeterminate: 1,
|
||||
confirmed_payments: 0,
|
||||
},
|
||||
currencies: [],
|
||||
}}
|
||||
/>,
|
||||
);
|
||||
expect(html).toContain('histórico indeterminado');
|
||||
expect(html).not.toContain('0,00');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user