diff --git a/app/src/pages/Calendar.tsx b/app/src/pages/Calendar.tsx index 6e4334b..157bc38 100644 --- a/app/src/pages/Calendar.tsx +++ b/app/src/pages/Calendar.tsx @@ -1,6 +1,6 @@ import { useState } from 'react'; import { Link } from 'react-router-dom'; -import { useCalendar } from '../api/queries'; +import { useActiveSession, useCalendar } from '../api/queries'; import { monthStr } from '../lib/format'; import { DAY_STATUS, MUSCLE_NAMES } from '../lib/labels'; import { useTopbar } from '../topbar'; @@ -25,6 +25,9 @@ import { /* Karta wybranego dnia: data + status + lista ćwiczeń + CTA. */ function SelectedDayCard({ day }: { day: CalendarDay }) { const st = DAY_STATUS[day.status]; + const { data: activeData } = useActiveSession(); + // dzień ma już rozpoczętą sesję — CTA prowadzi do powrotu, nie do startu + const inProgress = activeData?.session?.dayId === day.id; return (
@@ -50,7 +53,11 @@ function SelectedDayCard({ day }: { day: CalendarDay }) { diff --git a/app/src/pages/Dashboard.tsx b/app/src/pages/Dashboard.tsx index 68a3364..5d84d6c 100644 --- a/app/src/pages/Dashboard.tsx +++ b/app/src/pages/Dashboard.tsx @@ -352,10 +352,10 @@ export default function Dashboard() { ))} - + ) : ( diff --git a/app/src/pages/DayExecution.tsx b/app/src/pages/DayExecution.tsx index d0bf00f..750d016 100644 --- a/app/src/pages/DayExecution.tsx +++ b/app/src/pages/DayExecution.tsx @@ -401,7 +401,7 @@ export default function DayExecution() { } }, [rest, restRemaining, push]); - const { data: sessionData, isLoading } = useSession(sessionId ?? ''); + const { data: sessionData, isLoading: sessionLoading } = useSession(sessionId ?? ''); const session = sessionData?.session; // Serie normowe (zaplanowane) to norma; serie nadmiarowe (bez planSetId) to bonus. @@ -606,7 +606,7 @@ export default function DayExecution() { const exercises = exData?.exercises ?? []; - if (isLoading && !session) { + if (sessionLoading && !session) { return (
@@ -628,6 +628,8 @@ export default function DayExecution() { {dayInfo && dayInfo.status === 'PLANNED' && + // nie pokazuj „Rozpocznij sesję”, dopóki sesja dnia się ładuje (może być IN_PROGRESS) + !sessionLoading && (!session || session.status !== 'IN_PROGRESS') && (

Dzień zaplanowany. Rozpocznij sesję, aby wykonać trening.

diff --git a/app/test/Calendar.test.tsx b/app/test/Calendar.test.tsx index d3d97eb..af2ca0b 100644 --- a/app/test/Calendar.test.tsx +++ b/app/test/Calendar.test.tsx @@ -100,6 +100,81 @@ afterEach(() => { vi.unstubAllGlobals(); }); +const ACTIVE_SESSION = { + id: 'sess-1', + dayId: 'day-1', + dayDate: '2026-08-24', + dayOfWeek: 1, + planTitle: 'Plan testowy', + startedAt: '2026-08-24T07:00:00.000Z', +}; + +/** Kalendarz z jednym dniem zaplanowanym na dziś + opcjonalna aktywna sesja. */ +function mockApiWithDay(active: unknown) { + vi.stubGlobal( + 'fetch', + vi.fn(async (input: RequestInfo | URL) => { + const url = String(input); + if (url.includes('/auth/login')) return jsonResponse(200, { user: USER, accessToken: 'tok-1' }); + if (url.includes('/auth/refresh')) + return jsonResponse(401, { error: { code: 'UNAUTHORIZED', message: 'no cookie' } }); + if (url.includes('/me/active-session')) return jsonResponse(200, { session: active }); + if (url.includes('/me')) return jsonResponse(200, { user: USER, memberships: [] }); + if (url.includes('/dashboard')) + return jsonResponse(200, { + killstreak: 0, + activePlan: null, + nextTraining: null, + progress: null, + extra: null, + missing: null, + }); + if (url.includes('/calendar')) + return jsonResponse(200, { + month: monthStr(new Date()), + days: [ + { + id: 'day-1', + date: new Date().toISOString(), + status: 'PLANNED', + dayOfWeek: 1, + exercises: [{ name: 'Przysiady', muscle: 'legs' }], + }, + ], + }); + if (url.includes('/exercises')) return jsonResponse(200, { exercises: [] }); + if (url.includes('/gyms')) return jsonResponse(200, { gyms: [] }); + if (url.includes('/trainer/invitations')) return jsonResponse(200, { invitations: [] }); + return jsonResponse(404, { error: { code: 'NOT_FOUND', message: 'not found' } }); + }), + ); +} + +describe('Kalendarz — CTA karty dnia wg stanu sesji', () => { + it('dzień zaplanowany bez aktywnej sesji: „Rozpocznij trening”', async () => { + mockApiWithDay(null); + const user = userEvent.setup(); + renderApp(); + await openCalendar(user); + + // wybór dnia z listy mobilnej (siatka ukryta w jsdom) + await user.click(screen.getByRole('button', { name: /Zaplanowany/ })); + expect(await screen.findByRole('button', { name: 'Rozpocznij trening' })).toBeInTheDocument(); + expect(screen.queryByRole('button', { name: 'Wróć do treningu' })).not.toBeInTheDocument(); + }); + + it('dzień z aktywną sesją: „Wróć do treningu” zamiast „Rozpocznij trening”', async () => { + mockApiWithDay(ACTIVE_SESSION); + const user = userEvent.setup(); + renderApp(); + await openCalendar(user); + + await user.click(screen.getByRole('button', { name: /Zaplanowany/ })); + expect(await screen.findByRole('button', { name: 'Wróć do treningu' })).toBeInTheDocument(); + expect(screen.queryByRole('button', { name: 'Rozpocznij trening' })).not.toBeInTheDocument(); + }); +}); + describe('Kalendarz — nawigacja miesiąca w top menu', () => { it('przyciski „Poprzedni/Następny miesiąc” zmieniają miesiąc (z rolowaniem roku)', async () => { mockApi(); diff --git a/app/test/e2e/active-training.spec.ts b/app/test/e2e/active-training.spec.ts index b18ed53..3c39c31 100644 --- a/app/test/e2e/active-training.spec.ts +++ b/app/test/e2e/active-training.spec.ts @@ -27,7 +27,10 @@ test('aktywna sesja — skrót „Trening” w menu bocznym i na dashboardzie', // dashboard: karta „Trwa trening” ze skrótem do dnia sesji await expect(page.getByText('Trwa trening')).toBeVisible(); - await expect(page.getByRole('link', { name: /Wróć do treningu/ })).toBeVisible(); + // karta „Następny trening” wskazuje ten sam dzień co aktywna sesja — + // oba CTA to „Wróć do treningu” (nie „Wykonaj trening”) + await expect(page.getByRole('link', { name: /Wróć do treningu/ })).toHaveCount(2); + await expect(page.getByRole('button', { name: 'Wykonaj trening' })).toHaveCount(0); // menu boczne: link „Trening” prowadzi do dnia aktywnego treningu (exact — „Wróć/Wykonaj trening” to inne linki) const sidebarLink = page.getByRole('link', { name: 'Trening', exact: true });