88 lines
3.1 KiB
TypeScript
88 lines
3.1 KiB
TypeScript
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');
|
|
});
|