feat(captura): fecha junto a checkboxes de Obra con semaforo verde/rojo
This commit is contained in:
@@ -206,4 +206,49 @@ describe('TablaCaptura', () => {
|
||||
fireEvent.click(screen.getByText('Siguiente'))
|
||||
expect(screen.getByText(/Mostrando 51–60 de 60/)).toBeTruthy()
|
||||
})
|
||||
|
||||
it('boolean con conFecha: fecha + checkbox en una celda, semáforo y dirty del campo fecha', () => {
|
||||
const onGuardar = vi.fn()
|
||||
const camposEmparejados: CampoDef[] = [
|
||||
{ campo: 'certificacion_gas', tipo: 'boolean', label: 'Certificación Gas', conFecha: 'certificacion_gas_fecha' },
|
||||
{ campo: 'certificacion_gas_fecha', tipo: 'date', label: 'Fecha Certificación Gas' },
|
||||
]
|
||||
const datosEmparejados: DatosCaptura = {
|
||||
// Check activo → fecha en verde
|
||||
'409-1': { certificacion_gas: 'true', certificacion_gas_fecha: '2026-01-01' },
|
||||
// Fecha pasada sin check → fecha en rojo
|
||||
'409-2': { certificacion_gas: null, certificacion_gas_fecha: '2026-01-01' },
|
||||
}
|
||||
|
||||
const { container } = render(
|
||||
<TablaCaptura
|
||||
unidades={UNIDADES}
|
||||
campos={camposEmparejados}
|
||||
datos={datosEmparejados}
|
||||
onGuardar={onGuardar}
|
||||
guardando={false}
|
||||
/>,
|
||||
)
|
||||
|
||||
// La columna standalone de fecha se oculta: solo Unidad + Certificación Gas
|
||||
expect(screen.getAllByRole('columnheader')).toHaveLength(2)
|
||||
expect(screen.queryByText('Fecha Certificación Gas')).toBeNull()
|
||||
|
||||
// Un date input y un checkbox por unidad
|
||||
const fechas = container.querySelectorAll('input[type="date"]')
|
||||
expect(fechas).toHaveLength(2)
|
||||
expect((fechas[0] as HTMLInputElement).value).toBe('2026-01-01')
|
||||
|
||||
// Semáforo: check activo → verde; fecha pasada sin check → rojo
|
||||
expect(fechas[0].className).toContain('text-green-600')
|
||||
expect(fechas[1].className).toContain('text-red-600')
|
||||
|
||||
// Cambiar la fecha marca dirty en el campo _fecha y se guarda en el bulk
|
||||
fireEvent.change(fechas[1], { target: { value: '2026-12-01' } })
|
||||
fireEvent.click(screen.getByText('Guardar cambios'))
|
||||
|
||||
expect(onGuardar).toHaveBeenCalledTimes(1)
|
||||
const dirty = onGuardar.mock.calls[0][0]
|
||||
expect(dirty['409-2']).toEqual({ certificacion_gas_fecha: '2026-12-01' })
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user