commit melhorias compras5
tests / ci (push) Waiting to run

This commit is contained in:
2026-11-22 19:39:09 +02:00
parent 36dcfdf00c
commit db1615fac1
79 changed files with 4082 additions and 120 deletions
@@ -4,7 +4,7 @@ import { expect, test } from 'vitest';
import { RequisitionApprovalSettings } from '@/components/requisition-approval-settings';
import { procurementNavigation } from '@/lib/procurement-navigation';
function render(ready: boolean) {
function render(ready: boolean, categoryOptions: Record<string, string> = {}) {
return renderToStaticMarkup(
<App
initialComponent={RequisitionApprovalSettings}
@@ -17,6 +17,7 @@ function render(ready: boolean) {
props: {
errors: {},
ready,
categoryOptions,
version: 4,
profiles: [
{
@@ -42,6 +43,13 @@ function render(ready: boolean) {
scope: 'company',
min_minor: 11601,
categories: ['Material'],
...(Object.keys(categoryOptions).length
? {
procurement_categories: [
'office_equipment',
],
}
: {}),
cost_center_ids: [1],
},
],
@@ -52,6 +60,24 @@ function render(ready: boolean) {
);
}
test('explicit RQ01 group conditions are separate from original article categories and remain hidden until available', () => {
const html = render(true, {
office_equipment: 'Equipamento de escritório',
capital_equipment: 'Maquinaria',
});
expect(html).toContain('Categoria da necessidade (RQ-01)');
expect(html).toContain('Categorias exactas do artigo');
expect(html).toContain('Equipamento de escritório');
expect(html).toContain('Maquinaria');
expect(html).toContain('não são classificados automaticamente');
const groups = html.slice(
html.indexOf('Categoria da necessidade (RQ-01)'),
html.indexOf('Perfis elegíveis'),
);
expect(groups).toContain('checked=""');
expect(render(true)).not.toContain('Categoria da necessidade (RQ-01)');
});
test('approval settings retain exact threshold and selected revoked profiles so the administrator can reconcile the plan', () => {
const html = render(true);
expect(html).toContain('116.01');
@@ -0,0 +1,48 @@
import { renderToStaticMarkup } from 'react-dom/server';
import { expect, test } from 'vitest';
import {
RequisitionCategoryFields,
requisitionCategoryLabels,
} from '@/components/requisition-category-fields';
test('classification fields explain the native controls and preserve the explicit investment reason', () => {
const html = renderToStaticMarkup(
<RequisitionCategoryFields
index={2}
category="capital_equipment"
reason="Investimento deliberado"
options={requisitionCategoryLabels}
onChange={() => {}}
/>,
);
expect(html).toContain('Justificação do investimento');
expect(html).toContain('Investimento deliberado');
expect(html).toContain('orçamento de investimento');
expect(html).toContain('aria-describedby="rq-category-2-help"');
expect(html).toContain('Peças sobressalentes');
});
test('legacy classification stays unselected and production guidance requires the published stock catalogue', () => {
const legacy = renderToStaticMarkup(
<RequisitionCategoryFields
index={0}
category=""
reason=""
options={requisitionCategoryLabels}
onChange={() => {}}
/>,
);
expect(legacy).toContain('Sem classificação adicional');
expect(legacy).toContain('não é inferida');
expect(legacy).not.toContain('<textarea');
const production = renderToStaticMarkup(
<RequisitionCategoryFields
index={1}
category="production_input"
reason=""
options={requisitionCategoryLabels}
onChange={() => {}}
/>,
);
expect(production).toContain('material de stock no catálogo publicado');
});
@@ -6,6 +6,38 @@ import { hasPreparationChanges } from '@/lib/requisition-history';
afterEach(() => vi.restoreAllMocks());
test('new empty classification fields preserve an older recovered preparation while real classification changes remain dirty', () => {
const old = { items: [{ description: 'Artigo anterior' }] };
const current = {
items: [
{
description: 'Artigo anterior',
procurement_category: '',
category_reason: '',
},
],
};
expect(hasPreparationChanges(old, current)).toBe(false);
expect(hasPreparationChanges(current, old)).toBe(false);
expect(
hasPreparationChanges(old, {
items: [
{
...current.items[0],
procurement_category: 'office_equipment',
},
],
}),
).toBe(true);
expect(
hasPreparationChanges(old, {
items: [
{ ...current.items[0], category_reason: 'Razão deliberada' },
],
}),
).toBe(true);
});
test('restored technical identities do not mark a cleared preparation as changed', () => {
const original = {
operation_key: 'initial-operation',
@@ -0,0 +1,96 @@
import { App, router } from '@inertiajs/react';
import { renderToStaticMarkup } from 'react-dom/server';
import { afterEach, expect, test, vi } from 'vitest';
import ProcurementSearch from '@/pages/search/procurement';
import type { SavedSearches } from '../../resources/js/components/saved-procurement-searches';
afterEach(() => vi.restoreAllMocks());
const saved: SavedSearches = {
max_active: 50,
active: [
{
id: 3,
name: '<script>Nome privado</script>',
term: 'QA%_',
version: 4,
href: '/compras/pesquisa?q=QA%25_',
},
],
archived: {
data: [
{
id: 6,
name: 'Anterior',
term: 'Outro texto',
version: 2,
href: '/compras/pesquisa?q=Outro%20texto',
},
],
total: 1,
prev_page_url: null,
next_page_url: null,
},
};
function renderSearch(searches: SavedSearches | null, actorId = 7) {
return renderToStaticMarkup(
<App
initialComponent={ProcurementSearch}
initialPage={{
component: 'search/procurement',
url: '/compras/pesquisa?q=QA',
version: null,
clearHistory: false,
encryptHistory: true,
props: {
errors: {},
auth: { user: { id: actorId, tenant_id: 2 } },
term: 'QA',
groups: [],
savedSearches: searches,
},
}}
/>,
);
}
test('private saved criteria reopen a local live search and explain archival recovery without rendering supplied markup', () => {
const html = renderSearch(saved);
expect(html).toContain('As minhas pesquisas guardadas');
expect(html).toContain('pesquisa activa');
expect(html).toContain('href="/compras/pesquisa?q=QA%25_"');
expect(html).toContain('acesso actual');
expect(html).toContain('Arquivar pesquisa');
expect(html).toContain('Restaurar pesquisa Anterior');
expect(html).toContain('&lt;script&gt;Nome privado&lt;/script&gt;');
expect(html).not.toContain('<script>Nome privado');
});
test('uninstalled saved-search storage does not advertise unavailable actions', () => {
const html = renderSearch(null);
expect(html).not.toContain('As minhas pesquisas guardadas');
expect(html).not.toContain('Guardar pesquisa');
expect(html).toContain('Pesquisar processos');
});
test('encrypted preparation keys isolate owner company source version and editing state', () => {
const keys: string[] = [];
vi.spyOn(router, 'restore').mockImplementation((key) => {
if (key) keys.push(key);
return undefined;
});
renderSearch(saved, 7);
expect(keys.some((key) => key.startsWith('saved-search:2:7:QA'))).toBe(
true,
);
expect(
keys.some((key) => key.startsWith('saved-search-edit:2:7:3:4')),
).toBe(true);
keys.length = 0;
renderSearch(saved, 8);
expect(
keys.some((key) => key.startsWith('saved-search-edit:2:8:3:4')),
).toBe(true);
expect(keys.some((key) => key.includes(':2:7:'))).toBe(false);
});