Card evento filtrata sui convocati + copertura test per numero di convocati
- La card (Calendario e Home) conta «presenti/convocati» e mostra i pulsanti di presenza solo ai convocati; «Da confermare» in Home esclude gli eventi a cui non si è convocati. - Nuove eConvocato() e rosaConvocata(): il filtro, prima ripetuto in tre punti, è una funzione pura usata da card, «Rosa e presenze» e convocatiEvento. - Test per 0, 1, 2, 3, tutti e id sconosciuti su visibilità, convocazione e solleciti. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8def97731c
commit
5ee148b88b
7 files changed
+103
-12
No files matched your search
@@ -7,7 +7,9 @@ import {
|
||||
convocatiEvento,
|
||||
daCategoria,
|
||||
daRiga,
|
||||
eConvocato,
|
||||
eventoVisibile,
|
||||
rosaConvocata,
|
||||
eventoVuoto,
|
||||
type RigaEvento,
|
||||
} from "@/lib/eventi";
|
||||
@@ -131,3 +133,42 @@ assert.equal(eventoVisibile({ convocati: ["g1"] }, "g2", false), false, "il non
|
||||
assert.equal(eventoVisibile({ convocati: ["g1"] }, null, false), false, "senza slot no");
|
||||
assert.equal(eventoVisibile({ convocati: ["g1"] }, "g2", true), true, "admin/allenatore sempre");
|
||||
assert.equal(eventoVisibile({ convocati: [] }, "g2", false), true, "vuoto = tutta la rosa");
|
||||
|
||||
// --- eConvocato: elenco vuoto = tutti ----------------------------------------
|
||||
assert.equal(eConvocato({ convocati: ["g1"] }, "g1"), true, "convocato");
|
||||
assert.equal(eConvocato({ convocati: ["g1"] }, "g2"), false, "non convocato");
|
||||
assert.equal(eConvocato({ convocati: [] }, "g2"), true, "vuoto = tutti");
|
||||
|
||||
// --- Copertura per numero di convocati: 1, 2, 3, tutti, nessuno, id sconosciuti -
|
||||
const squadra = ["g1", "g2", "g3", "g4"].map((id) => ({ id }));
|
||||
const ids = (l: Array<{ id: string }>) => l.map((g) => g.id);
|
||||
const casi: Array<{ nome: string; convocati: string[]; attesi: string[] }> = [
|
||||
{ nome: "nessuno indicato = tutta la rosa", convocati: [], attesi: ["g1", "g2", "g3", "g4"] },
|
||||
{ nome: "solo 1", convocati: ["g2"], attesi: ["g2"] },
|
||||
{ nome: "2", convocati: ["g1", "g4"], attesi: ["g1", "g4"] },
|
||||
{ nome: "3", convocati: ["g3", "g1", "g2"], attesi: ["g1", "g2", "g3"] },
|
||||
{ nome: "tutti indicati", convocati: ["g1", "g2", "g3", "g4"], attesi: ["g1", "g2", "g3", "g4"] },
|
||||
{ nome: "id sconosciuto ignorato", convocati: ["g2", "zz"], attesi: ["g2"] },
|
||||
{ nome: "solo ids sconosciuti: nessuno", convocati: ["zz"], attesi: [] },
|
||||
];
|
||||
for (const { nome, convocati, attesi } of casi) {
|
||||
assert.deepEqual(ids(rosaConvocata(squadra, convocati)), attesi, `rosaConvocata: ${nome}`);
|
||||
const conv = { convocati };
|
||||
for (const { id } of squadra) {
|
||||
const dentro = attesi.includes(id) || convocati.length === 0;
|
||||
assert.equal(
|
||||
eConvocato(conv, id),
|
||||
convocati.length === 0 || convocati.includes(id),
|
||||
`eConvocato ${id}: ${nome}`,
|
||||
);
|
||||
assert.equal(eventoVisibile(conv, id, false), dentro, `visibile a ${id}: ${nome}`);
|
||||
assert.equal(
|
||||
eventoVisibile(conv, id, true),
|
||||
true,
|
||||
`admin/allenatore vede sempre (${id}): ${nome}`,
|
||||
);
|
||||
}
|
||||
assert.equal(eventoVisibile(conv, null, false), convocati.length === 0, `senza slot: ${nome}`);
|
||||
assert.equal(eventoVisibile(conv, null, true), true, `admin senza slot: ${nome}`);
|
||||
}
|
||||
assert.equal(rosaConvocata([], ["g1"]).length, 0, "rosa vuota resta vuota");
|
||||
@@ -294,3 +294,35 @@ assert.equal(
|
||||
);
|
||||
|
||||
console.log("presenze: ok");
|
||||
|
||||
// --- Solleciti per numero di convocati: 1, 2, 3, tutti ------------------------
|
||||
{
|
||||
const sq = (["g1", "g2", "g3", "g4"] as const).map((id) => ({
|
||||
id,
|
||||
attivo: true,
|
||||
tipo: "giocatore" as const,
|
||||
}));
|
||||
const nessuna: Array<{ giocatore_id: string; stato: string }> = [];
|
||||
assert.deepEqual(destinatariSollecito(sq, nessuna, ["g2"]), ["g2"], "solo 1 convocato");
|
||||
assert.deepEqual(destinatariSollecito(sq, nessuna, ["g1", "g3"]), ["g1", "g3"], "2 convocati");
|
||||
assert.deepEqual(
|
||||
destinatariSollecito(sq, nessuna, ["g1", "g2", "g4"]),
|
||||
["g1", "g2", "g4"],
|
||||
"3 convocati",
|
||||
);
|
||||
assert.deepEqual(
|
||||
destinatariSollecito(sq, [{ giocatore_id: "g1", stato: "presente" }], ["g1", "g3"]),
|
||||
["g3"],
|
||||
"il convocato che ha già risposto non va sollecitato",
|
||||
);
|
||||
assert.deepEqual(
|
||||
destinatariSollecito(sq, [{ giocatore_id: "g4", stato: "presente" }], ["g1"]),
|
||||
["g1"],
|
||||
"chi ha risposto ma non è convocato non cambia i destinatari",
|
||||
);
|
||||
assert.deepEqual(
|
||||
destinatariSollecito(sq, nessuna, []),
|
||||
["g1", "g2", "g3", "g4"],
|
||||
"nessuno = tutti",
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user