Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions components/DieD16.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,14 @@ describe("DieD16 — tamaño, interacción y accesibilidad", () => {
expect(onRoll).toHaveBeenCalledTimes(1);
});

// T34: los call sites fijan nombres exactos («Tirar 1D16») — pin de accesibilidad preservado.
it("rollLabel pone el texto EXACTO del botón de tirar", () => {
const onRoll = vi.fn();
render(<DieD16 value={null} onRoll={onRoll} rollLabel="Tirar 1D16" />);
fireEvent.click(screen.getByRole("button", { name: "Tirar 1D16" }));
expect(onRoll).toHaveBeenCalledTimes(1);
});

it("el botón queda deshabilitado mientras rolling", () => {
render(<DieD16 value={1} rolling onRoll={() => {}} />);
const btn = must(screen.getByRole("button", { name: "Tirar" }) as HTMLButtonElement | null);
Expand Down
6 changes: 5 additions & 1 deletion components/DieD16.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ export interface DieD16Props {
label?: string;
/** Spanish result text; defaults to «Resultado: n». */
resultText?: (n: number) => string;
/** Spanish roll-button label; defaults to «Tirar». T34: migrated call sites
* pin exact button names («Tirar 1D6»…) — this text renders verbatim. */
rollLabel?: string;
}

/** Scaled jico skew (L112 judgment call kept: -8/12 vs the d6's -16/24). */
Expand Down Expand Up @@ -105,6 +108,7 @@ export function DieD16({
size = 120,
label = "Dado 1D16",
resultText = (n) => `Resultado: ${n}`,
rollLabel = "Tirar",
}: DieD16Props) {
const [roll, setRoll] = useState<RollState>(() => ({
prev: value,
Expand Down Expand Up @@ -200,7 +204,7 @@ export function DieD16({
</p>
{onRoll && (
<button type="button" className={styles.btn} onClick={onRoll} disabled={rolling}>
Tirar
{rollLabel}
</button>
)}
</div>
Expand Down
8 changes: 8 additions & 0 deletions components/DieD6.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,14 @@ describe("DieD6 — tamaño, interacción y accesibilidad", () => {
expect(onRoll).toHaveBeenCalledTimes(1);
});

// T34: los call sites fijan nombres exactos («Tirar 1D6») — pin de accesibilidad preservado.
it("rollLabel pone el texto EXACTO del botón de tirar", () => {
const onRoll = vi.fn();
render(<DieD6 value={null} onRoll={onRoll} rollLabel="Tirar 1D6" />);
fireEvent.click(screen.getByRole("button", { name: "Tirar 1D6" }));
expect(onRoll).toHaveBeenCalledTimes(1);
});

it("el botón queda deshabilitado mientras rolling", () => {
render(<DieD6 value={1} rolling onRoll={() => {}} />);
const btn = must(screen.getByRole("button", { name: "Tirar" }) as HTMLButtonElement | null);
Expand Down
6 changes: 5 additions & 1 deletion components/DieD6.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ export interface DieD6Props {
label?: string;
/** Spanish result text; defaults to «Resultado: n». */
resultText?: (n: number) => string;
/** Spanish roll-button label; defaults to «Tirar». T34: migrated call sites
* pin exact button names («Tirar 1D6»…) — this text renders verbatim. */
rollLabel?: string;
}

/** Jico skewed landing (approved v3): never face-on. */
Expand Down Expand Up @@ -112,6 +115,7 @@ export function DieD6({
size = 120,
label = "Dado 1D6",
resultText = (n) => `Resultado: ${n}`,
rollLabel = "Tirar",
}: DieD6Props) {
const [roll, setRoll] = useState<RollState>(() => ({
prev: value,
Expand Down Expand Up @@ -202,7 +206,7 @@ export function DieD6({
</p>
{onRoll && (
<button type="button" className={styles.btn} onClick={onRoll} disabled={rolling}>
Tirar
{rollLabel}
</button>
)}
</div>
Expand Down
12 changes: 12 additions & 0 deletions features/leagues/actaKickoffGate.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -331,3 +331,15 @@ describe("U12 · L32 — manual or automatic 2D6, per-coach duel, optional skip"
).toBeNull();
});
});

describe("ActaKickoffGate — T34 · migración del dado del duelo a DieD6", () => {
// WHY (T34, L121): the duel dice (one 1D6 per coach) migrate to the shared
// DieD6 (highlight default "none") keeping their pinned button names via
// the component's rollLabel prop.

it("los dos dados 1D6 del duelo se renderizan con el componente DieD6 (TÚ y RIVAL)", () => {
gate({ d1: 1, d2: 5, followUp: { home: null, away: null } });
expect(screen.getByRole("img", { name: /Dado 1D6 · TÚ/ })).toBeTruthy();
expect(screen.getByRole("img", { name: /Dado 1D6 · RIVAL/ })).toBeTruthy();
});
});
44 changes: 22 additions & 22 deletions features/leagues/actaKickoffGate.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { useState } from "react";

import { DieD6 } from "@/components/DieD6";

import {
KICKOFF_EVENTS,
KICKOFF_FREE_RECEPTION_QUOTE,
Expand Down Expand Up @@ -63,7 +65,10 @@ export interface ActaKickoffGateProps {
onSkipDuel: () => void;
}

/** Editorial die card (the wizard's DieCard pattern): face + dice BUTTON. */
/** Editorial die card (the wizard's DieCard pattern): face + dice BUTTON.
* T34 (L121): the face is the shared DieD6 (highlight default "none"); its
* roll button carries the pinned «Tirar 1D6 · TÚ/RIVAL» names via rollLabel
* and the trigger is withheld once recorded (U12's one-shot roll). */
function GateDie({
label,
value,
Expand All @@ -84,27 +89,22 @@ function GateDie({
<p className="w-full font-display text-xs font-bold uppercase tracking-wide text-navy">
{label}
</p>
<span
key={`glyph-${rollSeq}`}
aria-hidden
data-testid="die-glyph"
className={`flex h-10 w-10 items-center justify-center border border-navy/30 bg-white font-display text-lg font-bold text-navy${
rolled ? " dice-roll" : ""
}`}
>
{value ?? "–"}
</span>
<button
type="button"
className={BTN}
disabled={recorded}
onClick={() => {
setRollSeq((seq) => seq + 1);
onRoll();
}}
>
{dieLabel}
</button>
{/* Controlled wiring (T34): the RNG/state stay with the gate and feed
`value`; no trigger after the recorded throw (the die locks). */}
<DieD6
value={value}
size={40}
label={`Dado 1D6 · ${label}`}
rollLabel={dieLabel}
onRoll={
recorded
? undefined
: () => {
setRollSeq((seq) => seq + 1);
onRoll();
}
}
/>
<span
key={`status-${rollSeq}`}
role="status"
Expand Down
58 changes: 58 additions & 0 deletions features/leagues/actaPreMatchWizard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1085,3 +1085,61 @@ describe("ActaPreMatchSection — T28 · the granted blessings on the pre-match
).not.toContain("Plegarias");
});
});

describe("ActaPreMatchWizard — T34 · migración del dado a los componentes DieD6/DieD16", () => {
// WHY (T34, L121): the die FACE visuals migrate to the shared controlled
// components (PR #423) with highlight defaulting to "none". Per-site pins:
// the component must render with the RIGHT sides (1D6 -> DieD6, 1D16 ->
// DieD16). The Los Hinchas 1D3 glyph is deliberately NOT migrated (a DieD6
// would show 6 pips for a 1D3 result — out of coverage, kept as-is).

it("el paso El Clima muestra la tirada 1D6 con el componente DieD6", () => {
const snapshot = emptySnapshot();
snapshot.fans.home = { base: 4, dice: 1, total: 5 };
renderWizard({ snapshot });
expect(screen.getByRole("img", { name: "Dado 1D6" })).toBeTruthy();
expect(screen.getByRole("button", { name: "Tirar 1D6" })).toBeTruthy();
});

it("el paso Equipo pateador muestra la tirada 1D6 con el componente DieD6", () => {
renderWizard({ snapshot: readySnapshot() });
expect(screen.getByRole("img", { name: "Dado 1D6" })).toBeTruthy();
expect(screen.getByRole("button", { name: "Tirar 1D6" })).toBeTruthy();
});

it("el resultado ACEPTADO de una plegaria se muestra con el componente DieD16", () => {
renderWizard({ snapshot: prayersSnapshot(1) });
const card = within(step(4, "Plegarias a Nuffle")).getByRole("group", {
name: `Plegaria 1 de 1 · ${HOME}`,
});
fireEvent.change(within(card).getByRole("spinbutton"), {
target: { value: "8" },
});
fireEvent.click(within(card).getByRole("button", { name: "Aceptar" }));
expect(within(card).getByRole("img", { name: /Dado 1D16/ })).toBeTruthy();
// The prayer step keeps its manual contract: NO die roll button here.
expect(screen.queryByRole("button", { name: "Tirar 1D16" })).toBeNull();
});

it("TRIANGULA · el paso Los Hinchas (1D3) conserva el glyph plano — fuera de cobertura", () => {
// WHY (T34 boundary): DieD6 shows 6 pips — a 1D3 result on that cube
// would lie about the roll. The 1D3 site is deliberately NOT migrated.
renderWizard();
expect(screen.getByTestId("die-glyph")).toBeTruthy();
expect(screen.queryByRole("img", { name: "Dado 1D6" })).toBeNull();
expect(screen.getByRole("button", { name: "Tirar 1D3" })).toBeTruthy();
});

it("TRIANGULA · tras registrar en un sitio migrado NO queda dispara de re-tirada (lock S7)", () => {
// WHY (T34 contract): on migrated sites the DieD6 trigger is withheld
// once recorded (the component renders its button only with onRoll) —
// «una vez tirado los dados, ya no se puede volver a tirar» (S7.6).
const snapshot = emptySnapshot();
snapshot.fans.home = { base: 4, dice: 1, total: 5 };
const { onCommit } = renderWizard({ snapshot });
fireEvent.click(screen.getByRole("button", { name: "Tirar 1D6" }));
expect(onCommit).toHaveBeenCalledTimes(1);
expect(screen.queryByRole("button", { name: "Tirar 1D6" })).toBeNull();
expect(step(2, "El Clima").textContent).toMatch(/Registrado/);
});
});
91 changes: 62 additions & 29 deletions features/leagues/actaPreMatchWizard.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Fragment, useState, type ReactNode } from "react";

import { DieD6 } from "@/components/DieD6";
import { DieD16 } from "@/components/DieD16";
import { rollD3, rollD6, rollD16 } from "@/lib/random";
import {
displayNameOf,
Expand Down Expand Up @@ -233,11 +235,18 @@ function WeatherTable({ sum }: { sum: number | null }) {

/** Editorial die card: face + dice BUTTON (roll records directly) with the
* roll animation — LOCKED once recorded: a finished roll never re-rolls (the
* only re-roll path is the kick tie's «Repetir tirada»). */
* only re-roll path is the kick tie's «Repetir tirada»).
*
* T34 (L121): the die FACE visual migrates to the shared controlled
* components (PR #423), highlight at its default "none". `sides` decides:
* 6 renders the shared DieD6 (its own roll button carries the pinned
* «Tirar 1D6» name via rollLabel); 3 KEEPS the flat glyph — a DieD6 would
* show 6 pips for a 1D3 result (out of component coverage, kept as-is). */
function DieCard({
teamLabel,
value,
dieLabel,
sides,
recorded,
onRoll,
totalLine,
Expand All @@ -246,6 +255,8 @@ function DieCard({
teamLabel: string;
value: number | null;
dieLabel: string;
/** Roll shape: 3 = flat glyph (kept), 6 = shared DieD6 (T34). */
sides: 3 | 6;
recorded: boolean;
onRoll: () => void;
totalLine: ReactNode;
Expand All @@ -259,27 +270,49 @@ function DieCard({
{teamLabel}
</p>
<div className="mt-2 flex flex-wrap items-center gap-3">
<span
key={`glyph-${rollSeq}`}
aria-hidden="true"
data-testid="die-glyph"
className={`flex h-10 w-10 items-center justify-center border border-navy/30 bg-white font-display text-lg font-bold text-navy${
rolled ? " dice-roll" : ""
}`}
>
{value ?? "–"}
</span>
<button
type="button"
className={BTN}
disabled={recorded}
onClick={() => {
setRollSeq((seq) => seq + 1);
onRoll();
}}
>
{dieLabel}
</button>
{sides === 6 ? (
/* Controlled wiring (T34): the RNG/state stay here and feed the die
* `value`; the roll trigger is withheld once recorded so the S7 lock
* («una vez tirado los dados, ya no se puede volver a tirar») holds
* — no dead re-roll button is offered. */
<DieD6
value={value}
size={40}
rollLabel={dieLabel}
onRoll={
recorded
? undefined
: () => {
setRollSeq((seq) => seq + 1);
onRoll();
}
}
/>
) : (
<>
<span
key={`glyph-${rollSeq}`}
aria-hidden="true"
data-testid="die-glyph"
className={`flex h-10 w-10 items-center justify-center border border-navy/30 bg-white font-display text-lg font-bold text-navy${
rolled ? " dice-roll" : ""
}`}
>
{value ?? "–"}
</span>
<button
type="button"
className={BTN}
disabled={recorded}
onClick={() => {
setRollSeq((seq) => seq + 1);
onRoll();
}}
>
{dieLabel}
</button>
</>
)}
<span
key={`status-${rollSeq}`}
role="status"
Expand Down Expand Up @@ -353,13 +386,10 @@ function PrayerManualCard({
</p>
<div className="mt-2 flex flex-wrap items-center gap-3">
{accepted ? (
<span
aria-hidden="true"
data-testid="die-glyph"
className="flex h-10 w-10 items-center justify-center border border-navy/30 bg-white font-display text-lg font-bold text-navy"
>
{value}
</span>
/* T34 (L121): the recorded 1D16 face is the shared DieD16,
* display-only — the manual entry above already committed the roll
* (no die button rides this step, per T29/L95). */
<DieD16 value={value} size={40} label={`Dado 1D16 · ${label}`} />
) : (
<>
<input
Expand Down Expand Up @@ -932,6 +962,7 @@ export function ActaPreMatchWizard({
teamLabel={`Tu tirada · ${nameOf(viewerSide)}`}
value={shownFan}
dieLabel="Tirar 1D3"
sides={3}
recorded={recordedFan}
onRoll={() => {
const value = dice.d3();
Expand Down Expand Up @@ -966,6 +997,7 @@ export function ActaPreMatchWizard({
teamLabel={`Tu tirada · ${nameOf(viewerSide)}`}
value={shownWeather}
dieLabel="Tirar 1D6"
sides={6}
recorded={recordedWeather}
onRoll={() => {
const value = dice.d6();
Expand Down Expand Up @@ -1297,6 +1329,7 @@ export function ActaPreMatchWizard({
teamLabel={`Tu tirada · ${nameOf(viewerSide)}`}
value={shownKick}
dieLabel="Tirar 1D6"
sides={6}
recorded={recordedKick}
onRoll={() => {
const value = dice.d6();
Expand Down
Loading