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,120 @@
import { App, router } from '@inertiajs/react';
import { renderToStaticMarkup } from 'react-dom/server';
import { afterEach, expect, test, vi } from 'vitest';
import OrderAmendment from '@/pages/purchases/order-parts-amendment';
import DistributionAmendment from '@/pages/purchases/distribution-amendment';
afterEach(() => vi.restoreAllMocks());
const allocation = {
allocation_key: 'synthetic-allocation',
line_id: 8,
centre_id: 9,
subtotal: '100.00',
total: '100.00',
};
const source = {
origin: 3,
version: 1,
plan_hash: 'synthetic-plan',
allocations: [allocation],
};
const preparedSource = {
...source,
allocations: source.allocations.map(
({ allocation_key, subtotal, total }) => ({
allocation_key,
subtotal,
total,
}),
),
};
const order = { id: 2, number: 'OC-QA', currency: 'MZN' };
function render(parts: boolean, actor = 7, plan = 'synthetic-plan') {
const component = parts ? OrderAmendment : DistributionAmendment;
return renderToStaticMarkup(
<App
initialComponent={component}
initialPage={{
component: 'purchases/amendment',
url: '/ordens/2/reafectacao',
version: null,
clearHistory: false,
encryptHistory: true,
props: {
errors: {},
auth: { user: { id: actor, tenant_id: 4 } },
order,
history: [],
sources: [{ ...source, plan_hash: plan }],
planHash: plan,
version: 1,
options: [
{
...allocation,
line_label: 'Synthetic line',
centre_label: 'Synthetic centre',
},
],
},
}}
/>,
);
}
test.each([true, false])(
'restored Finance preparation remains dirty without submitting (%s)',
(parts) => {
const key = parts
? 'order-parts-amendment:4:7:2:3:1:synthetic-plan:data'
: 'distribution-amendment:4:7:2:synthetic-plan:data';
vi.spyOn(router, 'restore').mockImplementation((candidate) =>
candidate === key
? {
operation_key: '00000000-0000-4000-8000-000000000001',
reason: 'FINANCE-QA-NOT-SUBMITTED',
...(parts
? { sources: [preparedSource] }
: {
expected_plan_hash: 'synthetic-plan',
budget_distribution_preparation: [allocation],
}),
}
: undefined,
);
const post = vi.spyOn(router, 'post');
const html = render(parts);
expect(html).toContain('FINANCE-QA-NOT-SUBMITTED');
expect(html).toContain('data-preparation-dirty="true"');
expect(render(parts, 8)).not.toContain('FINANCE-QA-NOT-SUBMITTED');
expect(render(parts, 7, 'new-plan')).not.toContain(
'FINANCE-QA-NOT-SUBMITTED',
);
expect(post).not.toHaveBeenCalled();
},
);
test.each([true, false])(
'regenerated operation identity alone does not mark Finance preparation dirty (%s)',
(parts) => {
const key = parts
? 'order-parts-amendment:4:7:2:3:1:synthetic-plan:data'
: 'distribution-amendment:4:7:2:synthetic-plan:data';
vi.spyOn(router, 'restore').mockImplementation((candidate) =>
candidate === key
? {
operation_key: '00000000-0000-4000-8000-000000000001',
reason: '',
...(parts
? { sources: [preparedSource] }
: {
expected_plan_hash: 'synthetic-plan',
budget_distribution_preparation: [allocation],
}),
}
: undefined,
);
expect(render(parts)).toContain('data-preparation-dirty="false"');
},
);