From d611a6b53b833d548eb425e05745a2b2874ca18c Mon Sep 17 00:00:00 2001 From: Tilumca Date: Wed, 14 Oct 2026 22:15:59 +0200 Subject: [PATCH] Trening: auto-przewijanie do nastepnej serii do uzupelnienia po zapisie i przy wejsciu w sesje --- app/src/pages/DayExecution.tsx | 8 ++++++++ app/test/DayExecution.test.tsx | 20 +++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/app/src/pages/DayExecution.tsx b/app/src/pages/DayExecution.tsx index 29709d5..2b1b3a2 100644 --- a/app/src/pages/DayExecution.tsx +++ b/app/src/pages/DayExecution.tsx @@ -179,6 +179,7 @@ function SetRow({ .join(' · '); return (
setExpandedIds((cur) => (cur.includes(id) ? cur.filter((x) => x !== id) : [...cur, id])); + + // Auto-nawigacja: przy zmianie „następnej" serii (też po zapisie) rozwinięte + // ćwiczenie przewija widok do niej — bez ręcznego szukania kolejnej serii. + useEffect(() => { + if (!nextSetId) return; + document.getElementById(`set-${nextSetId}`)?.scrollIntoView?.({ behavior: 'smooth', block: 'center' }); + }, [nextSetId, expandedIds]); const editSetData = editSet ? allSets.find((s) => s.id === editSet.setId) : undefined; const editValues: SetFieldValues = editSetData ? { diff --git a/app/test/DayExecution.test.tsx b/app/test/DayExecution.test.tsx index edf5215..1b37aa5 100644 --- a/app/test/DayExecution.test.tsx +++ b/app/test/DayExecution.test.tsx @@ -1,4 +1,4 @@ -import { render, screen, within } from '@testing-library/react'; +import { render, screen, waitFor, within } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import { MemoryRouter } from 'react-router-dom'; import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; @@ -362,6 +362,24 @@ describe('Kolejka serii w sesji', () => { ).not.toBeInTheDocument(); }); + it('przewija widok do następnej serii do uzupełnienia (auto-nawigacja)', async () => { + const spy = vi.fn(); + const orig = Element.prototype.scrollIntoView; + Element.prototype.scrollIntoView = spy; + mockApi({ 'ss-1': 10, 'ss-2': null, 'ss-3': null }); + const user = userEvent.setup(); + try { + renderApp(); + await openActiveDay(user); + + // następna seria to ss-2 (w rozwiniętym automatycznie ćwiczeniu) — na nią scroll + await waitFor(() => expect(spy).toHaveBeenCalled()); + expect(spy.mock.contexts).toContain(document.getElementById('set-ss-2')); + } finally { + Element.prototype.scrollIntoView = orig; + } + }); + it('odblokowuje „Dodaj serię” dla ćwiczenia bez normy mimo niedokończonej normy innego ćwiczenia', async () => { mockApi({ 'ss-1': 10, 'ss-2': null, 'ss-3': 12 }); const user = userEvent.setup();