@@ -0,0 +1,106 @@
|
||||
import { renderToStaticMarkup } from 'react-dom/server';
|
||||
import { expect, test } from 'vitest';
|
||||
import AgreementOrderBindings, {
|
||||
AgreementOrderLimitSummary,
|
||||
} from '@/components/agreement-order-bindings';
|
||||
import type { FrozenOrderAgreement } from '@/types/purchase';
|
||||
|
||||
const option = {
|
||||
contract: {
|
||||
reference: 'CONTRATO-GLOBAL-ANTES-EMISSAO',
|
||||
version: 2,
|
||||
currency: 'MZN',
|
||||
max_order_value_minor: 20000,
|
||||
},
|
||||
id: 7,
|
||||
version: 2,
|
||||
reference: 'ACORDO-QA',
|
||||
stock_item_id: 3,
|
||||
warehouse: 'Armazém de teste',
|
||||
unit: 'un',
|
||||
currency: 'MZN',
|
||||
max_order_value_minor: 10000,
|
||||
max_order_quantity_milli: 1000,
|
||||
};
|
||||
test('issue form makes association explicit and describes a full limit for each order', () => {
|
||||
const html = renderToStaticMarkup(
|
||||
<AgreementOrderBindings
|
||||
requestId={1}
|
||||
lines={[
|
||||
{
|
||||
id: 4,
|
||||
description: 'Artigo sintético',
|
||||
stock_item_id: 3,
|
||||
unit: 'un',
|
||||
},
|
||||
]}
|
||||
options={[option]}
|
||||
value={[{ requisition_item_id: 4, agreement_id: 7 }]}
|
||||
onChange={() => {}}
|
||||
/>,
|
||||
);
|
||||
expect(html).toContain('Cada ordem pode utilizar o limite completo');
|
||||
expect(html).toContain('sem somar outras ordens');
|
||||
expect(html).toContain('ACORDO-QA');
|
||||
expect(html).toContain('Sem acordo associado');
|
||||
expect(html).toContain('Pesquisar acordos');
|
||||
expect(html).toContain('CONTRATO-GLOBAL-ANTES-EMISSAO');
|
||||
expect(html).toContain('Soma todos os artigos ligados ao mesmo contrato');
|
||||
expect(html).toContain('type="button"');
|
||||
});
|
||||
|
||||
test('a missing selected version is visibly unavailable and a catalogue identity is required instead of a name match', () => {
|
||||
const html = renderToStaticMarkup(
|
||||
<AgreementOrderBindings
|
||||
requestId={1}
|
||||
lines={[
|
||||
{
|
||||
id: 4,
|
||||
description: 'Artigo sintético',
|
||||
stock_item_id: null,
|
||||
unit: 'un',
|
||||
},
|
||||
]}
|
||||
options={[]}
|
||||
value={[{ requisition_item_id: 4, agreement_id: 7 }]}
|
||||
onChange={() => {}}
|
||||
/>,
|
||||
);
|
||||
expect(html).toContain('Selecção já não disponível');
|
||||
expect(html).toContain('disabled');
|
||||
expect(html).toContain('o nome da linha não comprova essa ligação');
|
||||
});
|
||||
|
||||
test('order summary uses frozen group totals once per agreement and keeps absence separate from zero', () => {
|
||||
const row: FrozenOrderAgreement = {
|
||||
contract: {
|
||||
id: 5,
|
||||
reference: 'CONTRATO-GLOBAL-QA',
|
||||
version: 2,
|
||||
currency: 'MZN',
|
||||
max_order_value_minor: null,
|
||||
checked_order_value_minor: 20000,
|
||||
},
|
||||
agreement_id: 7,
|
||||
record_key: 'synthetic',
|
||||
version: 2,
|
||||
reference: 'ACORDO-QA',
|
||||
unit: 'un',
|
||||
currency: 'MZN',
|
||||
checked_order_value_minor: 0,
|
||||
checked_order_quantity_milli: '2000',
|
||||
max_order_value_minor: null,
|
||||
max_order_quantity_milli: 0,
|
||||
};
|
||||
const html = renderToStaticMarkup(
|
||||
<AgreementOrderLimitSummary bindings={{ 1: row, 2: row }} />,
|
||||
);
|
||||
expect(html.match(/ACORDO-QA/g)).toHaveLength(1);
|
||||
expect(html.match(/CONTRATO-GLOBAL-QA/g)).toHaveLength(1);
|
||||
expect(html).toContain('Total com impostos dos artigos ligados');
|
||||
expect(html).toContain('Não definido');
|
||||
expect(html).toContain('2,000 un');
|
||||
expect(html).toContain('0,000 un');
|
||||
expect(html).toContain('sem acumular outras ordens');
|
||||
expect(renderToStaticMarkup(<AgreementOrderLimitSummary />)).toBe('');
|
||||
});
|
||||
Reference in New Issue
Block a user