- 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>
168 lines
5.5 KiB
TypeScript
168 lines
5.5 KiB
TypeScript
import { describe, expect, test } from 'bun:test'
|
|
import type { AttentionMember, AttentionOverview, StudentAlert } from '@gruperly/shared'
|
|
import { createElement } from 'react'
|
|
import { renderToStaticMarkup } from 'react-dom/server'
|
|
import {
|
|
attentionItems,
|
|
attentionSubtitle,
|
|
filterCounts,
|
|
filterItems,
|
|
flaggedStudents,
|
|
itemsBySeverity,
|
|
reminderMessage,
|
|
whatsappLink,
|
|
withoutAlert,
|
|
} from '../src/features/attention/attention'
|
|
import { FilterChips } from '../src/features/attention/FilterChips'
|
|
|
|
/* "Requiere atención" recibe las alertas calculadas: acá se prueba cómo se
|
|
aplanan en tarjetas, se cuentan por filtro y gravedad, y qué mensaje sale. */
|
|
|
|
const alerta = (tipo: StudentAlert['tipo'], gravedad: StudentAlert['gravedad'], peso = 2): StudentAlert => ({
|
|
tipo,
|
|
gravedad,
|
|
etiqueta: tipo === 'pago' ? 'Cuota vencida' : `${peso} faltas`,
|
|
detalle: '',
|
|
firma: `${tipo}-firma`,
|
|
peso,
|
|
})
|
|
|
|
const miembro = (id: string, fullName: string, alerts: StudentAlert[], extra: Partial<AttentionMember> = {}) => ({
|
|
attendeeId: id,
|
|
fullName,
|
|
phone: '11 5555-0000',
|
|
whatsappPhone: '+5491155550000',
|
|
alerts,
|
|
overduePayments: [],
|
|
...extra,
|
|
})
|
|
|
|
const overview: AttentionOverview = {
|
|
groups: [
|
|
{
|
|
groupId: 'g1',
|
|
groupName: 'Natación',
|
|
capacity: 30,
|
|
members: [
|
|
miembro('a1', 'Agustina', [alerta('asistencia', 'urgente', 4)]),
|
|
miembro('a2', 'Bruno', [alerta('pago', 'vigilar', 1)]),
|
|
miembro('a3', 'Felipe', []),
|
|
// Dos alertas: aparece en dos tarjetas, pero cuenta como un alumno.
|
|
miembro('a4', 'Valentina', [alerta('pago', 'urgente', 2), alerta('asistencia', 'vigilar')]),
|
|
],
|
|
},
|
|
{
|
|
groupId: 'g2',
|
|
groupName: 'Tai Chi Martes',
|
|
capacity: 4,
|
|
members: [miembro('b1', 'Martina', [alerta('asistencia', 'vigilar')])],
|
|
},
|
|
],
|
|
}
|
|
|
|
describe('flaggedStudents', () => {
|
|
test('solo los alumnos con alerta, el más urgente primero, con su peor alerta', () => {
|
|
const students = flaggedStudents(overview)
|
|
expect(students.map((student) => [student.fullName, student.worst.gravedad])).toEqual([
|
|
['Agustina', 'urgente'],
|
|
['Valentina', 'urgente'],
|
|
['Martina', 'vigilar'],
|
|
['Bruno', 'vigilar'],
|
|
])
|
|
expect(students[2].groupName).toBe('Tai Chi Martes')
|
|
})
|
|
|
|
test('sin datos no hay alumnos', () => {
|
|
expect(flaggedStudents(undefined)).toEqual([])
|
|
})
|
|
})
|
|
|
|
describe('tarjetas, filtros y contadores', () => {
|
|
const items = attentionItems(flaggedStudents(overview))
|
|
|
|
test('una tarjeta por alerta, urgentes primero', () => {
|
|
expect(items.map((item) => `${item.student.fullName}:${item.alert.tipo}`)).toEqual([
|
|
'Agustina:asistencia',
|
|
'Valentina:pago',
|
|
'Martina:asistencia',
|
|
'Valentina:asistencia',
|
|
'Bruno:pago',
|
|
])
|
|
})
|
|
|
|
test('cuenta por filtro', () => {
|
|
expect(filterCounts(items)).toEqual({ todos: 5, asistencia: 3, pago: 2 })
|
|
expect(filterItems(items, 'pago').map((item) => item.student.fullName)).toEqual(['Valentina', 'Bruno'])
|
|
})
|
|
|
|
test('separa por gravedad', () => {
|
|
const { urgente, vigilar } = itemsBySeverity(items)
|
|
expect(urgente).toHaveLength(2)
|
|
expect(vigilar).toHaveLength(3)
|
|
})
|
|
|
|
test('el subtítulo cuenta alumnos, no tarjetas', () => {
|
|
expect(attentionSubtitle(items)).toBe('4 alumnos · 2 urgentes')
|
|
expect(attentionSubtitle(filterItems(items, 'asistencia').slice(2))).toBe('1 alumno')
|
|
expect(attentionSubtitle([])).toBe('Nada pendiente')
|
|
})
|
|
|
|
test('"Resuelto" saca solo esa alerta del caché', () => {
|
|
const next = withoutAlert(overview, 'a4', 'pago')
|
|
const valentina = next.groups[0].members.find((member) => member.attendeeId === 'a4')
|
|
expect(valentina?.alerts.map((alert) => alert.tipo)).toEqual(['asistencia'])
|
|
expect(filterCounts(attentionItems(flaggedStudents(next)))).toEqual({ todos: 4, asistencia: 3, pago: 1 })
|
|
})
|
|
})
|
|
|
|
describe('WhatsApp', () => {
|
|
test('arma el link con el E.164 y el texto', () => {
|
|
expect(whatsappLink({ whatsappPhone: '+5491155550000' })).toBe('https://wa.me/5491155550000')
|
|
expect(whatsappLink({ whatsappPhone: '+5491155550000' }, 'Hola')).toBe('https://wa.me/5491155550000?text=Hola')
|
|
expect(whatsappLink({ whatsappPhone: null })).toBeNull()
|
|
})
|
|
|
|
test('el recordatorio nombra la cuota, la fecha y el link de pago', () => {
|
|
const [student] = flaggedStudents({
|
|
groups: [
|
|
{
|
|
groupId: 'g1',
|
|
groupName: 'Natación',
|
|
capacity: 30,
|
|
members: [
|
|
miembro('a1', 'Nicolás Gómez', [alerta('pago', 'vigilar', 1)], {
|
|
overduePayments: [
|
|
{
|
|
id: 'p1',
|
|
amount: 15000,
|
|
currency: 'ARS',
|
|
dueDate: '2026-10-10T12:00:00.000Z',
|
|
checkoutUrl: 'https://mpago.la/abc',
|
|
},
|
|
],
|
|
}),
|
|
],
|
|
},
|
|
],
|
|
})
|
|
const message = reminderMessage(student)
|
|
expect(message).toStartWith('¡Hola Nicolás!')
|
|
expect(message).toContain('la cuota de Natación')
|
|
expect(message).toContain('venció el 10/10')
|
|
expect(message).toContain('https://mpago.la/abc')
|
|
})
|
|
})
|
|
|
|
test('los chips marcan el activo con aria-pressed y muestran su contador', () => {
|
|
const markup = renderToStaticMarkup(
|
|
createElement(FilterChips, {
|
|
value: 'asistencia',
|
|
counts: { todos: 7, asistencia: 4, pago: 3 },
|
|
onChange: () => undefined,
|
|
}),
|
|
)
|
|
expect(markup.match(/aria-pressed="true"/g)).toHaveLength(1)
|
|
expect(markup).toMatch(/aria-pressed="true"[^>]*>Asistencia/)
|
|
expect(markup).toContain('>7<')
|
|
})
|