task/improve-ui #8
@@ -192,15 +192,33 @@ function buildSummaryFields(
|
|||||||
now,
|
now,
|
||||||
members: attendees
|
members: attendees
|
||||||
.filter((attendee) => attendee.groupId === group.id)
|
.filter((attendee) => attendee.groupId === group.id)
|
||||||
.map((attendee) => ({
|
.map((attendee) => {
|
||||||
|
const attendeeAttendances = attendanceByAttendee.get(attendee.id) ?? [];
|
||||||
|
// Si el alumno tiene asistencias previas a su fecha de alta en la BD (ej.
|
||||||
|
// creado hoy pero con clases pasadas registradas), su fecha efectiva de
|
||||||
|
// incorporación es la de la primera clase a la que se le tomó asistencia.
|
||||||
|
const earliestAttendance = attendeeAttendances.reduce<Date | null>(
|
||||||
|
(earliest, att) =>
|
||||||
|
!earliest || att.classSession.startsAt < earliest
|
||||||
|
? att.classSession.startsAt
|
||||||
|
: earliest,
|
||||||
|
null,
|
||||||
|
);
|
||||||
|
const enrolledAt =
|
||||||
|
earliestAttendance && earliestAttendance < attendee.createdAt
|
||||||
|
? earliestAttendance
|
||||||
|
: attendee.createdAt;
|
||||||
|
|
||||||
|
return {
|
||||||
attendeeId: attendee.id,
|
attendeeId: attendee.id,
|
||||||
fullName: attendee.fullName,
|
fullName: attendee.fullName,
|
||||||
enrolledAt: attendee.createdAt.toISOString(),
|
enrolledAt: enrolledAt.toISOString(),
|
||||||
sessions: memberSessions(
|
sessions: memberSessions(
|
||||||
sessionsByGroup.get(group.id) ?? [],
|
sessionsByGroup.get(group.id) ?? [],
|
||||||
attendanceByAttendee.get(attendee.id) ?? [],
|
attendeeAttendances,
|
||||||
),
|
),
|
||||||
})),
|
};
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
const urgentes: UrgentMemberSummary[] = resumen.urgentes
|
const urgentes: UrgentMemberSummary[] = resumen.urgentes
|
||||||
|
|||||||
@@ -364,6 +364,30 @@ it('una clase sin registrar después de las faltas las borra: la racha mira hast
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('reconoce asistencias previas a la fecha de alta del alumno como historial válido', async () => {
|
||||||
|
prismaFetchGroupFindMany([group('group-1', 'Natación', 30)]);
|
||||||
|
// El alumno fue creado hoy (offset 0), pero tiene 3 faltas en clases de hace 7, 3 y 1 días.
|
||||||
|
prismaFetchAttendeeFindMany([{ id: 'a-1', groupId: 'group-1', fullName: 'Abril Ortiz', createdAt: at(0) }]);
|
||||||
|
prismaFetchClassSessionFindMany([
|
||||||
|
{ id: 's1', groupId: 'group-1', startsAt: at(1) },
|
||||||
|
{ id: 's2', groupId: 'group-1', startsAt: at(3) },
|
||||||
|
{ id: 's3', groupId: 'group-1', startsAt: at(7) },
|
||||||
|
]);
|
||||||
|
prismaFetchAttendanceFindMany([
|
||||||
|
attendance('a-1', 's1', 'ABSENT', at(1)),
|
||||||
|
attendance('a-1', 's2', 'ABSENT', at(3)),
|
||||||
|
attendance('a-1', 's3', 'ABSENT', at(7)),
|
||||||
|
]);
|
||||||
|
|
||||||
|
const res = await makeApp({ id: userId }).request('/groups-risk/overview');
|
||||||
|
|
||||||
|
expect(res.status).toBe(200);
|
||||||
|
const { items } = (await res.json()) as { items: Record<string, unknown>[] };
|
||||||
|
expect(items[0].riesgoAlto).toBe(1);
|
||||||
|
expect(items[0].riskLevel).toBe('HIGH');
|
||||||
|
expect(items[0].absenceStreakCount).toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
/* El use-case pide `capacity` y el conteo de lista de espera para poder calcular
|
/* El use-case pide `capacity` y el conteo de lista de espera para poder calcular
|
||||||
los lugares libres, y `fullName` + `createdAt` de cada alumno para el resumen
|
los lugares libres, y `fullName` + `createdAt` de cada alumno para el resumen
|
||||||
por nivel. Los fixtures los dan para que los tests viejos no tengan que
|
por nivel. Los fixtures los dan para que los tests viejos no tengan que
|
||||||
|
|||||||
@@ -116,13 +116,13 @@ export function AttendanceCapacityIndicator({
|
|||||||
role="img"
|
role="img"
|
||||||
aria-label={label}
|
aria-label={label}
|
||||||
title={label}
|
title={label}
|
||||||
className={cn('flex h-3.5 min-w-0 flex-1 items-stretch gap-1.5', className)}
|
className={cn('flex h-3.5 min-w-0 items-center gap-1.5', className)}
|
||||||
>
|
>
|
||||||
{Array.from({ length: capacity }, (_, index) => (
|
{Array.from({ length: capacity }, (_, index) => (
|
||||||
<LevelSegment
|
<LevelSegment
|
||||||
key={index}
|
key={index}
|
||||||
level={levelAt(counts, index)}
|
level={levelAt(counts, index)}
|
||||||
className="w-[50px] min-w-0 flex-1 max-w-[50px]"
|
className="h-3.5 w-[50px] shrink-0"
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</span>
|
</span>
|
||||||
|
|||||||
@@ -1,91 +1,95 @@
|
|||||||
import type { GroupListItem, GroupRiskSummary } from '@gruperly/shared'
|
import type { GroupListItem, GroupRiskSummary } from '@gruperly/shared'
|
||||||
import { Link } from '@tanstack/react-router'
|
import { Link } from '@tanstack/react-router'
|
||||||
import { Square } from 'lucide-react'
|
import { TriangleAlert } from 'lucide-react'
|
||||||
import { cn } from '../../lib/utils'
|
import { AttendanceCapacityIndicator } from './AttendanceCapacityIndicator'
|
||||||
import { AttendanceCapacityIndicator, TONE_TEXT } from './AttendanceCapacityIndicator'
|
|
||||||
import {
|
import {
|
||||||
barCapacity,
|
SEGMENTED_CAPACITY_MAX,
|
||||||
capacityCounts,
|
alertTextFromMembers,
|
||||||
isSegmentedCapacity,
|
capacityCountsFromMembers,
|
||||||
occupancyLabel,
|
membersFromGroupAndRisk,
|
||||||
riskTone,
|
type GroupMember,
|
||||||
statusLine,
|
|
||||||
} from './card'
|
} from './card'
|
||||||
|
|
||||||
const CARD_CLASS_NAME =
|
const CARD_CLASS_NAME =
|
||||||
'block rounded-2xl border border-border/80 bg-surface px-7 py-5 transition-[border-color,background-color,transform] duration-150 ease-out hover:border-accent/35 hover:bg-primary-soft/35 focus-visible:ring-2 focus-visible:ring-accent focus-visible:outline-none active:scale-[0.995] active:bg-primary-soft/55'
|
'block rounded-2xl border border-border/80 bg-surface px-7 py-5 shadow-none transition-[border-color,background-color,transform] duration-150 ease-out hover:border-accent/35 hover:bg-primary-soft/35 focus-visible:ring-2 focus-visible:ring-accent focus-visible:outline-none active:scale-[0.995] active:bg-primary-soft/55'
|
||||||
|
|
||||||
/* La tarjeta es un resumen operativo: nombre y cupo ubican al grupo, la barra
|
export type GroupCardProps = {
|
||||||
muestra ocupación y asistencia, y la alerta dice a quién mirar. Toda la
|
id?: string
|
||||||
superficie sigue siendo el enlace a la ficha. */
|
name?: string
|
||||||
|
capacity?: number
|
||||||
|
members?: GroupMember[]
|
||||||
|
group?: GroupListItem
|
||||||
|
risk?: GroupRiskSummary | undefined
|
||||||
|
link?: boolean
|
||||||
|
}
|
||||||
|
|
||||||
export function GroupCard({
|
export function GroupCard({ link = true, ...props }: GroupCardProps) {
|
||||||
group,
|
const linkId = props.id ?? props.group?.id
|
||||||
risk,
|
|
||||||
}: {
|
if (link && linkId) {
|
||||||
group: GroupListItem
|
|
||||||
risk: GroupRiskSummary | undefined
|
|
||||||
}) {
|
|
||||||
return (
|
return (
|
||||||
<Link
|
<Link
|
||||||
to="/groups/$groupId"
|
to="/groups/$groupId"
|
||||||
params={{ groupId: group.id }}
|
params={{ groupId: linkId }}
|
||||||
className={CARD_CLASS_NAME}
|
className={CARD_CLASS_NAME}
|
||||||
>
|
>
|
||||||
<GroupCardContent group={group} risk={risk} />
|
<GroupCardContent {...props} />
|
||||||
</Link>
|
</Link>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function GroupCardContent({
|
return (
|
||||||
group,
|
<div className={CARD_CLASS_NAME}>
|
||||||
risk,
|
<GroupCardContent {...props} />
|
||||||
}: {
|
</div>
|
||||||
group: Pick<GroupListItem, 'name' | 'attendeesCount' | 'capacity'>
|
)
|
||||||
risk: GroupRiskSummary | undefined
|
}
|
||||||
}) {
|
|
||||||
const counts = capacityCounts(group, risk)
|
export function GroupCardContent(props: GroupCardProps) {
|
||||||
const line = statusLine(group, risk)
|
const name = props.name ?? props.group?.name ?? ''
|
||||||
const tone = riskTone(counts)
|
const members =
|
||||||
// Sin cupo declarado la barra mide a la matrícula en vez de a los lugares: no
|
props.members ??
|
||||||
// inventa ningún lugar libre, solo reparte a la gente por nivel.
|
(props.group ? membersFromGroupAndRisk(props.group, props.risk) : [])
|
||||||
const bar = barCapacity(group)
|
const capacity =
|
||||||
const segmented = isSegmentedCapacity(bar)
|
props.capacity ??
|
||||||
|
props.group?.capacity ??
|
||||||
|
props.group?.attendeesCount ??
|
||||||
|
members.length
|
||||||
|
|
||||||
|
const counts = capacityCountsFromMembers(members, capacity)
|
||||||
|
const alertText = alertTextFromMembers(members)
|
||||||
|
const segmented = capacity <= SEGMENTED_CAPACITY_MAX
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<h3 className="min-w-0 text-2xl leading-tight font-semibold tracking-tight text-balance text-primary">
|
<h3 className="min-w-0 text-2xl leading-tight font-semibold tracking-tight text-primary">
|
||||||
{group.name}
|
{name}
|
||||||
</h3>
|
</h3>
|
||||||
|
|
||||||
<div className="mt-5 flex min-w-0 items-center gap-3">
|
<div className="mt-5 flex min-w-0 items-center gap-3">
|
||||||
{bar > 0 ? (
|
|
||||||
<AttendanceCapacityIndicator
|
<AttendanceCapacityIndicator
|
||||||
counts={counts}
|
counts={counts}
|
||||||
capacity={bar}
|
capacity={capacity}
|
||||||
segmented={segmented}
|
segmented={segmented}
|
||||||
places={group.capacity !== null}
|
places={true}
|
||||||
/>
|
/>
|
||||||
) : (
|
|
||||||
<span className="min-w-0 flex-1" />
|
|
||||||
)}
|
|
||||||
|
|
||||||
<span className="shrink-0 whitespace-nowrap text-lg tabular-nums text-secondary">
|
<span className="shrink-0 whitespace-nowrap text-lg tabular-nums text-secondary">
|
||||||
{occupancyLabel(group)}
|
{members.length}/{capacity} {capacity === 1 ? 'miembro' : 'miembros'}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{tone !== 'ok' && line.text ? (
|
{alertText ? (
|
||||||
<p
|
<p className="mt-3 flex min-w-0 items-center gap-2.5 text-base leading-6 font-medium text-[#8B1A1A] dark:text-[#f87171]">
|
||||||
className={cn(
|
<TriangleAlert
|
||||||
'mt-3 flex min-w-0 items-center gap-2.5 text-base leading-6 font-medium',
|
className="size-4 shrink-0 text-[#8B1A1A] dark:text-[#f87171]"
|
||||||
TONE_TEXT[tone],
|
strokeWidth={2}
|
||||||
)}
|
aria-hidden="true"
|
||||||
>
|
/>
|
||||||
<Square className="size-4 shrink-0" strokeWidth={2} aria-hidden="true" />
|
<span className="min-w-0">{alertText}</span>
|
||||||
<span className="min-w-0">{line.text}</span>
|
|
||||||
</p>
|
</p>
|
||||||
) : null}
|
) : null}
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
import { useQuery } from '@tanstack/react-query'
|
import { useQuery } from '@tanstack/react-query'
|
||||||
import { useNavigate } from '@tanstack/react-router'
|
import { useNavigate } from '@tanstack/react-router'
|
||||||
import { CalendarPlus, Loader2, Plus } from 'lucide-react'
|
import { CalendarPlus, Loader2, Plus } from 'lucide-react'
|
||||||
|
import { useState } from 'react'
|
||||||
import { Button } from '../../components/ui'
|
import { Button } from '../../components/ui'
|
||||||
import { getGroups, getGroupsRiskOverview } from '../../lib/api'
|
import { getGroups, getGroupsRiskOverview } from '../../lib/api'
|
||||||
import { GroupCard } from './GroupCard'
|
import { GroupCard } from './GroupCard'
|
||||||
|
import { MOCK_TEST_CASES } from './card'
|
||||||
|
|
||||||
export function GroupsView() {
|
export function GroupsView() {
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
@@ -16,17 +18,34 @@ export function GroupsView() {
|
|||||||
queryFn: getGroupsRiskOverview,
|
queryFn: getGroupsRiskOverview,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const [showExamples, setShowExamples] = useState(() => {
|
||||||
|
if (typeof window !== 'undefined') {
|
||||||
|
return new URLSearchParams(window.location.search).get('mock') === 'true'
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
})
|
||||||
|
|
||||||
const riskByGroup = new Map(
|
const riskByGroup = new Map(
|
||||||
(riskQuery.data?.items ?? []).map((item) => [item.groupId, item]),
|
(riskQuery.data?.items ?? []).map((item) => [item.groupId, item]),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const hasGroups = groupsQuery.isSuccess && groupsQuery.data.data.length > 0
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<section>
|
<section>
|
||||||
<div className="flex items-center justify-between gap-3">
|
<div className="flex items-center justify-between gap-3">
|
||||||
<h1 className="text-2xl font-bold text-primary">Grupos</h1>
|
<h1 className="text-2xl font-bold text-primary">Grupos</h1>
|
||||||
{/* `h-11` arriba del `md` del primitivo: son 40px y el mínimo táctil es
|
<div className="flex items-center gap-2">
|
||||||
44. Se sube acá y no en `Button` porque cambiar la altura del
|
{!hasGroups && groupsQuery.isSuccess ? (
|
||||||
primitivo mueve todas las pantallas de la app de un golpe. */}
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
className="h-11"
|
||||||
|
onClick={() => setShowExamples((prev) => !prev)}
|
||||||
|
>
|
||||||
|
{showExamples ? 'Ocultar ejemplos' : 'Ver ejemplos'}
|
||||||
|
</Button>
|
||||||
|
) : null}
|
||||||
<Button
|
<Button
|
||||||
variant="primary"
|
variant="primary"
|
||||||
className="h-11"
|
className="h-11"
|
||||||
@@ -36,6 +55,7 @@ export function GroupsView() {
|
|||||||
Nuevo grupo
|
Nuevo grupo
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
{groupsQuery.isPending ? (
|
{groupsQuery.isPending ? (
|
||||||
<div className="mt-8 flex items-center justify-center py-16" role="status">
|
<div className="mt-8 flex items-center justify-center py-16" role="status">
|
||||||
@@ -53,7 +73,15 @@ export function GroupsView() {
|
|||||||
</div>
|
</div>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
{groupsQuery.isSuccess && groupsQuery.data.data.length === 0 ? (
|
{showExamples ? (
|
||||||
|
<div className="mt-6 grid gap-4">
|
||||||
|
{MOCK_TEST_CASES.map((group) => (
|
||||||
|
<GroupCard key={group.id} {...group} />
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
{groupsQuery.isSuccess && groupsQuery.data.data.length === 0 && !showExamples ? (
|
||||||
/* Un ícono solo, con un punto focal, y el texto en secundario: la
|
/* Un ícono solo, con un punto focal, y el texto en secundario: la
|
||||||
pantalla vacía compite con la acción y no puede ganar. */
|
pantalla vacía compite con la acción y no puede ganar. */
|
||||||
<div className="mt-8 rounded-xl bg-primary-soft px-5 py-12 text-center">
|
<div className="mt-8 rounded-xl bg-primary-soft px-5 py-12 text-center">
|
||||||
@@ -64,18 +92,27 @@ export function GroupsView() {
|
|||||||
<p className="mx-auto mt-1.5 max-w-[30ch] text-sm leading-relaxed text-secondary">
|
<p className="mx-auto mt-1.5 max-w-[30ch] text-sm leading-relaxed text-secondary">
|
||||||
Creá tu primer grupo y empezá a cobrar las cuotas de tus alumnos.
|
Creá tu primer grupo y empezá a cobrar las cuotas de tus alumnos.
|
||||||
</p>
|
</p>
|
||||||
|
<div className="mt-6 flex items-center justify-center gap-3">
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
className="h-11"
|
||||||
|
onClick={() => setShowExamples(true)}
|
||||||
|
>
|
||||||
|
Ver tarjetas de ejemplo
|
||||||
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
variant="primary"
|
variant="primary"
|
||||||
className="mt-6 h-11"
|
className="h-11"
|
||||||
onClick={() => void navigate({ to: '/groups/new' })}
|
onClick={() => void navigate({ to: '/groups/new' })}
|
||||||
>
|
>
|
||||||
<Plus className="size-4" />
|
<Plus className="size-4" />
|
||||||
Crear primer grupo
|
Crear primer grupo
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
{groupsQuery.isSuccess && groupsQuery.data.data.length > 0 ? (
|
{hasGroups && !showExamples ? (
|
||||||
<div className="mt-6 grid gap-4">
|
<div className="mt-6 grid gap-4">
|
||||||
{groupsQuery.data.data.map((group) => (
|
{groupsQuery.data.data.map((group) => (
|
||||||
<GroupCard
|
<GroupCard
|
||||||
@@ -89,3 +126,4 @@ export function GroupsView() {
|
|||||||
</section>
|
</section>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,15 @@ export type GroupLike = Pick<GroupListItem, 'attendeesCount' | 'capacity'>
|
|||||||
* proporcionales. */
|
* proporcionales. */
|
||||||
export const SEGMENTED_CAPACITY_MAX = 10
|
export const SEGMENTED_CAPACITY_MAX = 10
|
||||||
|
|
||||||
|
export type MemberStatus = 'high_risk' | 'attention' | 'ok'
|
||||||
|
|
||||||
|
export type GroupMember = {
|
||||||
|
id: string
|
||||||
|
name: string
|
||||||
|
status: MemberStatus
|
||||||
|
absences: number
|
||||||
|
}
|
||||||
|
|
||||||
export type CapacityCounts = {
|
export type CapacityCounts = {
|
||||||
riesgoAlto: number
|
riesgoAlto: number
|
||||||
atencion: number
|
atencion: number
|
||||||
@@ -24,6 +33,128 @@ export type CapacityCounts = {
|
|||||||
libres: number
|
libres: number
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Conteos derivados directamente de una lista de miembros y el cupo.
|
||||||
|
*/
|
||||||
|
export function capacityCountsFromMembers(
|
||||||
|
members: GroupMember[],
|
||||||
|
capacity: number,
|
||||||
|
): CapacityCounts {
|
||||||
|
let riesgoAlto = 0
|
||||||
|
let atencion = 0
|
||||||
|
let ok = 0
|
||||||
|
|
||||||
|
for (const m of members) {
|
||||||
|
if (m.status === 'high_risk') riesgoAlto++
|
||||||
|
else if (m.status === 'attention') atencion++
|
||||||
|
else ok++
|
||||||
|
}
|
||||||
|
|
||||||
|
const libres = Math.max(capacity - members.length, 0)
|
||||||
|
|
||||||
|
return {
|
||||||
|
riesgoAlto,
|
||||||
|
atencion,
|
||||||
|
ok,
|
||||||
|
libres,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reglas de texto de alerta a partir de los miembros:
|
||||||
|
* - 1 en riesgo alto: "{Nombre}: {N} faltas" + (si hay atención > 0) " · {K} en atención"
|
||||||
|
* - 2 o más en riesgo alto: "{N} en riesgo alto" + (si hay atención > 0) " · {K} en atención"
|
||||||
|
* - 0 en riesgo alto pero atención > 0: "{K} en atención"
|
||||||
|
* - Ninguno: null
|
||||||
|
*/
|
||||||
|
export function alertTextFromMembers(members: GroupMember[]): string | null {
|
||||||
|
const highRisk = members.filter((m) => m.status === 'high_risk')
|
||||||
|
const attention = members.filter((m) => m.status === 'attention')
|
||||||
|
|
||||||
|
const kAtencion = attention.length > 0 ? ` · ${attention.length} en atención` : ''
|
||||||
|
|
||||||
|
if (highRisk.length === 1) {
|
||||||
|
const first = highRisk[0]
|
||||||
|
const nombre = firstName(first.name)
|
||||||
|
const faltas = `${first.absences} ${first.absences === 1 ? 'falta' : 'faltas'}`
|
||||||
|
return `${nombre}: ${faltas}${kAtencion}`
|
||||||
|
}
|
||||||
|
|
||||||
|
if (highRisk.length >= 2) {
|
||||||
|
return `${highRisk.length} en riesgo alto${kAtencion}`
|
||||||
|
}
|
||||||
|
|
||||||
|
if (attention.length > 0) {
|
||||||
|
return `${attention.length} en atención`
|
||||||
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convierte un GroupListItem y GroupRiskSummary en una lista de GroupMember
|
||||||
|
* para unificar la representación interna.
|
||||||
|
*/
|
||||||
|
export function membersFromGroupAndRisk(
|
||||||
|
group: Pick<GroupListItem, 'attendeesCount' | 'capacity'>,
|
||||||
|
risk: GroupRiskSummary | undefined,
|
||||||
|
): GroupMember[] {
|
||||||
|
const members: GroupMember[] = []
|
||||||
|
const urgentes = risk?.urgentes ?? []
|
||||||
|
|
||||||
|
for (const u of urgentes) {
|
||||||
|
if (u.level === 'riesgo_alto') {
|
||||||
|
members.push({
|
||||||
|
id: u.attendeeId,
|
||||||
|
name: u.fullName,
|
||||||
|
status: 'high_risk',
|
||||||
|
absences: u.consecutiveAbsences,
|
||||||
|
})
|
||||||
|
} else if (u.level === 'atencion') {
|
||||||
|
members.push({
|
||||||
|
id: u.attendeeId,
|
||||||
|
name: u.fullName,
|
||||||
|
status: 'attention',
|
||||||
|
absences: u.consecutiveAbsences,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const currentHigh = members.filter((m) => m.status === 'high_risk').length
|
||||||
|
const remainingHigh = Math.max((risk?.riesgoAlto ?? 0) - currentHigh, 0)
|
||||||
|
for (let i = 0; i < remainingHigh; i++) {
|
||||||
|
members.push({
|
||||||
|
id: `high-risk-extra-${i}`,
|
||||||
|
name: `Alumno ${members.length + 1}`,
|
||||||
|
status: 'high_risk',
|
||||||
|
absences: 1,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const currentAttention = members.filter((m) => m.status === 'attention').length
|
||||||
|
const remainingAttention = Math.max((risk?.atencion ?? 0) - currentAttention, 0)
|
||||||
|
for (let i = 0; i < remainingAttention; i++) {
|
||||||
|
members.push({
|
||||||
|
id: `attention-extra-${i}`,
|
||||||
|
name: `Alumno ${members.length + 1}`,
|
||||||
|
status: 'attention',
|
||||||
|
absences: 0,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const remainingOk = Math.max(group.attendeesCount - members.length, 0)
|
||||||
|
for (let i = 0; i < remainingOk; i++) {
|
||||||
|
members.push({
|
||||||
|
id: `ok-${i}`,
|
||||||
|
name: `Alumno ${members.length + 1}`,
|
||||||
|
status: 'ok',
|
||||||
|
absences: 0,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return members
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Conteos que consume el indicador de cupo y asistencia.
|
* Conteos que consume el indicador de cupo y asistencia.
|
||||||
*
|
*
|
||||||
@@ -154,3 +285,57 @@ function firstName(fullName: string): string {
|
|||||||
function membersLabel(count: number): string {
|
function membersLabel(count: number): string {
|
||||||
return count === 1 ? '1 miembro' : `${count} miembros`
|
return count === 1 ? '1 miembro' : `${count} miembros`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Casos de prueba solicitados para verificación contra la imagen de referencia.
|
||||||
|
*/
|
||||||
|
export const MOCK_TEST_CASES = [
|
||||||
|
{
|
||||||
|
id: 'mock-tai-chi',
|
||||||
|
name: 'Tai Chi Martes',
|
||||||
|
capacity: 5,
|
||||||
|
members: [
|
||||||
|
{ id: 'tc-1', name: 'Sofía Ramírez', status: 'high_risk' as const, absences: 4 },
|
||||||
|
{ id: 'tc-2', name: 'Lucas Rossi', status: 'attention' as const, absences: 1 },
|
||||||
|
{ id: 'tc-3', name: 'Martín Paz', status: 'ok' as const, absences: 0 },
|
||||||
|
{ id: 'tc-4', name: 'Elena Gómez', status: 'ok' as const, absences: 0 },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'mock-pilates',
|
||||||
|
name: 'Pilates Sábado',
|
||||||
|
capacity: 15,
|
||||||
|
members: [
|
||||||
|
{ id: 'p-1', name: 'Sofía Ramírez', status: 'high_risk' as const, absences: 4 },
|
||||||
|
{ id: 'p-2', name: 'Lucas Rossi', status: 'attention' as const, absences: 1 },
|
||||||
|
{ id: 'p-3', name: 'Mateo Díaz', status: 'attention' as const, absences: 1 },
|
||||||
|
...Array.from({ length: 9 }, (_, i) => ({
|
||||||
|
id: `p-ok-${i}`,
|
||||||
|
name: `Alumno ${i + 1}`,
|
||||||
|
status: 'ok' as const,
|
||||||
|
absences: 0,
|
||||||
|
})),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'mock-natacion',
|
||||||
|
name: 'Natación Adultos',
|
||||||
|
capacity: 30,
|
||||||
|
members: [
|
||||||
|
{ id: 'n-1', name: 'Alumno 1', status: 'high_risk' as const, absences: 3 },
|
||||||
|
{ id: 'n-2', name: 'Alumno 2', status: 'high_risk' as const, absences: 2 },
|
||||||
|
{ id: 'n-3', name: 'Alumno 3', status: 'high_risk' as const, absences: 4 },
|
||||||
|
{ id: 'n-4', name: 'Alumno 4', status: 'attention' as const, absences: 1 },
|
||||||
|
{ id: 'n-5', name: 'Alumno 5', status: 'attention' as const, absences: 1 },
|
||||||
|
{ id: 'n-6', name: 'Alumno 6', status: 'attention' as const, absences: 2 },
|
||||||
|
{ id: 'n-7', name: 'Alumno 7', status: 'attention' as const, absences: 1 },
|
||||||
|
...Array.from({ length: 15 }, (_, i) => ({
|
||||||
|
id: `n-ok-${i}`,
|
||||||
|
name: `Alumno ${i + 8}`,
|
||||||
|
status: 'ok' as const,
|
||||||
|
absences: 0,
|
||||||
|
})),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -3,18 +3,23 @@ import type { GroupRiskSummary, UrgentMemberSummary } from '@gruperly/shared'
|
|||||||
import { createElement } from 'react'
|
import { createElement } from 'react'
|
||||||
import { renderToStaticMarkup } from 'react-dom/server'
|
import { renderToStaticMarkup } from 'react-dom/server'
|
||||||
import {
|
import {
|
||||||
|
alertTextFromMembers,
|
||||||
barCapacity,
|
barCapacity,
|
||||||
capacityCounts,
|
capacityCounts,
|
||||||
|
capacityCountsFromMembers,
|
||||||
isSegmentedCapacity,
|
isSegmentedCapacity,
|
||||||
|
MOCK_TEST_CASES,
|
||||||
occupancyLabel,
|
occupancyLabel,
|
||||||
riskTone,
|
riskTone,
|
||||||
|
SEGMENTED_CAPACITY_MAX,
|
||||||
statusLine,
|
statusLine,
|
||||||
|
type GroupMember,
|
||||||
} from '../src/features/groups/card'
|
} from '../src/features/groups/card'
|
||||||
import {
|
import {
|
||||||
capacityIndicatorLabel,
|
capacityIndicatorLabel,
|
||||||
capacitySegmentWidth,
|
capacitySegmentWidth,
|
||||||
} from '../src/features/groups/AttendanceCapacityIndicator'
|
} 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
|
/* 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
|
`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 })
|
const grupo = (attendeesCount: number, capacity: number | null) => ({ attendeesCount, capacity })
|
||||||
|
|
||||||
describe('GroupCardContent', () => {
|
describe('GroupCard - Casos de prueba de referencia', () => {
|
||||||
test('no muestra un segundo label de lugares junto al nombre', () => {
|
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(
|
const markup = renderToStaticMarkup(
|
||||||
createElement(GroupCardContent, {
|
createElement(GroupCard, {
|
||||||
group: { name: 'Tai Chi Martes', attendeesCount: 4, capacity: 5 },
|
name: 'Yoga Tranquilo',
|
||||||
risk: risk(1, 1, {
|
capacity: 10,
|
||||||
urgentes: [urgente({ fullName: 'Sofía Ramírez', consecutiveAbsences: 4 })],
|
members,
|
||||||
}),
|
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
expect(markup).not.toContain('text-[#8B1A1A]')
|
||||||
expect(markup).not.toContain('hasta 10 lugares')
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user