120 lines
4.4 KiB
TypeScript
120 lines
4.4 KiB
TypeScript
import { App, router } from '@inertiajs/react';
|
|
import { renderToStaticMarkup } from 'react-dom/server';
|
|
import { afterEach, expect, test, vi } from 'vitest';
|
|
import Award from '@/pages/purchases/award';
|
|
import { money } from '@/types/procurement';
|
|
|
|
afterEach(() => vi.restoreAllMocks());
|
|
const option = {
|
|
allocation_key: 'qa-a',
|
|
line_id: 12,
|
|
centre_id: 4,
|
|
subtotal: '50.00',
|
|
total: '50.00',
|
|
line_label: 'Artigo sintético',
|
|
centre_label: 'Centro sintético',
|
|
};
|
|
function render(
|
|
currency = 'MZN',
|
|
reference: object | null = null,
|
|
actorId = 7,
|
|
) {
|
|
return renderToStaticMarkup(
|
|
<App
|
|
initialComponent={Award}
|
|
initialPage={{
|
|
component: 'purchases/award',
|
|
url: '/requisicoes/2/adjudicacao',
|
|
version: null,
|
|
clearHistory: false,
|
|
encryptHistory: true,
|
|
props: {
|
|
errors: {},
|
|
auth: { user: { id: actorId, tenant_id: 3 } },
|
|
requisition: { id: 2, number: 'QA-2', process_version: 4 },
|
|
award: null,
|
|
canSelect: true,
|
|
canDecide: false,
|
|
canIssue: false,
|
|
order: null,
|
|
recommendation: { adopted: false, quotation_id: null },
|
|
budgetDistributionOptions: [option],
|
|
comparison: {
|
|
ready: true,
|
|
top_ids: [1],
|
|
policy: {
|
|
revision: 0,
|
|
configured: false,
|
|
minimum_proposals: 3,
|
|
minimum_evaluators: 2,
|
|
weights: {
|
|
price: 40,
|
|
quality: 20,
|
|
delivery: 15,
|
|
history: 15,
|
|
payment: 10,
|
|
},
|
|
},
|
|
rows: [
|
|
{
|
|
id: 1,
|
|
reference: 'QA-QUOTE',
|
|
supplier: { name: 'Fornecedor sintético' },
|
|
total_minor: 10000,
|
|
subtotal_minor: 10000,
|
|
tax_minor: 0,
|
|
currency,
|
|
reference_amounts: reference,
|
|
evaluation_count: 2,
|
|
eligible: true,
|
|
ineligibility_reasons: [],
|
|
score: 8,
|
|
},
|
|
],
|
|
},
|
|
},
|
|
}}
|
|
/>,
|
|
);
|
|
}
|
|
function rememberSelection() {
|
|
vi.spyOn(router, 'restore').mockImplementation((key) =>
|
|
key === 'award-selection:3:7:2:4:data'
|
|
? {
|
|
quotation_id: '1',
|
|
justification: '',
|
|
delivery_date: '',
|
|
delivery_location: '',
|
|
reason: '',
|
|
budget_distribution_preparation: [option],
|
|
}
|
|
: undefined,
|
|
);
|
|
}
|
|
test('quote is chosen before explicit allocations and a different actor cannot inherit the selection', () => {
|
|
expect(render()).not.toContain('<legend>Distribuição explícita');
|
|
rememberSelection();
|
|
const html = render();
|
|
expect(html.indexOf('id="award-quote"')).toBeLessThan(
|
|
html.indexOf('<legend>Distribuição explícita'),
|
|
);
|
|
expect(html).toContain('Referência da proposta em MZN');
|
|
expect(render('MZN', null, 8)).not.toContain(
|
|
'<legend>Distribuição explícita',
|
|
);
|
|
});
|
|
test('foreign values never replace an unavailable MZN reference and a frozen reference is shown exactly', () => {
|
|
rememberSelection();
|
|
const missing = render('USD');
|
|
expect(missing).toContain('Referência em MZN indisponível');
|
|
expect(missing).toMatch(/disabled=""[^>]*>Registar adjudicação/);
|
|
const converted = render('USD', {
|
|
subtotal_minor: 600000,
|
|
tax_minor: 0,
|
|
total_minor: 600000,
|
|
});
|
|
expect(converted).toContain(money(600000, 'MZN'));
|
|
expect(converted).not.toContain(`sem IVA ${money(10000, 'MZN')}`);
|
|
expect(converted).not.toContain('Referência em MZN indisponível');
|
|
});
|