2026-09-12 15:16:13 +02:00
|
|
|
|
import { render, screen, waitFor, within } from '@testing-library/react';
|
2026-09-04 19:06:19 +02:00
|
|
|
|
import userEvent from '@testing-library/user-event';
|
|
|
|
|
|
import { MemoryRouter } from 'react-router-dom';
|
|
|
|
|
|
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
|
|
|
|
|
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
|
|
|
|
import App from '../src/App';
|
|
|
|
|
|
import { useAuth } from '../src/store/auth';
|
|
|
|
|
|
import { setAccessToken } from '../src/api/client';
|
|
|
|
|
|
|
|
|
|
|
|
const TRAINEE_ID = 'trainee-1';
|
|
|
|
|
|
|
|
|
|
|
|
const USER = {
|
|
|
|
|
|
id: 'trainer-1',
|
|
|
|
|
|
email: 'trener@test.local',
|
|
|
|
|
|
firstName: 'Tomasz',
|
|
|
|
|
|
lastName: 'Trener',
|
|
|
|
|
|
age: 35,
|
|
|
|
|
|
heightCm: 185,
|
|
|
|
|
|
phone: null,
|
|
|
|
|
|
isAdmin: false,
|
|
|
|
|
|
availability: null,
|
|
|
|
|
|
priorities: 'chest',
|
|
|
|
|
|
exclusions: 'knee',
|
|
|
|
|
|
developMuscles: [],
|
|
|
|
|
|
canDoMuscles: [],
|
|
|
|
|
|
difficultMuscles: [],
|
|
|
|
|
|
avoidMuscles: [],
|
|
|
|
|
|
createdAt: '2026-08-01T10:00:00.000Z',
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const OTHER_TRAINER = { id: 'trainer-2', firstName: 'Jan', lastName: 'Kowalski' };
|
|
|
|
|
|
|
|
|
|
|
|
const EXERCISES = [
|
|
|
|
|
|
{ id: 'ex-1', name: 'Przysiady', primaryMuscle: 'legs' },
|
|
|
|
|
|
{ id: 'ex-2', name: 'Wyciskanie', primaryMuscle: 'chest' },
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
const TRAINEE_DETAIL = {
|
|
|
|
|
|
user: { id: TRAINEE_ID, firstName: 'Anna', lastName: 'Nowak' },
|
2026-09-13 03:18:18 +02:00
|
|
|
|
gyms: [{ id: 'gym-1', name: 'Siłownia Podopiecznej', equipment: [] }],
|
2026-09-04 19:06:19 +02:00
|
|
|
|
activePlan: null,
|
|
|
|
|
|
progress: null,
|
|
|
|
|
|
killstreak: 0,
|
|
|
|
|
|
nextTraining: null,
|
|
|
|
|
|
extra: null,
|
|
|
|
|
|
missing: null,
|
|
|
|
|
|
lastSessionAt: null,
|
|
|
|
|
|
flags: [],
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const PLANS = [
|
|
|
|
|
|
{
|
|
|
|
|
|
id: 'plan-1',
|
|
|
|
|
|
title: 'Plan masowy',
|
|
|
|
|
|
status: 'DRAFT',
|
|
|
|
|
|
weeksCount: 1,
|
|
|
|
|
|
startDate: null,
|
|
|
|
|
|
creator: OTHER_TRAINER,
|
|
|
|
|
|
weeks: [],
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
id: 'plan-2',
|
|
|
|
|
|
title: 'Plan aktywny',
|
|
|
|
|
|
status: 'ACTIVE',
|
|
|
|
|
|
weeksCount: 4,
|
|
|
|
|
|
startDate: '2026-08-24',
|
|
|
|
|
|
creator: null,
|
|
|
|
|
|
weeks: [],
|
|
|
|
|
|
},
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
const DRAFT_DETAIL = {
|
|
|
|
|
|
id: 'plan-1',
|
|
|
|
|
|
title: 'Plan masowy',
|
|
|
|
|
|
status: 'DRAFT',
|
|
|
|
|
|
weeksCount: 1,
|
|
|
|
|
|
startDate: null,
|
|
|
|
|
|
creator: OTHER_TRAINER,
|
|
|
|
|
|
weeks: [
|
|
|
|
|
|
{
|
|
|
|
|
|
id: 'w1',
|
|
|
|
|
|
index: 0,
|
|
|
|
|
|
days: [
|
|
|
|
|
|
{
|
|
|
|
|
|
id: 'd1',
|
|
|
|
|
|
dayOfWeek: 1,
|
|
|
|
|
|
date: null,
|
|
|
|
|
|
status: 'PLANNED',
|
|
|
|
|
|
moveLog: [],
|
|
|
|
|
|
sessions: [],
|
|
|
|
|
|
exercises: [
|
|
|
|
|
|
{
|
|
|
|
|
|
id: 'pe1',
|
|
|
|
|
|
exerciseId: 'ex-1',
|
|
|
|
|
|
order: 0,
|
|
|
|
|
|
exercise: { id: 'ex-1', name: 'Przysiady', primaryMuscle: 'legs' },
|
|
|
|
|
|
sets: [
|
|
|
|
|
|
{
|
|
|
|
|
|
id: 's1',
|
|
|
|
|
|
index: 0,
|
|
|
|
|
|
reps: 10,
|
|
|
|
|
|
loadKg: 60,
|
|
|
|
|
|
restSec: 90,
|
|
|
|
|
|
rir: 2,
|
|
|
|
|
|
cardioBpm: null,
|
|
|
|
|
|
timeSec: null,
|
|
|
|
|
|
speed: null,
|
|
|
|
|
|
},
|
|
|
|
|
|
],
|
|
|
|
|
|
},
|
|
|
|
|
|
],
|
|
|
|
|
|
},
|
|
|
|
|
|
],
|
|
|
|
|
|
},
|
|
|
|
|
|
],
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const ACTIVE_DETAIL = {
|
|
|
|
|
|
id: 'plan-2',
|
|
|
|
|
|
title: 'Plan aktywny',
|
|
|
|
|
|
status: 'ACTIVE',
|
|
|
|
|
|
weeksCount: 4,
|
|
|
|
|
|
startDate: '2026-08-24',
|
|
|
|
|
|
creator: null,
|
|
|
|
|
|
weeks: [
|
|
|
|
|
|
{
|
|
|
|
|
|
id: 'w1',
|
|
|
|
|
|
index: 0,
|
|
|
|
|
|
days: [
|
|
|
|
|
|
{
|
|
|
|
|
|
id: 'd1',
|
|
|
|
|
|
dayOfWeek: 1,
|
|
|
|
|
|
date: '2026-08-24',
|
|
|
|
|
|
status: 'PLANNED',
|
|
|
|
|
|
moveLog: [],
|
|
|
|
|
|
sessions: [],
|
|
|
|
|
|
exercises: [
|
|
|
|
|
|
{
|
|
|
|
|
|
id: 'pe2',
|
|
|
|
|
|
exerciseId: 'ex-2',
|
|
|
|
|
|
order: 0,
|
|
|
|
|
|
exercise: { id: 'ex-2', name: 'Wyciskanie', primaryMuscle: 'chest' },
|
|
|
|
|
|
sets: [
|
|
|
|
|
|
{
|
|
|
|
|
|
id: 's2',
|
|
|
|
|
|
index: 0,
|
|
|
|
|
|
reps: 8,
|
|
|
|
|
|
loadKg: 40,
|
|
|
|
|
|
restSec: 90,
|
|
|
|
|
|
rir: 2,
|
|
|
|
|
|
cardioBpm: null,
|
|
|
|
|
|
timeSec: null,
|
|
|
|
|
|
speed: null,
|
|
|
|
|
|
},
|
|
|
|
|
|
],
|
|
|
|
|
|
},
|
|
|
|
|
|
],
|
|
|
|
|
|
},
|
|
|
|
|
|
],
|
|
|
|
|
|
},
|
|
|
|
|
|
],
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const LATEST_RESULTS = [
|
2026-09-11 18:38:48 +02:00
|
|
|
|
{
|
|
|
|
|
|
exerciseId: 'ex-1',
|
|
|
|
|
|
name: 'Przysiady',
|
|
|
|
|
|
muscle: 'legs',
|
|
|
|
|
|
date: '2026-08-20',
|
|
|
|
|
|
sets: [{ reps: 12, loadKg: 70 }],
|
|
|
|
|
|
oneRm: 80.6,
|
|
|
|
|
|
},
|
2026-09-04 19:06:19 +02:00
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
const PROGRESS = [
|
|
|
|
|
|
{
|
|
|
|
|
|
exerciseId: 'ex-1',
|
|
|
|
|
|
name: 'Przysiady',
|
|
|
|
|
|
muscle: 'legs',
|
|
|
|
|
|
points: [
|
|
|
|
|
|
{ date: '2026-08-13', oneRm: 75, volumeKg: 420, reps: 30, sets: 3 },
|
|
|
|
|
|
{ date: '2026-08-20', oneRm: 80.6, volumeKg: 480, reps: 36, sets: 3 },
|
|
|
|
|
|
],
|
|
|
|
|
|
},
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
function jsonResponse(status: number, body: unknown) {
|
|
|
|
|
|
return new Response(JSON.stringify(body), {
|
|
|
|
|
|
status,
|
|
|
|
|
|
headers: { 'Content-Type': 'application/json' },
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-09-12 21:41:58 +02:00
|
|
|
|
function mockApi(
|
|
|
|
|
|
opts: { plans?: unknown[]; capture?: { createBody?: Record<string, unknown> } } = {},
|
|
|
|
|
|
) {
|
2026-09-04 19:06:19 +02:00
|
|
|
|
const plans = opts.plans ?? PLANS;
|
|
|
|
|
|
vi.stubGlobal(
|
|
|
|
|
|
'fetch',
|
|
|
|
|
|
vi.fn(async (input: RequestInfo | URL, init?: RequestInit) => {
|
|
|
|
|
|
const url = String(input);
|
|
|
|
|
|
const method = init?.method || 'GET';
|
2026-09-11 18:38:48 +02:00
|
|
|
|
if (url.includes('/auth/refresh'))
|
|
|
|
|
|
return jsonResponse(200, { user: USER, accessToken: 'tok-1' });
|
2026-09-04 19:06:19 +02:00
|
|
|
|
if (url.includes('/me/active-session')) return jsonResponse(200, { session: null });
|
|
|
|
|
|
if (url.endsWith('/me'))
|
2026-09-11 18:38:48 +02:00
|
|
|
|
return jsonResponse(200, {
|
|
|
|
|
|
user: USER,
|
|
|
|
|
|
memberships: [{ gymId: 'gym-1', roles: ['TRAINER'] }],
|
|
|
|
|
|
});
|
2026-09-04 19:06:19 +02:00
|
|
|
|
if (url.includes('/dashboard'))
|
|
|
|
|
|
return jsonResponse(200, {
|
|
|
|
|
|
killstreak: 0,
|
|
|
|
|
|
activePlan: null,
|
|
|
|
|
|
nextTraining: null,
|
|
|
|
|
|
progress: null,
|
|
|
|
|
|
extra: null,
|
|
|
|
|
|
missing: null,
|
|
|
|
|
|
});
|
|
|
|
|
|
if (url.includes('/gyms')) return jsonResponse(200, { gyms: [] });
|
|
|
|
|
|
if (url.includes('/trainer/invitations')) return jsonResponse(200, { invitations: [] });
|
|
|
|
|
|
if (url.includes('/exercises')) return jsonResponse(200, { exercises: EXERCISES });
|
|
|
|
|
|
// najpierw szczegóły planu (URL zawiera też /plans i /trainees/:id)
|
|
|
|
|
|
if (url.includes(`/trainer/trainees/${TRAINEE_ID}/plans/plan-1`)) {
|
|
|
|
|
|
if (method === 'PATCH' || method === 'DELETE') return jsonResponse(200, { ok: true });
|
|
|
|
|
|
return jsonResponse(200, { plan: DRAFT_DETAIL });
|
|
|
|
|
|
}
|
|
|
|
|
|
if (url.includes(`/trainer/trainees/${TRAINEE_ID}/plans/plan-2`))
|
|
|
|
|
|
return jsonResponse(200, { plan: ACTIVE_DETAIL });
|
|
|
|
|
|
if (url.includes(`/trainer/trainees/${TRAINEE_ID}/plans`)) {
|
2026-09-12 15:16:13 +02:00
|
|
|
|
if (method === 'POST') {
|
|
|
|
|
|
if (opts.capture) opts.capture.createBody = JSON.parse(String(init?.body));
|
|
|
|
|
|
return jsonResponse(201, { plan: { id: 'plan-new' } });
|
|
|
|
|
|
}
|
2026-09-04 19:06:19 +02:00
|
|
|
|
return jsonResponse(200, { plans });
|
|
|
|
|
|
}
|
|
|
|
|
|
if (url.includes(`/trainer/trainees/${TRAINEE_ID}/exercise-latest`))
|
|
|
|
|
|
return jsonResponse(200, { results: LATEST_RESULTS });
|
|
|
|
|
|
if (url.includes(`/trainer/trainees/${TRAINEE_ID}/exercise-progress`))
|
|
|
|
|
|
return jsonResponse(200, { exercises: PROGRESS });
|
2026-09-11 18:38:48 +02:00
|
|
|
|
if (url.includes(`/trainer/trainees/${TRAINEE_ID}/history`))
|
|
|
|
|
|
return jsonResponse(200, { sessions: [] });
|
2026-09-04 19:06:19 +02:00
|
|
|
|
if (url.includes(`/trainer/trainees/${TRAINEE_ID}/report`))
|
|
|
|
|
|
return jsonResponse(200, { plan: null, muscles: [], days: [] });
|
2026-09-11 18:38:48 +02:00
|
|
|
|
if (url.includes(`/trainer/trainees/${TRAINEE_ID}/moves`))
|
|
|
|
|
|
return jsonResponse(200, { moves: [] });
|
2026-09-04 19:06:19 +02:00
|
|
|
|
if (url.includes(`/trainer/trainees/${TRAINEE_ID}`)) return jsonResponse(200, TRAINEE_DETAIL);
|
|
|
|
|
|
return jsonResponse(200, {});
|
|
|
|
|
|
}),
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function renderAt(path: string) {
|
|
|
|
|
|
const queryClient = new QueryClient({
|
|
|
|
|
|
defaultOptions: { queries: { retry: 0, refetchOnWindowFocus: false } },
|
|
|
|
|
|
});
|
|
|
|
|
|
render(
|
|
|
|
|
|
<QueryClientProvider client={queryClient}>
|
|
|
|
|
|
<MemoryRouter initialEntries={[path]}>
|
|
|
|
|
|
<App />
|
|
|
|
|
|
</MemoryRouter>
|
|
|
|
|
|
</QueryClientProvider>,
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
|
|
|
|
|
await new Promise((r) => setTimeout(r, 25));
|
|
|
|
|
|
setAccessToken(null);
|
|
|
|
|
|
localStorage.clear();
|
|
|
|
|
|
useAuth.setState({ user: null, ready: false });
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
|
|
vi.unstubAllGlobals();
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
describe('Zakładka „Plany" w panelu podopiecznego', () => {
|
2026-09-04 23:19:28 +02:00
|
|
|
|
it('lista planów z badge statusu i etykietą twórcy; „Utwórz plan" w menu kontekstowym', async () => {
|
2026-09-04 19:06:19 +02:00
|
|
|
|
mockApi();
|
|
|
|
|
|
renderAt(`/trainees/${TRAINEE_ID}?tab=plans`);
|
|
|
|
|
|
|
|
|
|
|
|
expect(await screen.findByRole('heading', { name: 'Anna Nowak' })).toBeInTheDocument();
|
|
|
|
|
|
await screen.findByRole('heading', { name: 'Plany podopiecznego' });
|
|
|
|
|
|
|
2026-09-04 23:19:28 +02:00
|
|
|
|
// akcja tworzenia planu jest w menu kontekstowym strony (topbar), nie w zakładce
|
2026-09-04 19:06:19 +02:00
|
|
|
|
expect(screen.getByRole('button', { name: 'Utwórz plan' })).toBeInTheDocument();
|
|
|
|
|
|
expect(screen.getByText('Plan masowy')).toBeInTheDocument();
|
|
|
|
|
|
expect(screen.getByText('Plan aktywny')).toBeInTheDocument();
|
|
|
|
|
|
// badge statusu
|
|
|
|
|
|
expect(screen.getByText('Szkic')).toBeInTheDocument();
|
|
|
|
|
|
expect(screen.getByText('Aktywny')).toBeInTheDocument();
|
|
|
|
|
|
// etykieta twórcy (twórca ≠ zalogowany trener)
|
|
|
|
|
|
expect(screen.getByText('utworzył: Jan Kowalski')).toBeInTheDocument();
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('pusty stan, gdy podopieczny nie ma planów', async () => {
|
|
|
|
|
|
mockApi({ plans: [] });
|
|
|
|
|
|
renderAt(`/trainees/${TRAINEE_ID}?tab=plans`);
|
|
|
|
|
|
|
|
|
|
|
|
expect(await screen.findByRole('heading', { name: 'Plany podopiecznego' })).toBeInTheDocument();
|
|
|
|
|
|
expect(screen.getByText('Podopieczny nie ma żadnych planów.')).toBeInTheDocument();
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('szkic: akcje Edytuj/Aktywuj/Usuń i struktura inline', async () => {
|
|
|
|
|
|
mockApi();
|
|
|
|
|
|
const user = userEvent.setup();
|
|
|
|
|
|
renderAt(`/trainees/${TRAINEE_ID}?tab=plans`);
|
|
|
|
|
|
|
|
|
|
|
|
await screen.findByRole('heading', { name: 'Plany podopiecznego' });
|
|
|
|
|
|
await user.click(screen.getByRole('button', { name: 'Plan masowy' }));
|
|
|
|
|
|
|
|
|
|
|
|
expect(await screen.findByRole('button', { name: 'Edytuj' })).toBeInTheDocument();
|
|
|
|
|
|
expect(screen.getByRole('button', { name: 'Aktywuj' })).toBeInTheDocument();
|
|
|
|
|
|
expect(screen.getByRole('button', { name: 'Usuń' })).toBeInTheDocument();
|
2026-09-11 18:47:30 +02:00
|
|
|
|
// struktura inline (nagłówek akordeonu — pasek tygodni ma też chip „Tydzień 1”)
|
|
|
|
|
|
expect(screen.getByRole('heading', { name: 'Tydzień 1' })).toBeInTheDocument();
|
2026-09-04 19:06:19 +02:00
|
|
|
|
expect(screen.getByText('Poniedziałek')).toBeInTheDocument();
|
|
|
|
|
|
expect(screen.getByText(/Przysiady/)).toBeInTheDocument();
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('aktywny: akcje „Oznacz jako ukończony" i „Porzuć"', async () => {
|
|
|
|
|
|
mockApi();
|
|
|
|
|
|
const user = userEvent.setup();
|
|
|
|
|
|
renderAt(`/trainees/${TRAINEE_ID}?tab=plans`);
|
|
|
|
|
|
|
|
|
|
|
|
await screen.findByRole('heading', { name: 'Plany podopiecznego' });
|
|
|
|
|
|
await user.click(screen.getByRole('button', { name: 'Plan aktywny' }));
|
|
|
|
|
|
|
|
|
|
|
|
expect(await screen.findByRole('button', { name: 'Porzuć' })).toBeInTheDocument();
|
|
|
|
|
|
expect(screen.getByRole('button', { name: 'Oznacz jako ukończony' })).toBeInTheDocument();
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
describe('PlanEditor — tryb podopiecznego', () => {
|
2026-09-11 18:35:36 +02:00
|
|
|
|
it('edycja: formularz inicjalizuje się z danych planu po załadowaniu', async () => {
|
|
|
|
|
|
mockApi();
|
2026-09-12 15:16:13 +02:00
|
|
|
|
const user = userEvent.setup();
|
2026-09-11 18:35:36 +02:00
|
|
|
|
renderAt(`/trainees/${TRAINEE_ID}/plans/plan-1/edit`);
|
|
|
|
|
|
|
2026-09-11 18:38:48 +02:00
|
|
|
|
expect(
|
|
|
|
|
|
await screen.findByRole('heading', { name: 'Edycja planu podopiecznego' }),
|
|
|
|
|
|
).toBeInTheDocument();
|
2026-09-12 15:16:13 +02:00
|
|
|
|
// tytuł wczytany z API (krok 1); serie (krok 2) po przejściu „Dalej”
|
2026-09-11 18:35:36 +02:00
|
|
|
|
expect(await screen.findByDisplayValue('Plan masowy')).toBeInTheDocument();
|
2026-09-12 15:16:13 +02:00
|
|
|
|
await user.click(screen.getByRole('button', { name: 'Dalej' }));
|
|
|
|
|
|
expect(await screen.findByDisplayValue('60')).toBeInTheDocument();
|
2026-09-11 18:35:36 +02:00
|
|
|
|
});
|
|
|
|
|
|
|
2026-09-11 20:36:17 +02:00
|
|
|
|
it('„Wstecz" przy niezapisanych zmianach pyta o potwierdzenie', async () => {
|
2026-09-11 18:38:48 +02:00
|
|
|
|
mockApi();
|
|
|
|
|
|
const user = userEvent.setup();
|
|
|
|
|
|
renderAt(`/trainees/${TRAINEE_ID}/plans/new`);
|
|
|
|
|
|
|
|
|
|
|
|
await screen.findByRole('heading', { name: 'Plan dla podopiecznego' });
|
|
|
|
|
|
// zmiana tytułu → stan dirty
|
|
|
|
|
|
await user.type(screen.getByPlaceholderText('np. Plan masowy 8-tygodniowy'), 'X');
|
2026-09-11 20:36:17 +02:00
|
|
|
|
// „Wstecz” w treści (w jsdom jest też „<” topbara mobile — oba prowadzą do guardu)
|
|
|
|
|
|
await user.click(screen.getAllByRole('button', { name: 'Wstecz' }).at(-1)!);
|
2026-09-11 18:38:48 +02:00
|
|
|
|
expect(await screen.findByRole('heading', { name: 'Niezapisane zmiany' })).toBeInTheDocument();
|
|
|
|
|
|
// potwierdzenie → powrót do zakładki planów podopiecznego
|
|
|
|
|
|
await user.click(screen.getByRole('button', { name: 'Opuść' }));
|
|
|
|
|
|
expect(await screen.findByRole('heading', { name: 'Plany podopiecznego' })).toBeInTheDocument();
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2026-09-11 19:04:19 +02:00
|
|
|
|
it('karta ćwiczenia: badge grupy mięśniowej i podsumowanie serii', async () => {
|
|
|
|
|
|
mockApi();
|
|
|
|
|
|
const user = userEvent.setup();
|
|
|
|
|
|
renderAt(`/trainees/${TRAINEE_ID}/plans/new`);
|
|
|
|
|
|
|
|
|
|
|
|
await screen.findByRole('heading', { name: 'Plan dla podopiecznego' });
|
2026-09-12 15:16:13 +02:00
|
|
|
|
// krok 2 (ćwiczenia) — po tytule i przejściu „Dalej”
|
|
|
|
|
|
await user.type(screen.getByPlaceholderText('np. Plan masowy 8-tygodniowy'), 'Plan');
|
|
|
|
|
|
await user.click(screen.getByRole('button', { name: 'Dalej' }));
|
2026-09-11 19:04:19 +02:00
|
|
|
|
await user.click(screen.getByRole('button', { name: 'Poniedziałek' }));
|
2026-09-11 20:38:26 +02:00
|
|
|
|
await user.click(screen.getByRole('button', { name: 'dodaj ćwiczenie…' }));
|
2026-09-11 19:04:19 +02:00
|
|
|
|
await user.click(await screen.findByRole('option', { name: /Przysiady/ }));
|
|
|
|
|
|
|
|
|
|
|
|
// legs → badge „Nogi”; seria domyślna → „1×10 @ 20 kg · RIR 2”
|
|
|
|
|
|
expect(screen.getByText('Nogi')).toBeInTheDocument();
|
|
|
|
|
|
expect(screen.getByText(/1×10 @ 20 kg/)).toBeInTheDocument();
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2026-09-12 22:01:52 +02:00
|
|
|
|
it('„Wstecz” na kroku 2 cofa do kroku 1 (nie wychodzi z edytora)', async () => {
|
|
|
|
|
|
mockApi();
|
|
|
|
|
|
const user = userEvent.setup();
|
|
|
|
|
|
renderAt(`/trainees/${TRAINEE_ID}/plans/new`);
|
|
|
|
|
|
|
|
|
|
|
|
await screen.findByRole('heading', { name: 'Plan dla podopiecznego' });
|
2026-10-11 18:32:30 +02:00
|
|
|
|
// pole siłowni = krok 1
|
|
|
|
|
|
expect(screen.getByText('Siłownia')).toBeInTheDocument();
|
2026-09-12 22:01:52 +02:00
|
|
|
|
await user.type(screen.getByPlaceholderText('np. Plan masowy 8-tygodniowy'), 'Plan');
|
|
|
|
|
|
await user.click(screen.getByRole('button', { name: 'Dalej' }));
|
2026-10-11 18:32:30 +02:00
|
|
|
|
// krok 2: tytuł schowany — jesteśmy na etapie ćwiczeń
|
|
|
|
|
|
expect(screen.queryByPlaceholderText('np. Plan masowy 8-tygodniowy')).not.toBeInTheDocument();
|
2026-09-12 22:01:52 +02:00
|
|
|
|
// „Wstecz” w treści (ostatni w DOM) cofa do kroku 1
|
|
|
|
|
|
await user.click(screen.getAllByRole('button', { name: 'Wstecz' }).at(-1)!);
|
|
|
|
|
|
expect(screen.getByPlaceholderText('np. Plan masowy 8-tygodniowy')).toBeVisible();
|
2026-10-11 18:32:30 +02:00
|
|
|
|
expect(screen.getByText('Siłownia')).toBeInTheDocument();
|
2026-09-12 22:01:52 +02:00
|
|
|
|
});
|
|
|
|
|
|
|
2026-09-12 21:49:08 +02:00
|
|
|
|
it('walidacja: pusty tytuł blokuje „Dalej” i „Zapisz”', async () => {
|
2026-09-11 19:04:19 +02:00
|
|
|
|
mockApi();
|
|
|
|
|
|
renderAt(`/trainees/${TRAINEE_ID}/plans/new`);
|
|
|
|
|
|
|
|
|
|
|
|
await screen.findByRole('heading', { name: 'Plan dla podopiecznego' });
|
2026-09-12 21:49:08 +02:00
|
|
|
|
expect(screen.getByRole('button', { name: 'Dalej' })).toBeDisabled();
|
|
|
|
|
|
expect(screen.getByRole('button', { name: 'Zapisz' })).toBeDisabled();
|
2026-09-11 19:04:19 +02:00
|
|
|
|
});
|
|
|
|
|
|
|
2026-09-04 19:06:19 +02:00
|
|
|
|
it('„Wstaw wyniki" prefylluje serie z ostatniej sesji', async () => {
|
|
|
|
|
|
mockApi();
|
|
|
|
|
|
const user = userEvent.setup();
|
|
|
|
|
|
renderAt(`/trainees/${TRAINEE_ID}/plans/new`);
|
|
|
|
|
|
|
2026-09-11 18:38:48 +02:00
|
|
|
|
expect(
|
|
|
|
|
|
await screen.findByRole('heading', { name: 'Plan dla podopiecznego' }),
|
|
|
|
|
|
).toBeInTheDocument();
|
2026-09-04 19:06:19 +02:00
|
|
|
|
|
2026-09-12 15:16:13 +02:00
|
|
|
|
// krok 2 (ćwiczenia) — po tytule i przejściu „Dalej”
|
|
|
|
|
|
await user.type(screen.getByPlaceholderText('np. Plan masowy 8-tygodniowy'), 'Plan');
|
|
|
|
|
|
await user.click(screen.getByRole('button', { name: 'Dalej' }));
|
2026-09-11 18:50:47 +02:00
|
|
|
|
// dodaj dzień (Poniedziałek — aria-label z pełną nazwą)
|
|
|
|
|
|
await user.click(screen.getByRole('button', { name: 'Poniedziałek' }));
|
2026-09-11 18:40:58 +02:00
|
|
|
|
// dodaj ćwiczenie Przysiady (wyszukiwarka ćwiczeń)
|
2026-09-11 20:38:26 +02:00
|
|
|
|
await user.click(screen.getByRole('button', { name: 'dodaj ćwiczenie…' }));
|
2026-09-11 18:40:58 +02:00
|
|
|
|
await user.click(await screen.findByRole('option', { name: /Przysiady/ }));
|
2026-09-04 19:06:19 +02:00
|
|
|
|
|
|
|
|
|
|
// otwórz panel wyników i wstaw
|
|
|
|
|
|
await user.click(screen.getByRole('button', { name: 'Wyniki' }));
|
|
|
|
|
|
expect(await screen.findByText('Wstaw wyniki')).toBeInTheDocument();
|
|
|
|
|
|
await user.click(screen.getByRole('button', { name: 'Wstaw wyniki' }));
|
|
|
|
|
|
|
|
|
|
|
|
// serie z ostatniej sesji: 12 powt. @ 70 kg
|
|
|
|
|
|
expect(screen.getByDisplayValue('12')).toBeInTheDocument();
|
|
|
|
|
|
expect(screen.getByDisplayValue('70')).toBeInTheDocument();
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
2026-09-12 15:16:13 +02:00
|
|
|
|
|
|
|
|
|
|
describe('PlanEditor — wizard 3-etapowy (tryb podopiecznego)', () => {
|
|
|
|
|
|
it('krok 1 blokuje „Dalej” przy pustym tytule', async () => {
|
|
|
|
|
|
mockApi();
|
|
|
|
|
|
const user = userEvent.setup();
|
|
|
|
|
|
renderAt(`/trainees/${TRAINEE_ID}/plans/new`);
|
|
|
|
|
|
|
|
|
|
|
|
await screen.findByRole('heading', { name: 'Plan dla podopiecznego' });
|
|
|
|
|
|
expect(screen.getByRole('button', { name: 'Dalej' })).toBeDisabled();
|
2026-09-12 21:49:08 +02:00
|
|
|
|
expect(screen.getByRole('button', { name: 'Zapisz' })).toBeDisabled();
|
2026-09-12 15:16:13 +02:00
|
|
|
|
await user.type(screen.getByPlaceholderText('np. Plan masowy 8-tygodniowy'), 'Plan');
|
|
|
|
|
|
expect(screen.getByRole('button', { name: 'Dalej' })).toBeEnabled();
|
2026-09-12 21:49:08 +02:00
|
|
|
|
expect(screen.getByRole('button', { name: 'Zapisz' })).toBeEnabled();
|
2026-09-12 15:16:13 +02:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('krok 2: select siłowni z członkostw podopiecznego + alias tygodnia; krok 3: podsumowanie i zapis', async () => {
|
|
|
|
|
|
const capture: { createBody?: Record<string, unknown> } = {};
|
|
|
|
|
|
mockApi({ capture });
|
|
|
|
|
|
const user = userEvent.setup();
|
|
|
|
|
|
renderAt(`/trainees/${TRAINEE_ID}/plans/new`);
|
|
|
|
|
|
|
|
|
|
|
|
await screen.findByRole('heading', { name: 'Plan dla podopiecznego' });
|
|
|
|
|
|
await user.type(screen.getByPlaceholderText('np. Plan masowy 8-tygodniowy'), 'Plan wizard');
|
|
|
|
|
|
// 1 tydzień — podsumowanie bez lustrzanych tygodni
|
2026-09-12 21:41:58 +02:00
|
|
|
|
const weeksField = screen
|
|
|
|
|
|
.getByText('Długość (tygodnie)')
|
|
|
|
|
|
.closest('[data-slot="field"]') as HTMLElement;
|
2026-09-12 15:16:13 +02:00
|
|
|
|
await user.selectOptions(within(weeksField).getByRole('combobox'), '1');
|
|
|
|
|
|
|
2026-10-11 18:32:30 +02:00
|
|
|
|
// select siłowni (krok 1): opcja „Bez siłowni” + siłownia podopiecznego
|
2026-09-12 15:16:13 +02:00
|
|
|
|
// (Field bez <label for> — selekcja przez kontener pola)
|
|
|
|
|
|
const gymField = screen.getByText('Siłownia').closest('[data-slot="field"]') as HTMLElement;
|
|
|
|
|
|
const gymSelect = within(gymField).getByRole('combobox');
|
|
|
|
|
|
expect(within(gymSelect).getByRole('option', { name: 'Bez siłowni' })).toBeInTheDocument();
|
2026-09-12 21:41:58 +02:00
|
|
|
|
expect(
|
|
|
|
|
|
within(gymSelect).getByRole('option', { name: 'Siłownia Podopiecznej' }),
|
|
|
|
|
|
).toBeInTheDocument();
|
2026-09-12 15:16:13 +02:00
|
|
|
|
await user.selectOptions(gymSelect, 'gym-1');
|
|
|
|
|
|
|
2026-10-11 18:32:30 +02:00
|
|
|
|
await user.click(screen.getByRole('button', { name: 'Dalej' }));
|
|
|
|
|
|
|
|
|
|
|
|
// krok 2: dzień + ćwiczenie + alias tygodnia
|
2026-09-12 15:16:13 +02:00
|
|
|
|
await user.click(screen.getByRole('button', { name: 'Poniedziałek' }));
|
|
|
|
|
|
await user.click(screen.getByRole('button', { name: 'dodaj ćwiczenie…' }));
|
|
|
|
|
|
await user.click(await screen.findByRole('option', { name: /Przysiady/ }));
|
|
|
|
|
|
const aliasField = screen
|
2026-09-12 21:41:58 +02:00
|
|
|
|
.getByText('Nazwa tygodnia 1 (opcjonalnie)')
|
2026-09-12 15:16:13 +02:00
|
|
|
|
.closest('[data-slot="field"]') as HTMLElement;
|
|
|
|
|
|
await user.type(within(aliasField).getByRole('textbox'), 'Deload');
|
|
|
|
|
|
|
|
|
|
|
|
// krok 3: podsumowanie — alias, siłownia, dni i ćwiczenia
|
|
|
|
|
|
await user.click(screen.getByRole('button', { name: 'Dalej' }));
|
|
|
|
|
|
expect(await screen.findByText('Deload')).toBeInTheDocument();
|
|
|
|
|
|
expect(screen.getByText('Siłownia Podopiecznej')).toBeInTheDocument();
|
2026-09-13 02:37:07 +02:00
|
|
|
|
// liczniki w karcie podsumowania („Łącznie:” = unikalne; stopka na kroku 3 ukryta)
|
2026-09-12 15:16:13 +02:00
|
|
|
|
const summaryCard = screen
|
|
|
|
|
|
.getByText('Łącznie: 1 dzień · 1 ćwiczenie · 1 seria')
|
|
|
|
|
|
.closest('[data-slot="card"]') as HTMLElement;
|
2026-09-12 21:41:58 +02:00
|
|
|
|
expect(
|
|
|
|
|
|
within(summaryCard).getByText('Pon · 1 dzień · 1 ćwiczenie · 1 seria'),
|
|
|
|
|
|
).toBeInTheDocument();
|
2026-09-12 15:16:13 +02:00
|
|
|
|
|
|
|
|
|
|
// zapis (krok 3) — body z gymId i customName
|
|
|
|
|
|
await user.click(screen.getByRole('button', { name: 'Zapisz' }));
|
|
|
|
|
|
await waitFor(() => expect(capture.createBody).toBeDefined());
|
|
|
|
|
|
expect(capture.createBody).toMatchObject({
|
|
|
|
|
|
title: 'Plan wizard',
|
|
|
|
|
|
gymId: 'gym-1',
|
|
|
|
|
|
weeks: [expect.objectContaining({ index: 0, customName: 'Deload' })],
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|