// @vitest-environment happy-dom // #1025 VehiclePicker, #1026 RelateDocuments, #1027 PrintSendDialog. import { afterEach, describe, expect, it, vi } from 'vitest' import { cleanup, fireEvent, render, screen, waitFor, within } from '@testing-library/react' vi.mock('react-i18next', () => ({ useTranslation: () => ({ t: (k: string, o?: any) => o?.defaultValue ?? k, i18n: { language: 'es' } }), })) import { VehiclePicker, type VehicleResult } from '../business/vehicle-picker' import { RelateDocuments, serializeRelatedDocuments, type RelatedDocument } from '../business/relate-documents' import { PrintSendDialog } from '../business/print-send-dialog' import { PermissionsProvider } from '../permissions-context' import { ApiProvider, type ApiClient } from '../api-context' import { BUSINESS_COMPONENTS } from '../business/catalog' import * as runtime from '../index' afterEach(cleanup) const apiStub = (): ApiClient => ({ get: vi.fn().mockResolvedValue({ data: {} }), post: vi.fn().mockResolvedValue({ data: { data: { id: 'v9', plate: 'NEW-001', vin: 'VIN9' } } }), put: vi.fn(), delete: vi.fn(), }) as unknown as ApiClient describe('exports', () => { it('se exportan desde el runtime y están en el catálogo', () => { expect(runtime.VehiclePicker).toBeTypeOf('function') expect(runtime.RelateDocuments).toBeTypeOf('function') expect(runtime.PrintSendDialog).toBeTypeOf('function') const names = BUSINESS_COMPONENTS.map((c) => c.name) expect(names).toEqual(expect.arrayContaining(['VehiclePicker', 'RelateDocuments', 'PrintSendDialog'])) }) }) describe('VehiclePicker', () => { const veh: VehicleResult = { id: 'v1', plate: 'ABC-123', vin: '1HGCM82633A004352', make: 'Nissan', model: 'Versa', year: 2019 } it('busca por placa o VIN y elige el resultado', async () => { const search = vi.fn().mockResolvedValue([veh]) const onChange = vi.fn() render( , ) fireEvent.change(screen.getByPlaceholderText('Placa o VIN'), { target: { value: 'ABC' } }) const opt = await screen.findByRole('option') expect(search.mock.calls[0][0]).toBe('ABC') // La opción misma es el elemento interactivo (RecordPicker: role=option // sin