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

This commit is contained in:
2026-11-29 05:28:30 +02:00
parent 1ddabbbdcc
commit 448948a487
137 changed files with 9481 additions and 1926 deletions
@@ -0,0 +1,172 @@
import { App, router } from '@inertiajs/react';
import { renderToStaticMarkup } from 'react-dom/server';
import { afterEach, expect, test, vi } from 'vitest';
import Evaluation from '@/pages/suppliers/evaluation';
afterEach(() => vi.restoreAllMocks());
const payload = {
title: 'Avaliação QA',
nature: 'goods',
scope: 'Âmbito sintético.',
period_start: '2026-11-28',
period_end: '2026-11-28',
order_ids: [],
criteria: [],
conclusion: 'Conclusão original.',
critical_occurrences: '',
critical_evidence: '',
};
const identity =
'procurement-preparations:4:7:procurement.internal:procurement:supplier-evaluation:1:3';
function render(
kind: 'evidence' | 'decision',
actor = 7,
tenant = 4,
context = 'procurement.internal',
version = 3,
reportOnly = false,
) {
return renderToStaticMarkup(
<App
initialComponent={Evaluation}
initialPage={{
component: 'suppliers/evaluation',
url: '/fornecedores/avaliacoes/1',
version: null,
clearHistory: false,
encryptHistory: true,
props: {
errors: {},
auth: { user: { id: actor, tenant_id: tenant } },
workContext: { active: context },
organizationAccess: { permissions: ['procurement'] },
reportOnly,
canEdit: kind === 'evidence' && !reportOnly,
canReview: kind === 'decision' && !reportOnly,
canRevise: false,
nextRevisionId: null,
orders: [],
people: {},
history: {
data: [],
total: 0,
prev_page_url: null,
next_page_url: null,
},
generatedAt: '2026-11-28T12:00:00Z',
improvements: { ready: false, records: [] },
responses: { ready: false, records: [] },
evaluation: {
id: 1,
supplier_id: 2,
revision: 1,
version,
status: kind === 'evidence' ? 'draft' : 'review',
previous_id: null,
created_by: 9,
contributors: [9],
supplier_snapshot: {
id: 2,
name: 'Fornecedor QA',
nuit: '123456789',
},
payload,
review_reason: null,
reviewed_at: null,
reviewed_by: null,
},
},
}}
/>,
);
}
test.each(['evidence', 'decision'] as const)(
'%s navigation targets only present focusable sections and preserves report boundaries',
(kind) => {
for (const reportOnly of [false, true]) {
const html = render(
kind,
7,
4,
'procurement.internal',
3,
reportOnly,
);
const navigation = html.match(
/<nav aria-label="Áreas da avaliação do fornecedor"[\s\S]*?<\/nav>/,
)?.[0];
expect(navigation).toBeDefined();
const targets = [...navigation!.matchAll(/href="#([^"]+)"/g)].map(
(match) => match[1],
);
for (const id of targets) {
expect(html.split(`id="${id}"`)).toHaveLength(2);
expect(html).toContain(`id="${id}" tabindex="-1"`);
}
expect(targets).toContain('evaluation-evidence');
expect(targets).toContain('evaluation-improvements');
expect(targets).toContain('evaluation-responses');
expect(targets.includes('evaluation-review')).toBe(
kind === 'decision' && !reportOnly,
);
expect(targets.includes('evaluation-history')).toBe(!reportOnly);
expect(targets).not.toContain('evaluation-last-review');
expect(targets).not.toContain('evaluation-revision');
expect(html).toContain(
'class="rounded-xl border bg-card p-4 print:hidden"',
);
expect(html).not.toContain('<details open');
}
},
);
test.each(['evidence', 'decision'] as const)(
'%s preparation recovers only for the same actor company context and source version without submitting',
(kind) => {
vi.spyOn(router, 'restore').mockImplementation((key) =>
key === `${identity}:${kind}:data`
? kind === 'evidence'
? {
version: 3,
payload: {
...payload,
conclusion: 'PRIVATE-QA-PREPARATION',
},
}
: { version: 3, reason: 'PRIVATE-QA-PREPARATION' }
: undefined,
);
const post = vi.spyOn(router, 'post');
const put = vi.spyOn(router, 'put');
expect(render(kind)).toContain('PRIVATE-QA-PREPARATION');
expect(render(kind)).toContain('data-preparation-dirty="true"');
expect(render(kind, 8)).not.toContain('PRIVATE-QA-PREPARATION');
expect(render(kind, 7, 5)).not.toContain('PRIVATE-QA-PREPARATION');
expect(render(kind, 7, 4, 'finance')).not.toContain(
'PRIVATE-QA-PREPARATION',
);
expect(render(kind, 7, 4, 'procurement.internal', 4)).not.toContain(
'PRIVATE-QA-PREPARATION',
);
expect(
render(kind, 7, 4, 'procurement.internal', 3, true),
).not.toContain('PRIVATE-QA-PREPARATION');
expect(post).not.toHaveBeenCalled();
expect(put).not.toHaveBeenCalled();
},
);
test('a clean recovered evidence form is not dirty because object keys changed order', () => {
vi.spyOn(router, 'restore').mockImplementation((key) =>
key === `${identity}:evidence:data`
? {
version: 3,
payload: Object.fromEntries(
Object.entries(payload).reverse(),
),
}
: undefined,
);
expect(render('evidence')).not.toContain('data-preparation-dirty="true"');
});