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
@@ -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);
});