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.
This commit is contained in:
@@ -57,15 +57,9 @@ describe('attendanceStatusLabel', () => {
|
||||
})
|
||||
|
||||
describe('attendanceSummary', () => {
|
||||
test('el denominador son las clases registradas, no todas las filas', () => {
|
||||
// La vista previa son 5 filas, pero una quedó sin registrar: el resumen
|
||||
// cuenta 4, no 5, porque sin dato no hay ni asistencia ni ausencia.
|
||||
test('el denominador coincide con todas las filas visibles', () => {
|
||||
const { label } = attendanceSummary(visibleSessions(historial, false))
|
||||
expect(label).toBe('2 de 4 clases')
|
||||
})
|
||||
|
||||
test('las clases sin registro se avisan aparte, no mezcladas en el total', () => {
|
||||
expect(attendanceSummary(visibleSessions(historial, false)).unmarkedLabel).toBe('1 sin registrar')
|
||||
expect(label).toBe('2 de 5 clases')
|
||||
})
|
||||
|
||||
test('con una sola clase el total va en singular', () => {
|
||||
@@ -75,18 +69,16 @@ describe('attendanceSummary', () => {
|
||||
test('sin nada registrado lo dice, en vez de "0 de 0"', () => {
|
||||
const sinRegistrar = [sesion(5, null), sesion(6, null)]
|
||||
expect(attendanceSummary(sinRegistrar)).toEqual({
|
||||
label: 'Sin clases registradas',
|
||||
unmarkedLabel: null,
|
||||
label: '0 de 2 clases',
|
||||
})
|
||||
expect(attendanceSummary([])).toEqual({
|
||||
label: 'Sin clases registradas',
|
||||
unmarkedLabel: null,
|
||||
})
|
||||
})
|
||||
|
||||
test('faltó y faltó con aviso también cuentan como clases registradas', () => {
|
||||
const marcadas = [sesion(1, 'ABSENT'), sesion(2, 'EXCUSED')]
|
||||
expect(attendanceSummary(marcadas)).toEqual({ label: '0 de 2 clases', unmarkedLabel: null })
|
||||
expect(attendanceSummary(marcadas)).toEqual({ label: '0 de 2 clases' })
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
108
apps/web/test/attendee-detail.test.ts
Normal file
108
apps/web/test/attendee-detail.test.ts
Normal file
@@ -0,0 +1,108 @@
|
||||
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"/)
|
||||
})
|
||||
})
|
||||
@@ -11,12 +11,15 @@ describe('isImmersiveRoute', () => {
|
||||
expect(isImmersiveRoute('/class/ses_987/attendance')).toBe(true)
|
||||
})
|
||||
|
||||
test('las rutas hijas del grupo no lo son', () => {
|
||||
test('el detalle de miembro también es immersive', () => {
|
||||
expect(isImmersiveRoute('/groups/cm1234/attendees/at_55')).toBe(true)
|
||||
})
|
||||
|
||||
test('las demás rutas hijas del grupo no lo son', () => {
|
||||
expect(isImmersiveRoute('/groups')).toBe(false)
|
||||
expect(isImmersiveRoute('/groups/')).toBe(false)
|
||||
expect(isImmersiveRoute('/groups/new')).toBe(false)
|
||||
expect(isImmersiveRoute('/groups/cm1234/attendees/new')).toBe(false)
|
||||
expect(isImmersiveRoute('/groups/cm1234/attendees/at_55')).toBe(false)
|
||||
})
|
||||
|
||||
test('el resto de la app mantiene el header global', () => {
|
||||
|
||||
Reference in New Issue
Block a user