- Grupos: subtítulo con resumen (grupos · alumnos · lugares libres), sección "Requiere atención" con los 4 alumnos más urgentes y tarjetas con avatares (punteados por lugar libre en grupos chicos, superpuestos con "+N" en grandes; con alerta primero y anillo de gravedad). - Pantalla nueva /groups/attention: filtros Todos/Asistencia/Pagos, secciones Urgente y A vigilar, Contactar / Enviar recordatorio por wa.me y "Resuelto" persistente con update optimista. - FAB "Nuevo grupo" que se pliega al scrollear (respeta reduced motion); los toasts en mobile suben para no quedar debajo. - Alertas centralizadas en computeStudentAlerts (shared). La regla de asistencia pasa a: urgente = 3 seguidas o 4 de las últimas 6; a vigilar = 2 de las últimas 4 (sin inactividad por días ni tendencia). Cuotas: 1 vencida vigilar, 2+ urgente. - Backend: GET /attention y POST /attention/:attendeeId/resolve; tabla attendee_alert_resolutions (la alerta vuelve si cambia la firma). - Tokens de gravedad para claro y oscuro; se quita el indicador de pills. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
146 lines
5.3 KiB
TypeScript
146 lines
5.3 KiB
TypeScript
import { describe, expect, test } from 'bun:test'
|
|
import type { AttentionMember, StudentAlert } from '@gruperly/shared'
|
|
import { createElement } from 'react'
|
|
import { renderToStaticMarkup } from 'react-dom/server'
|
|
import { AvatarRow } from '../src/features/groups/AvatarRow'
|
|
import {
|
|
avatarRow,
|
|
groupStatus,
|
|
groupsSummary,
|
|
INLINE_SLOTS_MAX,
|
|
membersOf,
|
|
STACKED_FACES,
|
|
} from '../src/features/groups/card'
|
|
|
|
/* La tarjeta del listado no calcula alertas: las recibe de `GET /attention`,
|
|
que corre `computeStudentAlerts` (shared). Acá se prueba cómo se dibujan:
|
|
qué caras van, en qué orden, cuándo se superponen y qué estado se nombra. */
|
|
|
|
const alerta = (gravedad: StudentAlert['gravedad'], peso = 2): StudentAlert => ({
|
|
tipo: 'asistencia',
|
|
gravedad,
|
|
etiqueta: `${peso} faltas`,
|
|
detalle: '',
|
|
firma: 'ses_1',
|
|
peso,
|
|
})
|
|
|
|
const miembro = (id: string, alerts: StudentAlert[] = []): AttentionMember => ({
|
|
attendeeId: id,
|
|
fullName: `Alumno ${id}`,
|
|
phone: null,
|
|
whatsappPhone: null,
|
|
alerts,
|
|
overduePayments: [],
|
|
})
|
|
|
|
const miembros = (count: number) => Array.from({ length: count }, (_, index) => miembro(`m${index + 1}`))
|
|
|
|
describe('avatarRow', () => {
|
|
test('grupo chico: una cara por alumno y un círculo punteado por lugar libre', () => {
|
|
const row = avatarRow(miembros(1), 4)
|
|
expect(row.stacked).toBe(false)
|
|
expect(row.slots.map((slot) => slot.kind)).toEqual(['member', 'free', 'free', 'free'])
|
|
})
|
|
|
|
test(`hasta ${INLINE_SLOTS_MAX} lugares entra en una línea`, () => {
|
|
expect(avatarRow(miembros(2), INLINE_SLOTS_MAX).stacked).toBe(false)
|
|
expect(avatarRow(miembros(2), INLINE_SLOTS_MAX + 1).stacked).toBe(true)
|
|
})
|
|
|
|
test('grupo grande: caras superpuestas y un "+N" con el resto', () => {
|
|
const row = avatarRow(miembros(30), 30)
|
|
expect(row.stacked).toBe(true)
|
|
expect(row.slots).toHaveLength(STACKED_FACES + 1)
|
|
expect(row.slots.at(-1)).toEqual({ kind: 'more', count: 30 - STACKED_FACES })
|
|
})
|
|
|
|
test('el "+N" cuenta la ocupación del grupo, no solo los activos', () => {
|
|
// 28 activos con cara, pero 30 lugares ocupados (2 en pausa).
|
|
const row = avatarRow(miembros(28), 30, 30)
|
|
expect(row.slots.at(-1)).toEqual({ kind: 'more', count: 26 })
|
|
})
|
|
|
|
test('un grupo chico completo se superpone sin "+N"', () => {
|
|
const row = avatarRow(miembros(5), 5)
|
|
expect(row.stacked).toBe(true)
|
|
expect(row.slots.map((slot) => slot.kind)).toEqual(['member', 'member', 'member', 'member', 'member'])
|
|
})
|
|
|
|
test('los alumnos con alerta van primero, el más grave adelante, con su gravedad', () => {
|
|
const row = avatarRow(
|
|
[miembro('ok-1'), miembro('vig', [alerta('vigilar')]), miembro('ok-2'), miembro('urg', [alerta('urgente', 3)])],
|
|
30,
|
|
)
|
|
const caras = row.slots.flatMap((slot) => (slot.kind === 'member' ? [[slot.member.attendeeId, slot.severity]] : []))
|
|
expect(caras).toEqual([
|
|
['urg', 'urgente'],
|
|
['vig', 'vigilar'],
|
|
['ok-1', null],
|
|
['ok-2', null],
|
|
])
|
|
})
|
|
|
|
test('el render marca los lugares libres y el resto', () => {
|
|
const chico = renderToStaticMarkup(createElement(AvatarRow, { members: miembros(1), capacity: 3, occupied: 1 }))
|
|
expect(chico.match(/border-dashed/g)).toHaveLength(2)
|
|
|
|
const grande = renderToStaticMarkup(createElement(AvatarRow, { members: miembros(30), capacity: 30, occupied: 30 }))
|
|
expect(grande).toContain('+26')
|
|
expect(grande).toContain('-ml-1.5')
|
|
})
|
|
})
|
|
|
|
describe('groupStatus', () => {
|
|
test('con alertas dice cuántos están en riesgo, con el tono de la peor', () => {
|
|
expect(groupStatus([miembro('a', [alerta('vigilar')]), miembro('b')], 4)).toEqual({
|
|
tone: 'vigilar',
|
|
text: '1 en riesgo',
|
|
})
|
|
expect(groupStatus([miembro('a', [alerta('vigilar')]), miembro('b', [alerta('urgente')])], 2)).toEqual({
|
|
tone: 'urgente',
|
|
text: '2 en riesgo',
|
|
})
|
|
})
|
|
|
|
test('sin alertas muestra los lugares libres, y si no hay, "Completo"', () => {
|
|
expect(groupStatus(miembros(1), 4)).toEqual({ tone: 'free', text: '3 libres' })
|
|
expect(groupStatus(miembros(3), 4)).toEqual({ tone: 'free', text: '1 libre' })
|
|
expect(groupStatus(miembros(4), 4)).toEqual({ tone: 'full', text: 'Completo' })
|
|
})
|
|
|
|
test('sin cupo definido y sin alertas no hay estado', () => {
|
|
expect(groupStatus(miembros(3), null)).toBeNull()
|
|
})
|
|
})
|
|
|
|
describe('groupsSummary', () => {
|
|
test('suma grupos, alumnos y lugares libres', () => {
|
|
expect(
|
|
groupsSummary([
|
|
{ attendeesCount: 1, capacity: 4 },
|
|
{ attendeesCount: 1, capacity: 5 },
|
|
{ attendeesCount: 30, capacity: 30 },
|
|
{ attendeesCount: 5, capacity: 5 },
|
|
]),
|
|
).toBe('4 grupos · 37 alumnos · 7 lugares libres')
|
|
})
|
|
|
|
test('singular y grupos sin cupo o sobrecargados', () => {
|
|
expect(groupsSummary([{ attendeesCount: 1, capacity: 2 }])).toBe('1 grupo · 1 alumno · 1 lugar libre')
|
|
expect(
|
|
groupsSummary([
|
|
{ attendeesCount: 3, capacity: null },
|
|
{ attendeesCount: 6, capacity: 5 },
|
|
]),
|
|
).toBe('2 grupos · 9 alumnos · 0 lugares libres')
|
|
})
|
|
})
|
|
|
|
test('membersOf busca el grupo en el resumen de atención', () => {
|
|
const groups = [{ groupId: 'g1', groupName: 'Yoga', capacity: 4, members: miembros(2) }]
|
|
expect(membersOf(groups, 'g1')).toHaveLength(2)
|
|
expect(membersOf(groups, 'g2')).toBeUndefined()
|
|
expect(membersOf(undefined, 'g1')).toBeUndefined()
|
|
})
|