From 44dae4e953808f8c1b6e44bc70d5484df7e0960c Mon Sep 17 00:00:00 2001 From: Tilumca Date: Wed, 14 Oct 2026 21:44:11 +0200 Subject: [PATCH] Trening: przyczyna braku mozliwosci dodania serii jako alert-modal (przycisk klikalny, komunikat w oknie z OK) --- app/src/components/ui/dialogs.tsx | 24 ++++++++++++++ app/src/pages/DayExecution.tsx | 52 +++++++++++++++++------------- app/test/DayExecution.test.tsx | 40 +++++++++++++---------- app/test/e2e/day-execution.spec.ts | 10 ++++-- 4 files changed, 83 insertions(+), 43 deletions(-) diff --git a/app/src/components/ui/dialogs.tsx b/app/src/components/ui/dialogs.tsx index 27985ef..203623b 100644 --- a/app/src/components/ui/dialogs.tsx +++ b/app/src/components/ui/dialogs.tsx @@ -100,6 +100,30 @@ export function ConfirmDialog({ ); } +/* Alert — informacyjny modal z jednym przyciskiem (OK); brak akcji po drugiej stronie. */ +export function AlertModal({ + open, + onClose, + title, + message, +}: { + open: boolean; + onClose: () => void; + title: string; + message: string; +}) { + return ( + +

{message}

+
+ +
+
+ ); +} + /* Number pad dialog — mobile-friendly numeric entry (keypad + Wpisz/Anuluj). */ export function NumberPadDialog({ open, diff --git a/app/src/pages/DayExecution.tsx b/app/src/pages/DayExecution.tsx index d358ce1..ded941e 100644 --- a/app/src/pages/DayExecution.tsx +++ b/app/src/pages/DayExecution.tsx @@ -26,6 +26,7 @@ import { Button, Card, ConfirmDialog, + AlertModal, ErrorText, H3, Modal, @@ -272,8 +273,6 @@ function ExerciseAccordion({ expanded, inProgress, nextSetId, - canAddExtra, - addSetHint, onToggle, onRemove, onEditSet, @@ -286,8 +285,6 @@ function ExerciseAccordion({ expanded: boolean; inProgress: boolean; nextSetId: string | null; - canAddExtra: boolean; - addSetHint: string | null; onToggle: () => void; onRemove: () => void; onEditSet: (set: SessionSet, index: number) => void; @@ -370,15 +367,10 @@ function ExerciseAccordion({ ))} {inProgress && ( -
- - {!canAddExtra && addSetHint && ( -

{addSetHint}

- )} -
+ )} )} @@ -435,6 +427,8 @@ export default function DayExecution() { const [busy, setBusy] = useState(false); const [confirmAbandon, setConfirmAbandon] = useState(false); const [addExerciseOpen, setAddExerciseOpen] = useState(false); + // powód zablokowania „Dodaj serię" pokazany w alercie (null = alert zamknięty) + const [addSetAlert, setAddSetAlert] = useState(null); // Seria edytowana w oknie „Uzupełnij serię" (wsadowo: wszystkie pola naraz). // `planned` = wartości wyznaczonej normy (do przycisku „Norma spełniona"), // `restSec` = zaplanowany czas przerwy po serii (do timera). @@ -496,8 +490,15 @@ export default function DayExecution() { const extraPending = extraSets.filter((s) => s.reps == null).length; const extraDone = extraSets.filter((s) => s.reps != null).length; const nextSetId = allSets.find((s) => s.reps == null)?.id ?? null; - const canAddExtra = (exSets: { planSetId: string | null; reps: number | null }[]) => - extraPending === 0 && !exSets.some((s) => s.planSetId != null && s.reps == null); + // Powód blokady „Dodaj serię" (null = można); pokazujemy go w alercie po kliknięciu. + const addSetBlockedReason = (ex?: SessionExercise): string | null => + !ex + ? null + : ex.sets.some((s) => s.planSetId != null && s.reps == null) + ? 'Najpierw zapisz wszystkie serie normowe tego ćwiczenia' + : extraPending > 0 + ? 'W sesji jest już niezapisana seria dodatkowa — najpierw ją uzupełnij' + : null; // Akordeon: rozwinięte jest ćwiczenie zawierające następną serię (aktywne); // kliknięcie nagłówka przełącza rozwinięcie (jedno ćwiczenie naraz). @@ -665,6 +666,12 @@ export default function DayExecution() { const addSet = async (exerciseId: string) => { if (!session || addingRef.current) return; + // blokada po stronie klienta z komunikatem w alercie (serwer broni się dodatkowo) + const blocked = addSetBlockedReason(session.exercises.find((e) => e.id === exerciseId)); + if (blocked) { + setAddSetAlert(blocked); + return; + } addingRef.current = true; try { await addSessionSet(exerciseId); @@ -794,14 +801,6 @@ export default function DayExecution() { expanded={expandedExId === ex.id} inProgress={session.status === 'IN_PROGRESS'} nextSetId={nextSetId} - canAddExtra={canAddExtra(ex.sets)} - addSetHint={ - ex.sets.some((s) => s.planSetId != null && s.reps == null) - ? 'Najpierw zapisz wszystkie serie normowe tego ćwiczenia' - : extraPending > 0 - ? 'W sesji jest już niezapisana seria dodatkowa — najpierw ją uzupełnij' - : null - } onToggle={() => toggleEx(ex.id)} onRemove={() => removeExercise(ex)} onEditSet={(s, i) => { @@ -844,6 +843,13 @@ export default function DayExecution() { busy={busy} /> + setAddSetAlert(null)} + title="Nie można dodać serii" + message={addSetAlert ?? ''} + /> + { expect(completeBtn).toBeDisabled(); expect(screen.getByText(/została 1 seria/)).toBeInTheDocument(); - // „Dodaj serię” zablokowany: własna norma niedokończona + aktywna seria bonusowa (1 na sesję) - expect(screen.getAllByRole('button', { name: 'Dodaj serię' })[0]).toBeDisabled(); - // przy zablokowanym przycisku widać przyczynę (norma ma priorytet nad limitem bonusu) - expect(screen.getByText('Najpierw zapisz wszystkie serie normowe tego ćwiczenia')).toBeInTheDocument(); + // klik „Dodaj serię” przy niedokończonej normie => alert z przyczyną (norma przed limitem bonusu) + await user.click(screen.getByRole('button', { name: 'Dodaj serię' })); + expect( + await screen.findByText('Najpierw zapisz wszystkie serie normowe tego ćwiczenia'), + ).toBeInTheDocument(); + await user.click(screen.getByRole('button', { name: 'OK' })); + expect( + screen.queryByText('Najpierw zapisz wszystkie serie normowe tego ćwiczenia'), + ).not.toBeInTheDocument(); }); - it('pokazuje przyczynę blokady „Dodaj serię”, gdy w sesji trwa niezapisana seria dodatkowa', async () => { + it('pokazuje alert z przyczyną, gdy w sesji trwa niezapisana seria dodatkowa', async () => { mockApi({ 'ss-1': 10, 'ss-2': 10, 'ss-3': null }); const user = userEvent.setup(); renderApp(); await openActiveDay(user); - // norma zrobiona (100%), ale ss-3 to bonus w toku => przycisk zablokowany + komunikat + // norma zrobiona (100%), ale ss-3 to bonus w toku => klik „Dodaj serię” daje alert expect(await screen.findByText('100%')).toBeInTheDocument(); - const btn = screen.getByRole('button', { name: 'Dodaj serię' }); - expect(btn).toBeDisabled(); + await user.click(screen.getByRole('button', { name: 'Dodaj serię' })); expect( - screen.getByText('W sesji jest już niezapisana seria dodatkowa — najpierw ją uzupełnij'), + await screen.findByText('W sesji jest już niezapisana seria dodatkowa — najpierw ją uzupełnij'), ).toBeInTheDocument(); + expect(screen.getByRole('dialog', { name: /Nie można dodać serii/ })).toBeInTheDocument(); expect( screen.queryByText('Najpierw zapisz wszystkie serie normowe tego ćwiczenia'), ).not.toBeInTheDocument(); @@ -332,15 +337,16 @@ describe('Kolejka serii w sesji', () => { renderApp(); await openActiveDay(user); - // Przysiady (rozwinięte): własna norma niedokończona (ss-2) => brak bonusu + przyczyna - expect(screen.getByRole('button', { name: 'Dodaj serię' })).toBeDisabled(); - expect(screen.getByText('Najpierw zapisz wszystkie serie normowe tego ćwiczenia')).toBeInTheDocument(); - // Wyciskanie (dodane do sesji) nie ma normy planowej => bonus dostępny mimo ss-2, bez komunikatu - await user.click(screen.getByRole('button', { name: /Wyciskanie/ })); - expect(screen.getByRole('button', { name: 'Dodaj serię' })).toBeEnabled(); + // Przysiady (rozwinięte): własna norma niedokończona (ss-2) => klik daje alert z przyczyną + await user.click(screen.getByRole('button', { name: 'Dodaj serię' })); expect( - screen.queryByText('Najpierw zapisz wszystkie serie normowe tego ćwiczenia'), - ).not.toBeInTheDocument(); + await screen.findByText('Najpierw zapisz wszystkie serie normowe tego ćwiczenia'), + ).toBeInTheDocument(); + await user.click(screen.getByRole('button', { name: 'OK' })); + // Wyciskanie (dodane do sesji) nie ma normy planowej => bonus dostępny mimo ss-2, bez alertu + await user.click(screen.getByRole('button', { name: /Wyciskanie/ })); + await user.click(screen.getByRole('button', { name: 'Dodaj serię' })); + expect(screen.queryByRole('dialog', { name: /Nie można dodać serii/ })).not.toBeInTheDocument(); }); it('po zakończeniu wszystkich serii normowych odblokowuje ukończenie sesji', async () => { diff --git a/app/test/e2e/day-execution.spec.ts b/app/test/e2e/day-execution.spec.ts index 4b023a8..b04c84a 100644 --- a/app/test/e2e/day-execution.spec.ts +++ b/app/test/e2e/day-execution.spec.ts @@ -25,12 +25,16 @@ test('wyszczególnia założenia zaplanowanej serii i oznacza ćwiczenie dodane' await expect(page.getByText('0%')).toBeVisible(); await expect(page.getByText('Następna', { exact: true })).toBeVisible(); await expect(page.getByRole('button', { name: 'Ukończ sesję' })).toBeDisabled(); - // Przysiady: własna norma (ss-1) niedokończona => brak bonusu; Wyciskanie blokuje - // limit jednej aktywnej serii bonusowej w sesji (ss-2 niezapisana) - await expect(page.getByRole('button', { name: 'Dodaj serię' }).first()).toBeDisabled(); + // klik „Dodaj serię” przy niedokończonej normie (Przysiady, ss-1) => alert z przyczyną; + // w Wyciskaniu dodatkowo trzyma limit jednej niezapisanej serii bonusowej w sesji (ss-2) + await page.getByRole('button', { name: 'Dodaj serię' }).first().click(); await expect( page.getByText('Najpierw zapisz wszystkie serie normowe tego ćwiczenia'), ).toBeVisible(); + await page.getByRole('button', { name: 'OK' }).click(); + await expect( + page.getByText('Najpierw zapisz wszystkie serie normowe tego ćwiczenia'), + ).toHaveCount(0); }); test('uzupełnia serię wsadowo przez okno „Uzupełnij serię”', async ({ page }) => {