581 lines
23 KiB
TypeScript
581 lines
23 KiB
TypeScript
import { render, screen, 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';
|
||
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
||
import App from '../src/App';
|
||
import { useAuth } from '../src/store/auth';
|
||
import { useListSearch } from '../src/store/list-search';
|
||
import { setAccessToken } from '../src/api/client';
|
||
import type { User } from '../src/api/types';
|
||
|
||
const TRAINER: User = {
|
||
id: 'trainer-1',
|
||
email: 'trener@test.local',
|
||
firstName: 'Marek',
|
||
lastName: 'Trener',
|
||
age: 35,
|
||
heightCm: 185,
|
||
phone: null,
|
||
isAdmin: false,
|
||
availability: null,
|
||
priorities: null,
|
||
exclusions: null,
|
||
developMuscles: [],
|
||
canDoMuscles: [],
|
||
difficultMuscles: [],
|
||
avoidMuscles: [],
|
||
createdAt: '2026-01-01T00:00:00.000Z',
|
||
};
|
||
|
||
const GYM = {
|
||
id: 'gym-1',
|
||
name: 'Żelazna Świątynia',
|
||
location: 'Warszawa',
|
||
availability: null,
|
||
capacity: null,
|
||
equipment: [],
|
||
};
|
||
|
||
const TRAINEE = {
|
||
user: { id: 'trainee-1', firstName: 'Anna', lastName: 'Nowak' },
|
||
gyms: [GYM],
|
||
activePlan: { id: 'plan-1', title: 'Plan testowy', progress: { completed: 5, total: 20, percent: 25 } },
|
||
killstreak: 3,
|
||
lastSessionAt: '2026-08-24T07:00:00.000Z',
|
||
flags: ['streak_reset'],
|
||
};
|
||
|
||
const TRAINEE_DETAIL = {
|
||
coachingId: 'coaching-1',
|
||
user: { id: 'trainee-1', firstName: 'Anna', lastName: 'Nowak' },
|
||
gyms: [GYM],
|
||
activePlan: { id: 'plan-1', title: 'Plan testowy', startDate: '2026-08-01' },
|
||
progress: { completed: 5, total: 20, percent: 25 },
|
||
killstreak: 3,
|
||
nextTraining: { dayId: 'day-1', date: '2026-08-25', exercises: [{ name: 'Przysiady', muscle: 'legs' }] },
|
||
extra: { sets: 5 },
|
||
missing: { sets: 1 },
|
||
lastSessionAt: '2026-08-24T07:00:00.000Z',
|
||
flags: ['streak_reset'],
|
||
};
|
||
|
||
const TRAINEE_2 = {
|
||
user: { id: 'trainee-2', firstName: 'Piotr', lastName: 'Kowal' },
|
||
gyms: [],
|
||
activePlan: null,
|
||
killstreak: 0,
|
||
lastSessionAt: null,
|
||
flags: [],
|
||
};
|
||
|
||
const TRAINEE_3 = {
|
||
user: { id: 'trainee-3', firstName: 'Zofia', lastName: 'Wiśniewska' },
|
||
gyms: [],
|
||
activePlan: null,
|
||
killstreak: 10,
|
||
lastSessionAt: '2026-09-03T07:00:00.000Z',
|
||
flags: [],
|
||
};
|
||
|
||
const CANDIDATE = {
|
||
id: 'candidate-1',
|
||
firstName: 'Jan',
|
||
lastName: 'Kowalski',
|
||
email: 'jan.kowalski@test.local',
|
||
phone: '+48 500 100 200',
|
||
gyms: [{ id: 'gym-2', name: 'Mega Gym' }],
|
||
};
|
||
|
||
function jsonResponse(status: number, body: unknown) {
|
||
if (status === 204) return new Response(null, { status });
|
||
return new Response(JSON.stringify(body), {
|
||
status,
|
||
headers: { 'Content-Type': 'application/json' },
|
||
});
|
||
}
|
||
|
||
function mockApi() {
|
||
vi.stubGlobal(
|
||
'fetch',
|
||
vi.fn(async (input: RequestInfo | URL, init?: RequestInit) => {
|
||
const url = String(input);
|
||
const method = init?.method || 'GET';
|
||
if (url.includes('/auth/login')) return jsonResponse(200, { user: TRAINER, accessToken: 'tok-1' });
|
||
if (url.includes('/auth/refresh'))
|
||
return jsonResponse(401, { error: { code: 'UNAUTHORIZED', message: 'no cookie' } });
|
||
if (url.includes('/messages/conversations/coaching-1'))
|
||
return jsonResponse(200, {
|
||
role: 'trainer',
|
||
other: { id: 'trainee-1', firstName: 'Anna', lastName: 'Nowak', nickname: null },
|
||
messages: [],
|
||
});
|
||
if (url.includes('/me'))
|
||
return jsonResponse(200, {
|
||
user: TRAINER,
|
||
memberships: [{ gymId: GYM.id, roles: ['TRAINER'], gym: GYM }],
|
||
});
|
||
if (url.includes('/trainer/invitations/inv-1/accept'))
|
||
return jsonResponse(200, { coaching: { id: 'inv-1', status: 'ACTIVE' } });
|
||
if (url.includes('/trainer/invitations'))
|
||
return jsonResponse(
|
||
method === 'POST' ? 201 : 200,
|
||
method === 'POST'
|
||
? { coaching: { id: 'inv-new', status: 'PENDING' } }
|
||
: {
|
||
invitations: [
|
||
{
|
||
id: 'inv-1',
|
||
direction: 'received',
|
||
other: { id: 'trainer-2', firstName: 'Piotr', lastName: 'Trener', email: 'p.trener@test.local', phone: null },
|
||
invitedAt: '2026-08-20T00:00:00.000Z',
|
||
expiresAt: '2026-08-27T00:00:00.000Z',
|
||
},
|
||
{
|
||
id: 'inv-2',
|
||
direction: 'sent',
|
||
other: { id: 'trainee-2', firstName: 'Pola', lastName: 'Podopieczna', email: 'pola@test.local', phone: null },
|
||
invitedAt: '2026-08-21T00:00:00.000Z',
|
||
expiresAt: '2026-08-28T00:00:00.000Z',
|
||
},
|
||
],
|
||
},
|
||
);
|
||
if (url.includes('/trainer/trainees/trainee-1/moves'))
|
||
return jsonResponse(200, {
|
||
moves: [
|
||
{
|
||
dayId: 'day-3',
|
||
date: '2026-08-21T00:00:00.000Z',
|
||
fromDate: '2026-08-19T00:00:00.000Z',
|
||
toDate: '2026-08-21T00:00:00.000Z',
|
||
reason: 'choroba',
|
||
movedAt: '2026-08-19T09:00:00.000Z',
|
||
},
|
||
],
|
||
});
|
||
if (url.includes('/trainer/trainees/trainee-1/report'))
|
||
return jsonResponse(200, {
|
||
plan: { id: 'plan-1', title: 'Plan testowy', startDate: '2026-08-01T00:00:00.000Z' },
|
||
muscles: [
|
||
{
|
||
muscle: 'legs',
|
||
planned: { sets: 12, reps: 120 },
|
||
actual: { sets: 10, reps: 96 },
|
||
extra: { sets: 2 },
|
||
missing: { sets: 2 },
|
||
completionPct: 83,
|
||
recommendedRange: { setsMin: 10, setsMax: 18 },
|
||
outOfRange: false,
|
||
},
|
||
{
|
||
muscle: 'chest',
|
||
planned: { sets: 10, reps: 90 },
|
||
actual: { sets: 4, reps: 32 },
|
||
extra: { sets: 0 },
|
||
missing: { sets: 6 },
|
||
completionPct: 40,
|
||
recommendedRange: { setsMin: 10, setsMax: 20 },
|
||
outOfRange: true,
|
||
},
|
||
],
|
||
days: [
|
||
{ date: '2026-08-18T00:00:00.000Z', status: 'COMPLETED', moved: false },
|
||
{ date: '2026-08-20T00:00:00.000Z', status: 'SKIPPED', moved: false },
|
||
{ date: '2026-08-21T00:00:00.000Z', status: 'COMPLETED', moved: true },
|
||
{ date: '2026-08-25T00:00:00.000Z', status: 'PLANNED', moved: false },
|
||
],
|
||
});
|
||
if (url.includes('/trainer/trainees/trainee-1/history'))
|
||
return jsonResponse(200, {
|
||
sessions: [
|
||
{
|
||
id: 'hist-1',
|
||
status: 'COMPLETED',
|
||
startedAt: '2026-08-24T07:00:00.000Z',
|
||
endedAt: '2026-08-24T08:30:00.000Z',
|
||
date: '2026-08-24',
|
||
dayOfWeek: 1,
|
||
plan: 'Plan testowy',
|
||
exercises: [
|
||
{
|
||
id: 'hist-ex-1',
|
||
name: 'Przysiady',
|
||
muscle: 'legs',
|
||
isExtra: false,
|
||
sets: [{ index: 0, reps: 10, rir: 2, difficulty: 3, planned: { reps: 10, loadKg: 60, restSec: 90, rir: 2 } }],
|
||
comments: [],
|
||
},
|
||
{
|
||
id: 'hist-ex-2',
|
||
name: 'Wyciskanie',
|
||
muscle: 'chest',
|
||
isExtra: true,
|
||
sets: [{ index: 0, reps: 8, rir: 1, difficulty: null, planned: null }],
|
||
comments: [],
|
||
},
|
||
],
|
||
},
|
||
{
|
||
id: 'hist-2',
|
||
status: 'COMPLETED',
|
||
startedAt: '2026-08-17T07:00:00.000Z',
|
||
endedAt: '2026-08-17T08:30:00.000Z',
|
||
date: '2026-08-17',
|
||
dayOfWeek: 1,
|
||
plan: 'Plan testowy',
|
||
exercises: [
|
||
{
|
||
id: 'hist-ex-3',
|
||
name: 'Przysiady',
|
||
muscle: 'legs',
|
||
isExtra: false,
|
||
sets: [{ index: 0, reps: 8, rir: 3, difficulty: 3, planned: { reps: 10, loadKg: 60, restSec: 90, rir: 2 } }],
|
||
comments: [],
|
||
},
|
||
],
|
||
},
|
||
],
|
||
});
|
||
if (url.includes('/trainer/trainees/trainee-1/exercise-progress'))
|
||
return jsonResponse(200, {
|
||
exercises: [
|
||
{
|
||
exerciseId: 'ex-1',
|
||
name: 'Przysiady',
|
||
muscle: 'legs',
|
||
points: [
|
||
{ date: '2026-08-17', oneRm: 72, volumeKg: 480, reps: 8, sets: 1 },
|
||
{ date: '2026-08-24', oneRm: 76, volumeKg: 600, reps: 10, sets: 1 },
|
||
],
|
||
},
|
||
{
|
||
exerciseId: 'ex-2',
|
||
name: 'Wyciskanie',
|
||
muscle: 'chest',
|
||
points: [{ date: '2026-08-24', oneRm: null, volumeKg: null, reps: 8, sets: 1 }],
|
||
},
|
||
],
|
||
});
|
||
if (url.includes('/trainer/trainees/trainee-1'))
|
||
return jsonResponse(method === 'DELETE' ? 204 : 200, method === 'DELETE' ? {} : TRAINEE_DETAIL);
|
||
if (url.includes('/trainer/trainees'))
|
||
return jsonResponse(200, { trainees: [TRAINEE, TRAINEE_2, TRAINEE_3] });
|
||
if (url.includes('/trainer/search')) return jsonResponse(200, { users: [CANDIDATE] });
|
||
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('/plans')) return jsonResponse(200, { plans: [] });
|
||
if (url.includes('/exercises')) return jsonResponse(200, { exercises: [] });
|
||
if (url.includes('/calendar')) return jsonResponse(200, { month: '2026-08', days: [] });
|
||
return jsonResponse(404, { error: { code: 'NOT_FOUND', message: 'not found' } });
|
||
}),
|
||
);
|
||
}
|
||
|
||
async function loginToTrainees(user: userEvent.User) {
|
||
expect(await screen.findByRole('heading', { name: 'FitOS' })).toBeInTheDocument();
|
||
const email = document.querySelector('input[type="email"]') as HTMLInputElement;
|
||
const password = document.querySelector('input[type="password"]') as HTMLInputElement;
|
||
await user.type(email, 'trener@test.local');
|
||
await user.type(password, 'Password123!');
|
||
await user.click(screen.getByRole('button', { name: 'Zaloguj' }));
|
||
expect(await screen.findByRole('heading', { name: 'Dashboard' })).toBeInTheDocument();
|
||
await user.click(screen.getByRole('link', { name: 'Podopieczni' }));
|
||
expect(await screen.findByRole('heading', { name: 'Podopieczni' })).toBeInTheDocument();
|
||
}
|
||
|
||
function renderApp() {
|
||
const queryClient = new QueryClient({
|
||
defaultOptions: { queries: { retry: 0, refetchOnWindowFocus: false } },
|
||
});
|
||
return render(
|
||
<QueryClientProvider client={queryClient}>
|
||
<MemoryRouter initialEntries={['/']}>
|
||
<App />
|
||
</MemoryRouter>
|
||
</QueryClientProvider>,
|
||
);
|
||
}
|
||
|
||
beforeEach(async () => {
|
||
await new Promise((r) => setTimeout(r, 25));
|
||
setAccessToken(null);
|
||
localStorage.clear();
|
||
useAuth.setState({ user: null, ready: false });
|
||
useListSearch.setState({ queries: { plans: '', gyms: '', trainees: '', invitations: '' } });
|
||
});
|
||
|
||
afterEach(() => {
|
||
vi.unstubAllGlobals();
|
||
});
|
||
|
||
describe('Trainees — lista i szczegóły', () => {
|
||
it('trener widzi listę podopiecznych z metrykami i flagami', async () => {
|
||
mockApi();
|
||
const user = userEvent.setup();
|
||
renderApp();
|
||
await loginToTrainees(user);
|
||
|
||
expect(await screen.findByText('Anna Nowak')).toBeInTheDocument();
|
||
expect(screen.getByText('Żelazna Świątynia')).toBeInTheDocument();
|
||
expect(screen.getByText('Zerowany streak')).toBeInTheDocument();
|
||
expect(screen.getByText('5/20 dni')).toBeInTheDocument();
|
||
expect(screen.getByText('Plan testowy')).toBeInTheDocument();
|
||
});
|
||
|
||
it('wyszukiwarka w menu kontekstowym filtruje listę podopiecznych', async () => {
|
||
mockApi();
|
||
const user = userEvent.setup();
|
||
renderApp();
|
||
await loginToTrainees(user);
|
||
await screen.findByText('Anna Nowak');
|
||
expect(screen.getByText('Piotr Kowal')).toBeInTheDocument();
|
||
|
||
// wyszukiwarka jest w menu kontekstowym (nagłówek) za ikoną 🔍
|
||
await user.click(screen.getByRole('button', { name: 'Wyszukiwarka' }));
|
||
const searchbox = screen.getByRole('searchbox', { name: 'Szukaj podopiecznego' });
|
||
await user.type(searchbox, 'anna');
|
||
expect(screen.queryByText('Piotr Kowal')).not.toBeInTheDocument();
|
||
expect(screen.getByText('Anna Nowak')).toBeInTheDocument();
|
||
|
||
// pełne imię i nazwisko również znajduje podopiecznego
|
||
await user.clear(searchbox);
|
||
await user.type(searchbox, 'anna nowak');
|
||
expect(screen.queryByText('Piotr Kowal')).not.toBeInTheDocument();
|
||
expect(screen.getByText('Anna Nowak')).toBeInTheDocument();
|
||
});
|
||
|
||
it('select sortowania w topmenu zmienia kolejność listy (flagi/killstreak/nazwa/ostatnia sesja)', async () => {
|
||
mockApi();
|
||
const user = userEvent.setup();
|
||
renderApp();
|
||
await loginToTrainees(user);
|
||
await screen.findByText('Anna Nowak');
|
||
|
||
const NAMES = ['Anna Nowak', 'Piotr Kowal', 'Zofia Wiśniewska'];
|
||
// kolejność wierszy = kolejność przycisków-wierszy zawierających imię i nazwisko
|
||
const rowOrder = () =>
|
||
Array.from(document.querySelectorAll('button'))
|
||
.filter((b) => NAMES.some((n) => b.textContent?.includes(n)))
|
||
.map((b) => NAMES.find((n) => b.textContent!.includes(n))!);
|
||
// wybór opcji sortowania: otwórz dropdown „Sortuj: …” i kliknij opcję
|
||
const pickSort = async (option: string) => {
|
||
await user.click(screen.getByRole('button', { name: /Sortuj:/ }));
|
||
await user.click(await screen.findByRole('button', { name: option }));
|
||
};
|
||
|
||
// domyślnie: najpierw flagi (Anna 1 > Piotr/Zofia 0; remis po nazwie)
|
||
expect(rowOrder()).toEqual(['Anna Nowak', 'Piotr Kowal', 'Zofia Wiśniewska']);
|
||
|
||
await pickSort('Killstreak');
|
||
expect(rowOrder()).toEqual(['Zofia Wiśniewska', 'Anna Nowak', 'Piotr Kowal']);
|
||
|
||
await pickSort('Nazwa');
|
||
expect(rowOrder()).toEqual(['Anna Nowak', 'Piotr Kowal', 'Zofia Wiśniewska']);
|
||
|
||
await pickSort('Ostatnia sesja');
|
||
expect(rowOrder()).toEqual(['Zofia Wiśniewska', 'Anna Nowak', 'Piotr Kowal']);
|
||
|
||
await pickSort('Flagi');
|
||
expect(rowOrder()).toEqual(['Anna Nowak', 'Piotr Kowal', 'Zofia Wiśniewska']);
|
||
});
|
||
|
||
it('trener może wyszukać kandydata i wysłać zaproszenie', async () => {
|
||
mockApi();
|
||
const user = userEvent.setup();
|
||
renderApp();
|
||
await loginToTrainees(user);
|
||
await screen.findByText('Anna Nowak');
|
||
|
||
// top menu „Dodaj podopiecznego” (za ikoną ➕) otwiera modal wyszukiwania
|
||
await user.click(screen.getByRole('button', { name: 'Dodawanie' }));
|
||
await user.click(screen.getByRole('button', { name: 'Dodaj podopiecznego' }));
|
||
await user.type(await screen.findByPlaceholderText('Imię'), 'Jan');
|
||
await user.type(screen.getByPlaceholderText('Nazwisko'), 'Kowalski');
|
||
await user.click(screen.getByRole('button', { name: 'Szukaj' }));
|
||
expect(await screen.findByText(/jan\.kowalski@test\.local/)).toBeInTheDocument();
|
||
expect(screen.getByText(/\+48 500 100 200/)).toBeInTheDocument();
|
||
|
||
await user.click(screen.getByRole('button', { name: 'Zaproś' }));
|
||
expect(await screen.findByText('Zaproszenie wysłane')).toBeInTheDocument();
|
||
});
|
||
|
||
it('szczegóły podopiecznego: przegląd i historia z planem vs. fakty', async () => {
|
||
mockApi();
|
||
const user = userEvent.setup();
|
||
renderApp();
|
||
await loginToTrainees(user);
|
||
await screen.findByText('Anna Nowak');
|
||
|
||
await user.click(screen.getByRole('button', { name: /Anna Nowak/ }));
|
||
expect(await screen.findByRole('heading', { name: 'Anna Nowak' })).toBeInTheDocument();
|
||
// overview tab
|
||
expect(screen.getByText('Następny trening')).toBeInTheDocument();
|
||
expect(screen.getByText('Nogi')).toBeInTheDocument();
|
||
expect(screen.getByText('+5')).toBeInTheDocument();
|
||
|
||
// history tab: expand the collapsed session to reveal exercises
|
||
await user.click(screen.getByRole('button', { name: 'Historia' }));
|
||
await user.click(await screen.findByRole('button', { name: /24\.08\.2026/ }));
|
||
expect(await screen.findByText('Przysiady')).toBeInTheDocument();
|
||
expect(screen.getByText('dodane')).toBeInTheDocument();
|
||
expect(screen.getByText(/plan: 10 powt. \/ 60 kg \/ 90 s/)).toBeInTheDocument();
|
||
});
|
||
|
||
it('trener archiwizuje podopiecznego i wraca na listę', async () => {
|
||
mockApi();
|
||
const user = userEvent.setup();
|
||
renderApp();
|
||
await loginToTrainees(user);
|
||
await screen.findByText('Anna Nowak');
|
||
|
||
await user.click(screen.getByRole('button', { name: /Anna Nowak/ }));
|
||
await screen.findByRole('heading', { name: 'Anna Nowak' });
|
||
// „Archiwizuj” jest w grupie „Akcje” menu kontekstowego (domyślnie zwinięta)
|
||
await user.click(screen.getByRole('button', { name: 'Akcje' }));
|
||
await user.click(screen.getByRole('button', { name: 'Archiwizuj' }));
|
||
const dialog = await screen.findByRole('dialog');
|
||
expect(dialog).toBeInTheDocument();
|
||
await user.click(within(dialog).getByRole('button', { name: 'Archiwizuj' }));
|
||
expect(await screen.findByText('Relacja zarchiwizowana')).toBeInTheDocument();
|
||
expect(await screen.findByRole('heading', { name: 'Podopieczni' })).toBeInTheDocument();
|
||
});
|
||
|
||
it('akcja „Napisz wiadomość” otwiera wątek komunikatora z podopiecznym', async () => {
|
||
mockApi();
|
||
const user = userEvent.setup();
|
||
renderApp();
|
||
await loginToTrainees(user);
|
||
await screen.findByText('Anna Nowak');
|
||
|
||
await user.click(screen.getByRole('button', { name: /Anna Nowak/ }));
|
||
await screen.findByRole('heading', { name: 'Anna Nowak' });
|
||
await user.click(screen.getByRole('button', { name: 'Akcje' }));
|
||
await user.click(screen.getByRole('button', { name: 'Napisz wiadomość' }));
|
||
|
||
// jesteśmy w wątku: pole pisania wiadomości
|
||
expect(await screen.findByRole('textbox', { name: 'Treść wiadomości' })).toBeInTheDocument();
|
||
});
|
||
|
||
it('zakładka Postępy: karty per ćwiczenie (1RM/objętość) i objętość per partia', async () => {
|
||
mockApi();
|
||
const user = userEvent.setup();
|
||
renderApp();
|
||
await loginToTrainees(user);
|
||
await screen.findByText('Anna Nowak');
|
||
|
||
await user.click(screen.getByRole('button', { name: /Anna Nowak/ }));
|
||
await screen.findByRole('heading', { name: 'Anna Nowak' });
|
||
await user.click(screen.getByRole('button', { name: 'Postępy' }));
|
||
|
||
// karty per ćwiczenie: ostatnie 1RM i objętość
|
||
expect(await screen.findByText('Postępy per ćwiczenie')).toBeInTheDocument();
|
||
expect(screen.getByText('Przysiady')).toBeInTheDocument();
|
||
expect(screen.getByText('Wyciskanie')).toBeInTheDocument();
|
||
expect(screen.getByText('76 kg')).toBeInTheDocument();
|
||
expect(screen.getByText('600 kg')).toBeInTheDocument();
|
||
// volume per muscle group with the recommended range and out-of-range badge
|
||
expect(screen.getByText('Objętość per partia')).toBeInTheDocument();
|
||
expect(screen.getByText('poza zakresem')).toBeInTheDocument();
|
||
expect(screen.getAllByText('Klatka').length).toBeGreaterThan(0);
|
||
expect(screen.getAllByText('Nogi').length).toBeGreaterThan(0);
|
||
// pasek objętości: fakty/plany + zalecany zakres
|
||
expect(screen.getByText('10/12 · 10–18')).toBeInTheDocument();
|
||
expect(screen.getByText('4/10 · 10–20')).toBeInTheDocument();
|
||
});
|
||
|
||
it('zakładka Dyscyplina: heatmapa dni i log przesunięć', async () => {
|
||
mockApi();
|
||
const user = userEvent.setup();
|
||
renderApp();
|
||
await loginToTrainees(user);
|
||
await screen.findByText('Anna Nowak');
|
||
|
||
await user.click(screen.getByRole('button', { name: /Anna Nowak/ }));
|
||
await screen.findByRole('heading', { name: 'Anna Nowak' });
|
||
await user.click(screen.getByRole('button', { name: 'Dyscyplina' }));
|
||
|
||
expect(await screen.findByRole('heading', { name: 'Dyscyplina' })).toBeInTheDocument();
|
||
// heatmap legend
|
||
expect(screen.getByText('ukończony')).toBeInTheDocument();
|
||
expect(screen.getByText('pominięty')).toBeInTheDocument();
|
||
expect(screen.getByText('przesunięty')).toBeInTheDocument();
|
||
// moved-day log
|
||
expect(screen.getByText('Przesunięte dni')).toBeInTheDocument();
|
||
expect(screen.getByText('· choroba')).toBeInTheDocument();
|
||
});
|
||
|
||
it('zapamiętuje ostatnio wybraną zakładkę przy powrocie do podopiecznego', async () => {
|
||
mockApi();
|
||
const user = userEvent.setup();
|
||
renderApp();
|
||
await loginToTrainees(user);
|
||
await screen.findByText('Anna Nowak');
|
||
|
||
await user.click(screen.getByRole('button', { name: /Anna Nowak/ }));
|
||
await screen.findByRole('heading', { name: 'Anna Nowak' });
|
||
await user.click(screen.getByRole('button', { name: 'Dyscyplina' }));
|
||
await screen.findByText('Przesunięte dni');
|
||
|
||
// powrót na listę i ponowne wejście — zakładka Dyscyplina przywrócona bez klikania
|
||
await user.click(screen.getByRole('button', { name: 'Wstecz' }));
|
||
await screen.findByRole('heading', { name: 'Podopieczni' });
|
||
await user.click(screen.getByRole('button', { name: /Anna Nowak/ }));
|
||
expect(await screen.findByText('Przesunięte dni')).toBeInTheDocument();
|
||
});
|
||
});
|
||
|
||
describe('Invitations — zaproszenia', () => {
|
||
it('lista zaproszeń: otrzymane i wysłane', async () => {
|
||
mockApi();
|
||
const user = userEvent.setup();
|
||
renderApp();
|
||
expect(await screen.findByRole('heading', { name: 'FitOS' })).toBeInTheDocument();
|
||
const email = document.querySelector('input[type="email"]') as HTMLInputElement;
|
||
const password = document.querySelector('input[type="password"]') as HTMLInputElement;
|
||
await user.type(email, 'trener@test.local');
|
||
await user.type(password, 'Password123!');
|
||
await user.click(screen.getByRole('button', { name: 'Zaloguj' }));
|
||
expect(await screen.findByRole('heading', { name: 'Dashboard' })).toBeInTheDocument();
|
||
|
||
await user.click(screen.getByRole('link', { name: 'Zaproszenia' }));
|
||
expect(await screen.findByRole('heading', { name: 'Zaproszenia' })).toBeInTheDocument();
|
||
expect(screen.getByText('Otrzymane')).toBeInTheDocument();
|
||
expect(screen.getByText('Piotr Trener')).toBeInTheDocument();
|
||
expect(screen.getByText('Wysłane')).toBeInTheDocument();
|
||
expect(screen.getByText('Pola Podopieczna')).toBeInTheDocument();
|
||
expect(screen.getByRole('button', { name: 'Przyjmij' })).toBeInTheDocument();
|
||
expect(screen.getByRole('button', { name: 'Wycofaj' })).toBeInTheDocument();
|
||
});
|
||
|
||
it('przyjęcie i wycofanie zaproszenia', async () => {
|
||
mockApi();
|
||
const user = userEvent.setup();
|
||
renderApp();
|
||
expect(await screen.findByRole('heading', { name: 'FitOS' })).toBeInTheDocument();
|
||
const email = document.querySelector('input[type="email"]') as HTMLInputElement;
|
||
const password = document.querySelector('input[type="password"]') as HTMLInputElement;
|
||
await user.type(email, 'trener@test.local');
|
||
await user.type(password, 'Password123!');
|
||
await user.click(screen.getByRole('button', { name: 'Zaloguj' }));
|
||
expect(await screen.findByRole('heading', { name: 'Dashboard' })).toBeInTheDocument();
|
||
|
||
await user.click(screen.getByRole('link', { name: 'Zaproszenia' }));
|
||
await screen.findByRole('heading', { name: 'Zaproszenia' });
|
||
|
||
await user.click(screen.getByRole('button', { name: 'Przyjmij' }));
|
||
expect(await screen.findByText('Zaproszenie przyjęte')).toBeInTheDocument();
|
||
|
||
await user.click(screen.getByRole('button', { name: 'Wycofaj' }));
|
||
expect(await screen.findByText('Zaproszenie wycofane')).toBeInTheDocument();
|
||
});
|
||
});
|