Files
gruperly/apps/web/test/attendee-detail.test.ts
Jose Selesan faf949fc9b feat(attendee-detail): enhance attendee detail view with payment and notes sections
- Added payment presentation logic to display payment status and due dates.
- Introduced AttendeeNotesSection and AttendeePaymentsSection components for managing notes and payments.
- Implemented forms for editing contact information and notes with validation.
- Updated API to support attendee updates and added corresponding tests.
- Improved attendance summary logic to reflect all visible sessions.
- Enhanced UI with loading states and error handling for better user experience.
2026-10-01 18:41:55 -03:00

109 lines
3.1 KiB
TypeScript

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(/<input[^>]*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(/<textarea[^>]*autofocus=""[^>]*aria-label="Notas del miembro"/)
})
})