From 1bed564bfc5e859300be155cccc4c0e16ffad3f7 Mon Sep 17 00:00:00 2001 From: Tilumca Date: Wed, 14 Oct 2026 22:07:33 +0200 Subject: [PATCH] Trening: nowo dodane cwiczenie rozwija sie automatycznie (przycisk "Dodaj serie" od razu widoczny) --- app/src/pages/DayExecution.tsx | 4 +++- app/test/DayExecution.test.tsx | 11 ++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/src/pages/DayExecution.tsx b/app/src/pages/DayExecution.tsx index bd5aa5f..2fb4ab1 100644 --- a/app/src/pages/DayExecution.tsx +++ b/app/src/pages/DayExecution.tsx @@ -660,7 +660,9 @@ export default function DayExecution() { if (!session || addingRef.current) return; addingRef.current = true; try { - await addSessionExercise(session.id, exerciseId); + const res = await addSessionExercise(session.id, exerciseId); + // nowe ćwiczenie rozwija się samo — „Dodaj serię” widoczne od razu, bez szukania + setExpandedIds((cur) => (cur.includes(res.exerciseId) ? cur : [...cur, res.exerciseId])); await queryClient.invalidateQueries({ queryKey: ['sessions', session.id] }); } catch (e) { setError(e instanceof Error ? e.message : 'Błąd'); diff --git a/app/test/DayExecution.test.tsx b/app/test/DayExecution.test.tsx index cb28140..065cfca 100644 --- a/app/test/DayExecution.test.tsx +++ b/app/test/DayExecution.test.tsx @@ -197,7 +197,8 @@ function mockApi( const body = JSON.parse(String(init?.body)) as { exerciseId: string }; const ex = catalog.find((c) => c.id === body.exerciseId); if (ex && !added.some((a) => a.id === ex.id)) added.push(ex); - return jsonResponse(200, { exerciseId: body.exerciseId }); + // id wiersza sesji jak w fixture (se-x1, se-x2…) — front używa go do rozwinięcia akordeonu + return jsonResponse(200, { exerciseId: `se-x${added.length}` }); } if (url.includes('/days/day-1')) return jsonResponse(200, { @@ -767,6 +768,14 @@ describe('Dodawanie ćwiczenia do sesji', () => { await user.click(within(dialog).getByRole('button', { name: /Martwy ciąg/ })); expect(await screen.findByRole('heading', { name: 'Martwy ciąg' })).toBeInTheDocument(); expect(screen.queryByRole('dialog')).not.toBeInTheDocument(); + + // dodane ćwiczenie rozwija się automatycznie — „Dodaj serię” od razu pod ręką + expect(screen.getByRole('button', { name: /Martwy ciąg/ })).toHaveAttribute( + 'aria-expanded', + 'true', + ); + // otwarte akordeony: Wyciskanie (auto, następna seria) + Martwy ciąg => 2 przyciski + expect(screen.getAllByRole('button', { name: 'Dodaj serię' })).toHaveLength(2); }); it('pusty katalog ćwiczeń pokazuje komunikat w modalu', async () => {