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

This commit is contained in:
2026-11-28 07:11:35 +02:00
parent d58b75c87a
commit eb32c74c56
202 changed files with 17463 additions and 1526 deletions
@@ -0,0 +1,85 @@
import { App, router } from '@inertiajs/react';
import { renderToStaticMarkup } from 'react-dom/server';
import { afterEach, expect, test, vi } from 'vitest';
import EditSupplier from '@/pages/suppliers/edit';
import type { Supplier } from '@/types/supplier';
afterEach(() => vi.restoreAllMocks());
const supplier: Supplier = {
id: 42,
name: 'Fornecedor sintético',
nuit: '123456789',
contact: 'Contacto sintético',
email: 'qa@example.invalid',
phone: '123456789',
address: 'Morada sintética',
category: 'Material',
beneficiaries: 'Beneficiário sintético',
document_references: 'Referências documentais sintéticas',
diligence_notes: 'Conferência sintética anterior',
next_review: '2027-01-01',
blocked: false,
version: 1,
status: 'active',
review_comment: null,
};
const preparation = {
geography_reference: null,
name: 'NOME-QA-POR-GUARDAR',
nuit: supplier.nuit,
contact: supplier.contact,
email: supplier.email,
phone: supplier.phone,
address: 'Morada por guardar',
category: supplier.category,
beneficiaries: supplier.beneficiaries,
document_references: supplier.document_references,
diligence_notes: 'Preparação de diligência ainda não submetida',
next_review: supplier.next_review,
blocked: false,
version: 1,
};
function render(tenant = 3, actor = 7, id = 42, version = 1) {
return renderToStaticMarkup(
<App
initialComponent={EditSupplier}
initialPage={{
component: 'suppliers/edit',
url: `/fornecedores/${id}/editar`,
version: null,
clearHistory: false,
encryptHistory: true,
props: {
errors: {},
auth: { user: { id: actor, tenant_id: tenant } },
supplier: { ...supplier, id, version },
},
}}
/>,
);
}
test('supplier editing recovers the same private preparation without renewing diligence or saving automatically', () => {
vi.spyOn(router, 'restore').mockImplementation((key) =>
key === 'supplier-preparation:3:7:42:1:data' ? preparation : undefined,
);
const put = vi.spyOn(router, 'put');
const html = render();
expect(html).toContain('NOME-QA-POR-GUARDAR');
expect(html).toContain('Morada por guardar');
expect(html).toContain('Preparação de diligência ainda não submetida');
expect(html).toContain('Alterações à ficha retiram a validação actual');
expect(put).not.toHaveBeenCalled();
});
test('supplier preparation does not cross actor company supplier identity or a changed server version', () => {
vi.spyOn(router, 'restore').mockImplementation((key) =>
key === 'supplier-preparation:3:7:42:1:data' ? preparation : undefined,
);
expect(render(4)).not.toContain('NOME-QA-POR-GUARDAR');
expect(render(3, 8)).not.toContain('NOME-QA-POR-GUARDAR');
expect(render(3, 7, 43)).not.toContain('NOME-QA-POR-GUARDAR');
expect(render(3, 7, 42, 2)).not.toContain('NOME-QA-POR-GUARDAR');
});