178 lines
6.5 KiB
TypeScript
178 lines
6.5 KiB
TypeScript
import { readdirSync } from 'node:fs';
|
|
import { join, relative } from 'node:path';
|
|
import { App } from '@inertiajs/react';
|
|
import { renderToStaticMarkup } from 'react-dom/server';
|
|
import { expect, test } from 'vitest';
|
|
import JourneyHelpPanel, {
|
|
JourneyHelpContent,
|
|
} from '@/components/journey-help';
|
|
import { FormErrors } from '@/components/procurement';
|
|
import {
|
|
helpAudience,
|
|
helpForJourney,
|
|
journeyHelp,
|
|
searchJourneyHelp,
|
|
recoveryHints,
|
|
} from '@/lib/journey-help';
|
|
|
|
function pageFiles(root: string): string[] {
|
|
return readdirSync(root, { withFileTypes: true }).flatMap((entry) =>
|
|
entry.isDirectory()
|
|
? pageFiles(join(root, entry.name))
|
|
: entry.name.endsWith('.tsx')
|
|
? [join(root, entry.name)]
|
|
: [],
|
|
);
|
|
}
|
|
|
|
test('multiarticle contract preparation has guidance for its global limit and independent article quantities', () => {
|
|
const help = helpForJourney(
|
|
'supply/index',
|
|
'/compras/fornecimento?view=contracts',
|
|
);
|
|
expect(help.id).toBe('supply-contract');
|
|
expect(help.checks.join(' ')).toContain(
|
|
'Cada ordem pode usar o limite completo',
|
|
);
|
|
expect(help.checks.join(' ')).toContain(
|
|
'Não some quantidades de unidades diferentes',
|
|
);
|
|
});
|
|
|
|
test('every operational page has a specific guide rather than silently falling back to generic instructions', () => {
|
|
const root = join(process.cwd(), 'resources/js/pages');
|
|
const pages = pageFiles(root)
|
|
.map((file) =>
|
|
relative(root, file)
|
|
.replace(/\\/g, '/')
|
|
.replace(/\.tsx$/, ''),
|
|
)
|
|
.filter((name) => !name.startsWith('preview/'));
|
|
const missing = pages.filter(
|
|
(name) => !journeyHelp.some((topic) => topic.pages.includes(name)),
|
|
);
|
|
expect(missing).toEqual([]);
|
|
expect(new Set(journeyHelp.map((topic) => topic.id)).size).toBe(
|
|
journeyHelp.length,
|
|
);
|
|
for (const name of pages)
|
|
expect(helpForJourney(name, '/').audience).toBe(helpAudience(name));
|
|
});
|
|
|
|
test('the supply guide follows the actual stage including imports calendar and technical alternatives', () => {
|
|
expect(
|
|
helpForJourney('supply/index', '/compras/fornecimento?view=imports').id,
|
|
).toBe('supply-import');
|
|
expect(
|
|
helpForJourney('supply/index', '/compras/fornecimento?view=calendar')
|
|
.id,
|
|
).toBe('supply-calendar');
|
|
expect(
|
|
helpForJourney('supply/index', '/compras/fornecimento?view=agreements')
|
|
.id,
|
|
).toBe('supply-agreement');
|
|
expect(
|
|
helpForJourney(
|
|
'supply/coordination',
|
|
'/compras/fornecimento?view=alternatives',
|
|
'alternative',
|
|
).id,
|
|
).toBe('supply-alternative');
|
|
});
|
|
|
|
test('search is local accent insensitive and confines candidate and authentication help to their own audience', () => {
|
|
expect(searchJourneyHelp('FACTURACAO', 'staff')).toEqual([]);
|
|
expect(
|
|
searchJourneyHelp('factura moeda', 'staff').map((topic) => topic.id),
|
|
).toContain('payment');
|
|
expect(
|
|
searchJourneyHelp('conversao', 'staff').map((topic) => topic.id),
|
|
).toContain('receipt');
|
|
expect(
|
|
searchJourneyHelp('candidatura', 'candidate').every(
|
|
(topic) => topic.audience === 'candidate',
|
|
),
|
|
).toBe(true);
|
|
expect(searchJourneyHelp('adjudicacao', 'candidate')).toEqual([]);
|
|
expect(searchJourneyHelp('conta', 'auth').map((topic) => topic.id)).toEqual(
|
|
['authentication'],
|
|
);
|
|
});
|
|
|
|
test('guidance separates payment evidence selection physical receipt and commercial quantities', () => {
|
|
const payment = renderToStaticMarkup(
|
|
<JourneyHelpContent
|
|
topic={helpForJourney('payments/index', '/')}
|
|
hasErrors
|
|
/>,
|
|
);
|
|
expect(payment).toContain('não executa uma transferência bancária');
|
|
expect(payment).toContain('mesma moeda');
|
|
expect(payment).toContain('Há dados por conferir');
|
|
const people = renderToStaticMarkup(
|
|
<JourneyHelpContent topic={helpForJourney('people/show', '/')} />,
|
|
);
|
|
expect(people).toContain('não comprovam assinatura ou admissão');
|
|
const invoice = renderToStaticMarkup(
|
|
<JourneyHelpContent topic={helpForJourney('invoices/index', '/')} />,
|
|
);
|
|
expect(invoice).toContain('não substitui a quantidade comercial');
|
|
});
|
|
|
|
test('validation help never submits a form and every guide includes recovery and a next action', () => {
|
|
const html = renderToStaticMarkup(
|
|
<FormErrors errors={{ quantity: 'Confira a quantidade.' }} />,
|
|
);
|
|
expect(html).toContain('role="alert"');
|
|
expect(html).toContain('type="button"');
|
|
expect(html).toContain('Consultar ajuda para corrigir e continuar');
|
|
expect(html).toContain('Confira a unidade e a quantidade ainda pendente');
|
|
for (const topic of journeyHelp) {
|
|
expect(topic.steps.length).toBeGreaterThan(0);
|
|
expect(topic.checks.length).toBeGreaterThan(0);
|
|
expect(topic.recovery.length).toBeGreaterThan(20);
|
|
expect(topic.next.length).toBeGreaterThan(20);
|
|
}
|
|
});
|
|
|
|
test('field hints address stale submissions quantities lots and bank choice without echoing private data', () => {
|
|
expect(
|
|
recoveryHints(['items.0.accepted_quantity', 'version']).join(' '),
|
|
).toContain('histórico antes de voltar a confirmar');
|
|
expect(recoveryHints(['supplier_bank_detail_id'])[0]).toContain(
|
|
'na moeda da factura',
|
|
);
|
|
expect(recoveryHints(['items.0.lots.0.expires_on'])[0]).toContain(
|
|
'unidade física',
|
|
);
|
|
expect(recoveryHints(['private_note'])).toEqual([]);
|
|
expect(
|
|
recoveryHints(['version', 'quantity', 'bank_id', 'lots']).length,
|
|
).toBe(2);
|
|
});
|
|
|
|
test('the contextual trigger is available within the current Inertia page without exposing form values', () => {
|
|
const html = renderToStaticMarkup(
|
|
<App
|
|
initialPage={{
|
|
component: 'candidate/profile',
|
|
url: '/candidaturas/perfil',
|
|
version: null,
|
|
props: {
|
|
errors: { name: 'Erro' },
|
|
privateNote: 'PRIVATE-FORM-CONTENT',
|
|
},
|
|
clearHistory: false,
|
|
encryptHistory: true,
|
|
}}
|
|
initialComponent={JourneyHelpPanel}
|
|
/>,
|
|
);
|
|
expect(html).toContain(
|
|
'Abrir ajuda desta etapa: Preparar o perfil de candidatura',
|
|
);
|
|
expect(html).toContain('Há dados por conferir');
|
|
expect(html).not.toContain('PRIVATE-FORM-CONTENT');
|
|
expect(html).not.toContain('adjudicação');
|
|
});
|