Files
Investidor-V2/tests/frontend/resource-incident-form.test.mjs
T

57 lines
2.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import test from 'node:test';
import assert from 'node:assert/strict';
import { harness, props, text } from './helpers/resource-incident-form.mjs';
const reasonLabel = 'Motivo (20–1000 caracteres)',
title = 'Título';
test('an upload incident response preserves the actual form fields, selected file and creation command without retrying', async () => {
const h = harness();
h.choose('Documentos');
h.change(title, 'SYNTHETIC document title');
h.change(reasonLabel, 'SYNTHETIC preserved upload reason');
const file = { name: 'synthetic.pdf' };
h.attach(file);
const request = h.submit();
await h.reply(503, {
message: 'Incidente técnico registado. Referência: SYNTHETIC-REFERENCE',
reference: 'SYNTHETIC-REFERENCE',
incident_recorded: true,
});
assert.equal(h.sent.length, 1);
assert.equal(h.reloads.length, 0);
assert.equal(h.value(title), 'SYNTHETIC document title');
assert.equal(h.value(reasonLabel), 'SYNTHETIC preserved upload reason');
assert.match(text(h.tree), /SYNTHETIC-REFERENCE/);
const retry = h.submit();
assert.equal(retry.form.get('file'), file);
assert.equal(
retry.form.get('creation_key'),
request.form.get('creation_key'),
);
assert.equal(retry.form.get('etag'), request.form.get('etag'));
});
test('reading the recorded upload incident adds its own operation label without resetting the preparation', () => {
const h = harness();
h.choose('Documentos');
h.change(title, 'SYNTHETIC draft');
h.change(reasonLabel, 'SYNTHETIC retained reason');
const file = { name: 'retained.pdf' };
h.attach(file);
h.render(
props({
technicalIncidents: [
{
reference: 'SYNTHETIC-REFERENCE',
operation: 'upload_document',
version: 4,
occurred_at: '2026-11-03',
error_code: 'database_failure',
},
],
}),
);
assert.match(text(h.tree), /Carregamento de documento/);
assert.equal(h.value(title), 'SYNTHETIC draft');
assert.equal(h.value(reasonLabel), 'SYNTHETIC retained reason');
assert.equal(h.submit().form.get('file'), file);
});