@@ -0,0 +1,153 @@
|
||||
import { App, router } from '@inertiajs/react';
|
||||
import { renderToStaticMarkup } from 'react-dom/server';
|
||||
import { afterEach, expect, test, vi } from 'vitest';
|
||||
import UrgentStock from '@/pages/requisitions/urgent-stock';
|
||||
import Summary from '@/components/urgent-quotation-summary';
|
||||
import { ComparisonPolicySummary } from '@/components/comparison-policy-summary';
|
||||
|
||||
afterEach(() => vi.restoreAllMocks());
|
||||
const policy = {
|
||||
revision: 2,
|
||||
configured: true,
|
||||
minimum_proposals: 3,
|
||||
minimum_evaluators: 2,
|
||||
urgent_minimum_proposals: 1,
|
||||
weights: { price: 40, quality: 20, delivery: 15, history: 15, payment: 10 },
|
||||
};
|
||||
const proof = {
|
||||
id: 9,
|
||||
version: 1,
|
||||
created_at: '2026-11-28T10:00:00Z',
|
||||
reason: 'SYNTHETIC-STOCK-PROOF',
|
||||
data: { requisition_item_id: 8 },
|
||||
snapshot: {
|
||||
item: { description: 'Synthetic material' },
|
||||
stock_policy: {
|
||||
minimum_stock_milli: 20000,
|
||||
usage_context: 'Daily synthetic production',
|
||||
warehouse: { name: 'Synthetic warehouse' },
|
||||
},
|
||||
availability: { free_milli: null },
|
||||
author: { name: 'Synthetic procurement' },
|
||||
},
|
||||
};
|
||||
function render(
|
||||
actor = 7,
|
||||
canRecord = true,
|
||||
evidence = false,
|
||||
configured = true,
|
||||
) {
|
||||
return renderToStaticMarkup(
|
||||
<App
|
||||
initialComponent={UrgentStock}
|
||||
initialPage={{
|
||||
component: 'requisitions/urgent-stock',
|
||||
url: '/requisicoes/3/urgencia-stock',
|
||||
version: null,
|
||||
clearHistory: false,
|
||||
encryptHistory: true,
|
||||
props: {
|
||||
errors: {},
|
||||
auth: {
|
||||
user: {
|
||||
id: actor,
|
||||
tenant_id: 4,
|
||||
name: 'Synthetic actor',
|
||||
},
|
||||
},
|
||||
workContext: { active: 'procurement.internal' },
|
||||
organizationAccess: { permissions: ['procurement'] },
|
||||
requisition: {
|
||||
id: 3,
|
||||
number: 'REQ-QA',
|
||||
priority: 'urgent',
|
||||
justification: 'Synthetic risk of stopping production.',
|
||||
},
|
||||
cycle: 1,
|
||||
canRecord,
|
||||
items: [
|
||||
{
|
||||
id: 8,
|
||||
description: 'Synthetic material',
|
||||
catalogue_snapshot: { stock_item_id: 1 },
|
||||
},
|
||||
],
|
||||
comparisonPolicy: configured
|
||||
? policy
|
||||
: { ...policy, urgent_minimum_proposals: undefined },
|
||||
policies: {
|
||||
data: [
|
||||
{
|
||||
id: 11,
|
||||
version: 2,
|
||||
stock_item_id: 1,
|
||||
item: {
|
||||
name: 'Synthetic material',
|
||||
unit: 'un',
|
||||
},
|
||||
warehouse: { name: 'Synthetic warehouse' },
|
||||
minimum_stock_milli: 20000,
|
||||
usage_context: 'Daily synthetic production',
|
||||
},
|
||||
],
|
||||
prev_page_url: null,
|
||||
next_page_url: null,
|
||||
},
|
||||
evidence: evidence ? [proof] : [],
|
||||
eligible: evidence ? [proof] : [],
|
||||
},
|
||||
}}
|
||||
/>,
|
||||
);
|
||||
}
|
||||
test('urgent stock preparation is scoped to actor process cycle and immutable evidence version without automatic submission', () => {
|
||||
const identity =
|
||||
'procurement-preparations:4:7:procurement.internal:procurement:urgent-stock:3:1:2:8:0';
|
||||
vi.spyOn(router, 'restore').mockImplementation((key) =>
|
||||
key === `${identity}:form:data`
|
||||
? {
|
||||
item_id: 8,
|
||||
policy_id: '11',
|
||||
version: 0,
|
||||
reason: 'RESTORED-URGENT-STOCK-DRAFT',
|
||||
operation_key: '117ed627-098c-49a8-a324-d75c4c989473',
|
||||
}
|
||||
: undefined,
|
||||
);
|
||||
const post = vi.spyOn(router, 'post');
|
||||
expect(render()).toContain('RESTORED-URGENT-STOCK-DRAFT');
|
||||
expect(render()).toContain('data-preparation-dirty="true"');
|
||||
expect(render(8)).not.toContain('RESTORED-URGENT-STOCK-DRAFT');
|
||||
expect(render(7, true, true)).not.toContain('RESTORED-URGENT-STOCK-DRAFT');
|
||||
expect(post).not.toHaveBeenCalled();
|
||||
});
|
||||
test('approval readers see the evidence without being granted the preparation command', () => {
|
||||
const html = render(7, false, true);
|
||||
expect(html).toContain('SYNTHETIC-STOCK-PROOF');
|
||||
expect(html).toContain('Indeterminado');
|
||||
expect(html).not.toContain('>Conferir stock mínimo</button>');
|
||||
expect(render(7, true, false, false)).not.toContain(
|
||||
'>Conferir stock mínimo</button>',
|
||||
);
|
||||
});
|
||||
test('comparison distinguishes the ordinary count from an applied urgent count and preserves independent evaluations', () => {
|
||||
const html = renderToStaticMarkup(
|
||||
<ComparisonPolicySummary
|
||||
policy={{
|
||||
...policy,
|
||||
minimum_proposals: 1,
|
||||
normal_minimum_proposals: 3,
|
||||
}}
|
||||
/>,
|
||||
);
|
||||
expect(html).toContain('mínimo de 1 propostas');
|
||||
expect(html).toContain('mínimo normal é 3');
|
||||
expect(html).toContain('2 avaliações');
|
||||
});
|
||||
test('frozen stock basis summary has no empty section and never represents unknown free stock as zero', () => {
|
||||
expect(renderToStaticMarkup(<Summary />)).toBe('');
|
||||
const html = renderToStaticMarkup(<Summary records={[proof]} />);
|
||||
expect(html).toContain('SYNTHETIC-STOCK-PROOF');
|
||||
expect(html).toContain('Indeterminado');
|
||||
expect(html).toContain('Daily synthetic production');
|
||||
});
|
||||
Reference in New Issue
Block a user