feat: enhance group management features with improved attendance tracking and UI components
This commit is contained in:
@@ -3,18 +3,23 @@ import type { GroupRiskSummary, UrgentMemberSummary } from '@gruperly/shared'
|
||||
import { createElement } from 'react'
|
||||
import { renderToStaticMarkup } from 'react-dom/server'
|
||||
import {
|
||||
alertTextFromMembers,
|
||||
barCapacity,
|
||||
capacityCounts,
|
||||
capacityCountsFromMembers,
|
||||
isSegmentedCapacity,
|
||||
MOCK_TEST_CASES,
|
||||
occupancyLabel,
|
||||
riskTone,
|
||||
SEGMENTED_CAPACITY_MAX,
|
||||
statusLine,
|
||||
type GroupMember,
|
||||
} from '../src/features/groups/card'
|
||||
import {
|
||||
capacityIndicatorLabel,
|
||||
capacitySegmentWidth,
|
||||
} from '../src/features/groups/AttendanceCapacityIndicator'
|
||||
import { GroupCardContent } from '../src/features/groups/GroupCard'
|
||||
import { GroupCard, GroupCardContent } from '../src/features/groups/GroupCard'
|
||||
|
||||
/* La tarjeta del listado no calcula el riesgo: lo recibe de
|
||||
`GET /groups-risk/overview`, que corre la función de dominio del backend. Lo
|
||||
@@ -53,18 +58,116 @@ const urgente = (extra: Partial<UrgentMemberSummary> = {}): UrgentMemberSummary
|
||||
|
||||
const grupo = (attendeesCount: number, capacity: number | null) => ({ attendeesCount, capacity })
|
||||
|
||||
describe('GroupCardContent', () => {
|
||||
test('no muestra un segundo label de lugares junto al nombre', () => {
|
||||
describe('GroupCard - Casos de prueba de referencia', () => {
|
||||
test('Caso 1: Tai Chi Martes (cupo 5, 4/5 miembros, 5 píldoras, alerta Sofía)', () => {
|
||||
const markup = renderToStaticMarkup(createElement(GroupCard, { ...MOCK_TEST_CASES[0], link: false }))
|
||||
|
||||
// Fila 1: el nombre solo. El cupo no se repite: ya está en "4/5 miembros"
|
||||
expect(markup).toContain('Tai Chi Martes')
|
||||
expect(markup).not.toContain('whitespace-nowrap text-base tabular-nums text-secondary')
|
||||
|
||||
// Fila 2: 4/5 miembros en una sola línea y 5 píldoras individuales
|
||||
expect(markup).toContain('4/5 miembros')
|
||||
expect(markup).toContain('whitespace-nowrap text-lg tabular-nums text-secondary">4/5 miembros')
|
||||
|
||||
// Píldoras individuales (Modo A: cupo <= 10)
|
||||
// 1 rojo (high), 1 ámbar (attention), 2 azul (ok), 1 vacía (libres)
|
||||
expect(markup).toContain('w-[50px] shrink-0')
|
||||
expect(markup).toContain('bg-attendance-high')
|
||||
expect(markup).toContain('bg-attendance-attention')
|
||||
expect(markup).toContain('bg-attendance-ok')
|
||||
|
||||
// Fila 3: alerta roja con ícono de cuadrado
|
||||
expect(markup).toContain('Sofía: 4 faltas · 1 en atención')
|
||||
expect(markup).toContain('text-[#8B1A1A]')
|
||||
})
|
||||
|
||||
test('Caso 2: Pilates Sábado (cupo 15, 12/15 miembros, barra continua, alerta Sofía)', () => {
|
||||
const markup = renderToStaticMarkup(createElement(GroupCard, { ...MOCK_TEST_CASES[1], link: false }))
|
||||
|
||||
// Fila 1: el nombre solo
|
||||
expect(markup).toContain('Pilates Sábado')
|
||||
|
||||
// Fila 2
|
||||
expect(markup).toContain('12/15 miembros')
|
||||
|
||||
// Modo B: barra continua (overflow-hidden rounded-full)
|
||||
expect(markup).toContain('overflow-hidden rounded-full')
|
||||
|
||||
// Fila 3: alerta
|
||||
expect(markup).toContain('Sofía: 4 faltas · 2 en atención')
|
||||
expect(markup).toContain('text-[#8B1A1A]')
|
||||
})
|
||||
|
||||
test('Caso 3: Natación Adultos (cupo 30, 22/30 miembros, barra continua, alerta múltiple)', () => {
|
||||
const markup = renderToStaticMarkup(createElement(GroupCard, { ...MOCK_TEST_CASES[2], link: false }))
|
||||
|
||||
// Fila 1: el nombre solo
|
||||
expect(markup).toContain('Natación Adultos')
|
||||
|
||||
// Fila 2
|
||||
expect(markup).toContain('22/30 miembros')
|
||||
|
||||
// Modo B: barra continua
|
||||
expect(markup).toContain('overflow-hidden rounded-full')
|
||||
|
||||
// Fila 3: alerta con 3 en riesgo alto y 4 en atención
|
||||
expect(markup).toContain('3 en riesgo alto · 4 en atención')
|
||||
expect(markup).toContain('text-[#8B1A1A]')
|
||||
})
|
||||
})
|
||||
|
||||
describe('alertTextFromMembers', () => {
|
||||
test('con exactamente 1 miembro en riesgo alto muestra su nombre y faltas', () => {
|
||||
const members: GroupMember[] = [
|
||||
{ id: '1', name: 'Sofía Ramírez', status: 'high_risk', absences: 4 },
|
||||
{ id: '2', name: 'Lucas', status: 'attention', absences: 1 },
|
||||
{ id: '3', name: 'Martín', status: 'ok', absences: 0 },
|
||||
]
|
||||
expect(alertTextFromMembers(members)).toBe('Sofía: 4 faltas · 1 en atención')
|
||||
})
|
||||
|
||||
test('con exactamente 1 miembro en riesgo alto y sin atención', () => {
|
||||
const members: GroupMember[] = [
|
||||
{ id: '1', name: 'Sofía', status: 'high_risk', absences: 1 },
|
||||
{ id: '2', name: 'Martín', status: 'ok', absences: 0 },
|
||||
]
|
||||
expect(alertTextFromMembers(members)).toBe('Sofía: 1 falta')
|
||||
})
|
||||
|
||||
test('con 2 o más en riesgo alto resume por cantidad', () => {
|
||||
const members: GroupMember[] = [
|
||||
{ id: '1', name: 'Sofía', status: 'high_risk', absences: 4 },
|
||||
{ id: '2', name: 'Mateo', status: 'high_risk', absences: 2 },
|
||||
{ id: '3', name: 'Lucas', status: 'attention', absences: 1 },
|
||||
]
|
||||
expect(alertTextFromMembers(members)).toBe('2 en riesgo alto · 1 en atención')
|
||||
})
|
||||
|
||||
test('sin riesgo alto pero con atención muestra solo atención', () => {
|
||||
const members: GroupMember[] = [
|
||||
{ id: '1', name: 'Lucas', status: 'attention', absences: 1 },
|
||||
{ id: '2', name: 'Elena', status: 'attention', absences: 1 },
|
||||
{ id: '3', name: 'Martín', status: 'ok', absences: 0 },
|
||||
]
|
||||
expect(alertTextFromMembers(members)).toBe('2 en atención')
|
||||
})
|
||||
|
||||
test('sin riesgo alto ni atención devuelve null y no renderiza fila de alerta', () => {
|
||||
const members: GroupMember[] = [
|
||||
{ id: '1', name: 'Lucas', status: 'ok', absences: 0 },
|
||||
{ id: '2', name: 'Martín', status: 'ok', absences: 0 },
|
||||
]
|
||||
expect(alertTextFromMembers(members)).toBeNull()
|
||||
|
||||
const markup = renderToStaticMarkup(
|
||||
createElement(GroupCardContent, {
|
||||
group: { name: 'Tai Chi Martes', attendeesCount: 4, capacity: 5 },
|
||||
risk: risk(1, 1, {
|
||||
urgentes: [urgente({ fullName: 'Sofía Ramírez', consecutiveAbsences: 4 })],
|
||||
}),
|
||||
createElement(GroupCard, {
|
||||
name: 'Yoga Tranquilo',
|
||||
capacity: 10,
|
||||
members,
|
||||
}),
|
||||
)
|
||||
|
||||
expect(markup).not.toContain('hasta 10 lugares')
|
||||
expect(markup).not.toContain('text-[#8B1A1A]')
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user