import { App, router } from '@inertiajs/react'; import { renderToStaticMarkup } from 'react-dom/server'; import { afterEach, expect, test, vi } from 'vitest'; import Legal, { revealInvalidLegalField, } from '../../resources/js/pages/supply/import-legal'; test('incomplete legal preparation reveals the first invalid field below the fixed header', () => { const callbacks: FrameRequestCallback[] = []; vi.stubGlobal('requestAnimationFrame', (callback: FrameRequestCallback) => { callbacks.push(callback); return callbacks.length; }); const field = { focus: vi.fn(), scrollIntoView: vi.fn() }; const form = { querySelector: vi.fn((selector: string) => selector === 'input:invalid, select:invalid, textarea:invalid' ? field : { tagName: 'FIELDSET' }, ), }; try { revealInvalidLegalField({ currentTarget: form, target: field, } as never); revealInvalidLegalField({ currentTarget: form, target: {} } as never); expect(callbacks).toHaveLength(1); expect(field.scrollIntoView).not.toHaveBeenCalled(); callbacks[0](0); expect(field.focus).toHaveBeenCalledWith({ preventScroll: true }); expect(field.scrollIntoView).toHaveBeenCalledWith({ block: 'center', behavior: 'instant', }); } finally { vi.unstubAllGlobals(); } }); afterEach(() => vi.restoreAllMocks()); test.each([true, false])( 'legal shortcuts target present focusable sections without exposing management (%s)', (canManage) => { const html = renderLegal(canManage); const navigation = html.match( /