import { describe, expect, test } from 'bun:test' import { createElement } from 'react' import { renderToStaticMarkup } from 'react-dom/server' import { AttendeeContactForm } from '../src/features/attendee-detail/AttendeeContactForm' import { AttendeeNotesForm } from '../src/features/attendee-detail/AttendeeNotesForm' import { contactEmailError, formatNotesUpdatedAt, paymentPresentation, } from '../src/features/attendee-detail/detail' describe('contactEmailError', () => { test('permite email vacío', () => { expect(contactEmailError('')).toBeNull() }) test('muestra el error acordado para un email inválido', () => { expect(contactEmailError('sin-arroba')).toBe('Ingresá un email válido') }) test('acepta un email válido', () => { expect(contactEmailError('lucas@example.com')).toBeNull() }) }) describe('paymentPresentation', () => { const today = new Date('2026-10-01T12:00:00.000Z') test('un cobro pendiente alimenta la sección y el chip', () => { expect( paymentPresentation( { status: 'PENDING', dueDate: '2026-10-10T00:00:00.000Z' }, today, ), ).toEqual({ periodLabel: 'Octubre 2026', statusLabel: 'Pendiente', chipLabel: 'Debe octubre', isDue: true, }) }) test('un cobro pagado se muestra al día', () => { expect( paymentPresentation( { status: 'PAID', dueDate: '2026-10-10T00:00:00.000Z' }, today, ).chipLabel, ).toBe('Al día') }) test('sin cobro registrado no inventa un pendiente', () => { expect(paymentPresentation(null, today)).toEqual({ periodLabel: 'Octubre 2026', statusLabel: 'Sin cobro registrado', chipLabel: 'Al día', isDue: false, }) }) }) describe('formatNotesUpdatedAt', () => { test('usa hoy cuando la edición fue en la misma fecha', () => { expect( formatNotesUpdatedAt('2026-10-01T08:00:00.000Z', new Date('2026-10-01T18:00:00.000Z')), ).toBe('Editado hoy') }) test('usa una fecha corta para ediciones anteriores', () => { expect( formatNotesUpdatedAt('2026-09-29T08:00:00.000Z', new Date('2026-10-01T18:00:00.000Z')), ).toBe('Editado 29 sep 2026') }) }) describe('foco inicial de los formularios del miembro', () => { test('el formulario de contacto enfoca el teléfono', () => { const markup = renderToStaticMarkup( createElement(AttendeeContactForm, { phone: '', email: '', error: null, isSaving: false, onPhoneChange: () => {}, onEmailChange: () => {}, onCancel: () => {}, onSave: () => {}, }), ) expect(markup).toMatch(/]*autofocus=""[^>]*aria-label="Teléfono"/) }) test('el formulario de notas enfoca el textarea', () => { const markup = renderToStaticMarkup( createElement(AttendeeNotesForm, { draft: '', error: null, isSaving: false, onDraftChange: () => {}, onCancel: () => {}, onSave: () => {}, }), ) expect(markup).toMatch(/]*autofocus=""[^>]*aria-label="Notas del miembro"/) }) })