refactor: remove unused attendee detail components and provider
This commit is contained in:
111
apps/web/test/attendee-attendance.test.ts
Normal file
111
apps/web/test/attendee-attendance.test.ts
Normal file
@@ -0,0 +1,111 @@
|
||||
import { describe, expect, test } from 'bun:test'
|
||||
import type { AttendanceStatus } from '@gruperly/shared'
|
||||
import {
|
||||
attendanceStatusLabel,
|
||||
attendanceSummaryLabel,
|
||||
classCountLabel,
|
||||
formatMemberSince,
|
||||
formatSessionShortDate,
|
||||
HISTORY_LIMIT,
|
||||
HISTORY_PREVIEW,
|
||||
visibleSessions,
|
||||
type AttendanceSession,
|
||||
} from '../src/features/attendee-detail/attendance'
|
||||
|
||||
/* La sección de asistencia no lee estos valores de la API: los deriva. Todo lo
|
||||
que decide qué se muestra —cuántas filas, el plural, el orden— vive acá. */
|
||||
|
||||
const fecha = (day: number) => new Date(2026, 8, day, 12).toISOString()
|
||||
|
||||
const sesion = (
|
||||
day: number,
|
||||
status: AttendanceStatus | null = 'PRESENT',
|
||||
): AttendanceSession => ({
|
||||
classSessionId: `s-${day}`,
|
||||
startsAt: fecha(day),
|
||||
status,
|
||||
})
|
||||
|
||||
// El endpoint devuelve de la más antigua a la más reciente.
|
||||
const historial = [
|
||||
sesion(1, 'PRESENT'),
|
||||
sesion(2, 'ABSENT'),
|
||||
sesion(3, 'EXCUSED'),
|
||||
sesion(4, 'PRESENT'),
|
||||
sesion(5, null),
|
||||
sesion(6, 'PRESENT'),
|
||||
]
|
||||
|
||||
describe('classCountLabel', () => {
|
||||
test('una clase en singular, dos en plural', () => {
|
||||
expect(classCountLabel(1)).toBe('1 clase')
|
||||
expect(classCountLabel(2)).toBe('2 clases')
|
||||
expect(classCountLabel(0)).toBe('0 clases')
|
||||
})
|
||||
})
|
||||
|
||||
describe('attendanceStatusLabel', () => {
|
||||
test('el estado se escribe, no se insinúa con el color', () => {
|
||||
expect(attendanceStatusLabel('PRESENT')).toBe('Asistió')
|
||||
expect(attendanceStatusLabel('ABSENT')).toBe('Faltó')
|
||||
expect(attendanceStatusLabel('EXCUSED')).toBe('Faltó (avisó)')
|
||||
})
|
||||
|
||||
test('una clase sin marcar no se cuenta como asistencia', () => {
|
||||
expect(attendanceStatusLabel(null)).toBe('Sin registrar')
|
||||
})
|
||||
})
|
||||
|
||||
describe('attendanceSummaryLabel', () => {
|
||||
test('cuenta solo las asistidas de las filas que se ven', () => {
|
||||
expect(attendanceSummaryLabel(visibleSessions(historial, false))).toBe('2 de 5 clases')
|
||||
})
|
||||
|
||||
test('con una sola clase el total va en singular', () => {
|
||||
expect(attendanceSummaryLabel([sesion(6, 'PRESENT')])).toBe('1 de 1 clase')
|
||||
})
|
||||
|
||||
test('sin clases no inventa una asistencia', () => {
|
||||
expect(attendanceSummaryLabel([])).toBe('0 de 0 clases')
|
||||
})
|
||||
})
|
||||
|
||||
describe('visibleSessions', () => {
|
||||
test('la vista previa son las últimas, de la más reciente a la más antigua', () => {
|
||||
const visibles = visibleSessions(historial, false)
|
||||
expect(visibles).toHaveLength(HISTORY_PREVIEW)
|
||||
expect(visibles.map((item) => item.classSessionId)).toEqual([
|
||||
's-6',
|
||||
's-5',
|
||||
's-4',
|
||||
's-3',
|
||||
's-2',
|
||||
])
|
||||
})
|
||||
|
||||
test('"ver todas" muestra el historial entero, sin inventar clases', () => {
|
||||
expect(visibleSessions(historial, true)).toHaveLength(historial.length)
|
||||
expect(visibleSessions([], true)).toEqual([])
|
||||
})
|
||||
|
||||
test('con menos de 5 clases se muestran todas y no hace falta el toggle', () => {
|
||||
const pocas = historial.slice(0, 3)
|
||||
expect(visibleSessions(pocas, false)).toHaveLength(3)
|
||||
})
|
||||
|
||||
test('el tope es el del endpoint: 20 sesiones', () => {
|
||||
expect(HISTORY_LIMIT).toBe(20)
|
||||
})
|
||||
})
|
||||
|
||||
describe('formatSessionShortDate', () => {
|
||||
test('fecha corta con día de la semana', () => {
|
||||
expect(formatSessionShortDate(fecha(28))).toBe('lun 28 sep')
|
||||
})
|
||||
})
|
||||
|
||||
describe('formatMemberSince', () => {
|
||||
test('fecha abreviada con año, en una sola línea', () => {
|
||||
expect(formatMemberSince(fecha(18))).toBe('18 sep 2026')
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user