57 lines
2.2 KiB
TypeScript
57 lines
2.2 KiB
TypeScript
import { App } from '@inertiajs/react';
|
|
import { renderToStaticMarkup } from 'react-dom/server';
|
|
import { expect, test } from 'vitest';
|
|
import ImportTariffs from '@/pages/supply/import-tariffs';
|
|
|
|
test.each([false, true])(
|
|
'tariff lookup remains a consultation while business forms respect authority (%s)',
|
|
(canWrite) => {
|
|
const page = { data: [], prev_page_url: null, next_page_url: null };
|
|
const html = renderToStaticMarkup(
|
|
<App
|
|
initialComponent={ImportTariffs}
|
|
initialPage={{
|
|
component: 'supply/import-tariffs',
|
|
url: '/requisicoes/1/classificacao-pautal',
|
|
version: null,
|
|
clearHistory: false,
|
|
encryptHistory: true,
|
|
props: {
|
|
errors: {},
|
|
requisition: { id: 1, number: 'REQ-QA' },
|
|
actorId: 2,
|
|
tenantId: 3,
|
|
legalReady: true,
|
|
canPropose: canWrite,
|
|
canConfirm: canWrite,
|
|
masterSearch: 'QA<123',
|
|
items: [
|
|
{
|
|
id: 4,
|
|
description: 'Material QA',
|
|
quantity: '1',
|
|
unit: 'un',
|
|
},
|
|
],
|
|
latest: [],
|
|
history: page,
|
|
masters: page,
|
|
stockItems: page,
|
|
},
|
|
}}
|
|
/>,
|
|
);
|
|
const forms = html.match(/<form\b[^>]*>/g) ?? [];
|
|
expect(
|
|
forms.filter((form) => form.includes('data-query-form="true"')),
|
|
).toHaveLength(1);
|
|
expect(forms.find((form) => form.includes('method="get"'))).toContain(
|
|
'data-query-form="true"',
|
|
);
|
|
expect(forms).toHaveLength(canWrite ? 2 : 1);
|
|
expect(html).toContain('QA<123');
|
|
expect(html).toContain('/requisicoes/1/base-legal');
|
|
expect(html).not.toContain('data-query-form="true" data-preparation');
|
|
},
|
|
);
|