Trening: CTA Wroc do treningu zamiast startu, gdy sesja juz trwa (kalendarz, dashboard, brak migotania startu w dniu treningowym)
This commit is contained in:
@@ -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 (
|
||||
<Card>
|
||||
<div className="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-2">
|
||||
@@ -50,7 +53,11 @@ function SelectedDayCard({ day }: { day: CalendarDay }) {
|
||||
</ul>
|
||||
<Link to={`/day/${day.id}`} className="mt-4 block">
|
||||
<Button className="w-full sm:w-auto">
|
||||
{day.status === 'PLANNED' ? 'Rozpocznij trening' : 'Pokaż szczegóły'}
|
||||
{inProgress
|
||||
? 'Wróć do treningu'
|
||||
: day.status === 'PLANNED'
|
||||
? 'Rozpocznij trening'
|
||||
: 'Pokaż szczegóły'}
|
||||
</Button>
|
||||
</Link>
|
||||
</Card>
|
||||
|
||||
@@ -352,10 +352,10 @@ export default function Dashboard() {
|
||||
))}
|
||||
</ul>
|
||||
<Link to={`/day/${data.nextTraining.dayId}`} className="mt-4 block">
|
||||
<Button className="w-full sm:w-auto">
|
||||
<Play className="h-4 w-4" />
|
||||
Wykonaj trening
|
||||
</Button>
|
||||
<Button className="w-full sm:w-auto">
|
||||
<Play className="h-4 w-4" />
|
||||
{active?.dayId === data.nextTraining.dayId ? 'Wróć do treningu' : 'Wykonaj trening'}
|
||||
</Button>
|
||||
</Link>
|
||||
</>
|
||||
) : (
|
||||
|
||||
@@ -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 (
|
||||
<div className="space-y-4">
|
||||
<Skeleton className="h-9 w-56" />
|
||||
@@ -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') && (
|
||||
<Card>
|
||||
<p className="mb-3">Dzień zaplanowany. Rozpocznij sesję, aby wykonać trening.</p>
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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 });
|
||||
|
||||
Reference in New Issue
Block a user