Formatowanie: prettier na testach apki i porzadki w api/app (zwijanie i zawijanie linii, koncowki linii) — wylacznie zmiany prezentacyjne, zero zmian logicznych (testy unit i e2e przechodza na tym drzewie)
This commit is contained in:
@@ -457,8 +457,7 @@ export async function getGymPresenceTelemetry(
|
||||
where: { userId_gymId: { userId: caller.userId, gymId } },
|
||||
select: { roles: true },
|
||||
});
|
||||
if (!membership?.roles.includes('OWNER'))
|
||||
throw forbidden('You do not have access to this gym');
|
||||
if (!membership?.roles.includes('OWNER')) throw forbidden('You do not have access to this gym');
|
||||
}
|
||||
return getGymStats(prisma, gymId, range);
|
||||
}
|
||||
|
||||
@@ -49,7 +49,8 @@ function mockApi(active: unknown, calls: { activeSession: number }) {
|
||||
'fetch',
|
||||
vi.fn(async (input: RequestInfo | URL, init?: RequestInit) => {
|
||||
const url = String(input);
|
||||
if (url.includes('/auth/login')) return jsonResponse(200, { user: USER, accessToken: 'tok-1' });
|
||||
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')) {
|
||||
@@ -73,7 +74,9 @@ function mockApi(active: unknown, calls: { activeSession: number }) {
|
||||
date: '2026-08-24',
|
||||
status: 'PLANNED',
|
||||
dayOfWeek: 1,
|
||||
sessions: [{ id: 'sess-1', status: 'IN_PROGRESS', startedAt: ACTIVE_SESSION.startedAt }],
|
||||
sessions: [
|
||||
{ id: 'sess-1', status: 'IN_PROGRESS', startedAt: ACTIVE_SESSION.startedAt },
|
||||
],
|
||||
},
|
||||
});
|
||||
if (url.includes('/sessions/sess-1'))
|
||||
@@ -154,7 +157,9 @@ describe('Aktywna sesja — skrót „Trening”', () => {
|
||||
// nawigacja przez menu boczne otwiera dzień z aktywną sesją
|
||||
// (tytuł PageHeader z danymi dnia — unikalny, Layout ma osobny h1 „Dzień treningowy”)
|
||||
await user.click(sidebarLink);
|
||||
expect(await screen.findByRole('heading', { name: 'Poniedziałek · 24.08.2026' })).toBeInTheDocument();
|
||||
expect(
|
||||
await screen.findByRole('heading', { name: 'Poniedziałek · 24.08.2026' }),
|
||||
).toBeInTheDocument();
|
||||
// pasek sesji: status + start + postęp normy
|
||||
expect(await screen.findByText('W trakcie')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
@@ -41,7 +41,8 @@ function mockApi() {
|
||||
'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/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: null });
|
||||
@@ -115,7 +116,8 @@ function mockApiWithDay(active: unknown) {
|
||||
'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/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 });
|
||||
@@ -201,7 +203,9 @@ describe('Kalendarz — nawigacja miesiąca w top menu', () => {
|
||||
await user.click(screen.getByRole('button', { name: 'Poprzedni miesiąc' }));
|
||||
}
|
||||
const prevYearDec = monthStr(new Date(y - 1, 11, 1));
|
||||
expect(await screen.findByRole('button', { name: formatMonth(prevYearDec) })).toBeInTheDocument();
|
||||
expect(
|
||||
await screen.findByRole('button', { name: formatMonth(prevYearDec) }),
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('„idź do miesiąca”: siatka 12 miesięcy z wyborem roku', async () => {
|
||||
@@ -224,6 +228,8 @@ describe('Kalendarz — nawigacja miesiąca w top menu', () => {
|
||||
expect(screen.getByText(String(y + 1))).toBeInTheDocument();
|
||||
await user.click(screen.getByRole('button', { name: 'Sty', exact: true }));
|
||||
|
||||
expect(await screen.findByRole('button', { name: formatMonth(`${y + 1}-01`) })).toBeInTheDocument();
|
||||
expect(
|
||||
await screen.findByRole('button', { name: formatMonth(`${y + 1}-01`) }),
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -75,8 +75,28 @@ function sessionBody(
|
||||
planExercise: {
|
||||
id: 'pe-1',
|
||||
sets: [
|
||||
{ id: 'ps-1', index: 0, reps: 10, loadKg: 60, restSec: 90, rir: 2, cardioBpm: null, timeSec: null, speed: null },
|
||||
{ id: 'ps-2', index: 1, reps: 8, loadKg: 60, restSec: 90, rir: 2, cardioBpm: null, timeSec: null, speed: null },
|
||||
{
|
||||
id: 'ps-1',
|
||||
index: 0,
|
||||
reps: 10,
|
||||
loadKg: 60,
|
||||
restSec: 90,
|
||||
rir: 2,
|
||||
cardioBpm: null,
|
||||
timeSec: null,
|
||||
speed: null,
|
||||
},
|
||||
{
|
||||
id: 'ps-2',
|
||||
index: 1,
|
||||
reps: 8,
|
||||
loadKg: 60,
|
||||
restSec: 90,
|
||||
rir: 2,
|
||||
cardioBpm: null,
|
||||
timeSec: null,
|
||||
speed: null,
|
||||
},
|
||||
],
|
||||
},
|
||||
sets: [
|
||||
@@ -90,7 +110,15 @@ function sessionBody(
|
||||
difficulty: secondary('ss-1') ? 3 : null,
|
||||
note: notes['ss-1'] ?? null,
|
||||
},
|
||||
{ id: 'ss-2', planSetId: 'ps-2', index: indices['ss-2'] ?? 1, reps: reps['ss-2'], rir: secondary('ss-2') ? 2 : null, difficulty: secondary('ss-2') ? 3 : null, note: notes['ss-2'] ?? null },
|
||||
{
|
||||
id: 'ss-2',
|
||||
planSetId: 'ps-2',
|
||||
index: indices['ss-2'] ?? 1,
|
||||
reps: reps['ss-2'],
|
||||
rir: secondary('ss-2') ? 2 : null,
|
||||
difficulty: secondary('ss-2') ? 3 : null,
|
||||
note: notes['ss-2'] ?? null,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
@@ -100,7 +128,17 @@ function sessionBody(
|
||||
removed: false,
|
||||
exercise: { id: 'pz-2', name: 'Wyciskanie', primaryMuscle: 'chest' },
|
||||
planExercise: null,
|
||||
sets: [{ id: 'ss-3', planSetId: null, index: 0, reps: reps['ss-3'], rir: null, difficulty: null, note: notes['ss-3'] ?? null }],
|
||||
sets: [
|
||||
{
|
||||
id: 'ss-3',
|
||||
planSetId: null,
|
||||
index: 0,
|
||||
reps: reps['ss-3'],
|
||||
rir: null,
|
||||
difficulty: null,
|
||||
note: notes['ss-3'] ?? null,
|
||||
},
|
||||
],
|
||||
},
|
||||
...extra.map((e, i) => ({
|
||||
id: `se-x${i + 1}`,
|
||||
@@ -178,7 +216,8 @@ function mockApi(
|
||||
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: USER, accessToken: 'tok-1' });
|
||||
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'))
|
||||
@@ -200,7 +239,11 @@ function mockApi(
|
||||
killstreak: 0,
|
||||
activePlan: null,
|
||||
nextTraining: nextTraining
|
||||
? { dayId: 'day-1', date: '2026-08-24', exercises: [{ name: 'Przysiady', muscle: 'legs' }] }
|
||||
? {
|
||||
dayId: 'day-1',
|
||||
date: '2026-08-24',
|
||||
exercises: [{ name: 'Przysiady', muscle: 'legs' }],
|
||||
}
|
||||
: null,
|
||||
progress: null,
|
||||
extra: null,
|
||||
@@ -231,7 +274,10 @@ function mockApi(
|
||||
const exId = url.split('/sessions/exercises/')[1]?.split('/')[0] ?? '';
|
||||
const cat = added[parseInt(exId.replace('se-x', ''), 10) - 1];
|
||||
if (cat) addedSets[cat.id] = (addedSets[cat.id] ?? 0) + 1;
|
||||
return jsonResponse(200, { setId: `ss-ax-${exId}`, index: (cat ? addedSets[cat.id] : 1) - 1 });
|
||||
return jsonResponse(200, {
|
||||
setId: `ss-ax-${exId}`,
|
||||
index: (cat ? addedSets[cat.id] : 1) - 1,
|
||||
});
|
||||
}
|
||||
if (url.includes('/days/day-1'))
|
||||
return jsonResponse(200, {
|
||||
@@ -243,11 +289,7 @@ function mockApi(
|
||||
sessions: [
|
||||
{
|
||||
id: 'sess-1',
|
||||
status: completed
|
||||
? 'COMPLETED'
|
||||
: abandoned
|
||||
? 'ABANDONED'
|
||||
: 'IN_PROGRESS',
|
||||
status: completed ? 'COMPLETED' : abandoned ? 'ABANDONED' : 'IN_PROGRESS',
|
||||
startedAt: '2026-08-24T07:00:00.000Z',
|
||||
},
|
||||
],
|
||||
@@ -269,7 +311,10 @@ function mockApi(
|
||||
if (url.includes('/sessions/sets/')) {
|
||||
if (method === 'PATCH') {
|
||||
if (opts.hangSets) return new Promise<Response>(() => undefined);
|
||||
if (opts.failSets) return jsonResponse(500, { error: { code: 'SERVER_ERROR', message: 'awaria serwera' } });
|
||||
if (opts.failSets)
|
||||
return jsonResponse(500, {
|
||||
error: { code: 'SERVER_ERROR', message: 'awaria serwera' },
|
||||
});
|
||||
const body = JSON.parse(String(init?.body)) as {
|
||||
reps?: number | null;
|
||||
note?: string | null;
|
||||
@@ -313,7 +358,9 @@ async function openActiveDay(user: userEvent.User) {
|
||||
// link „Trening” w menu bocznym (aktywna sesja)
|
||||
const sidebarLink = screen.getByRole('link', { name: 'Trening', exact: true });
|
||||
await user.click(sidebarLink);
|
||||
expect(await screen.findByRole('heading', { name: 'Poniedziałek · 24.08.2026' })).toBeInTheDocument();
|
||||
expect(
|
||||
await screen.findByRole('heading', { name: 'Poniedziałek · 24.08.2026' }),
|
||||
).toBeInTheDocument();
|
||||
// pasek sesji: status + start + postęp normy
|
||||
expect(await screen.findByText('W trakcie')).toBeInTheDocument();
|
||||
}
|
||||
@@ -746,7 +793,10 @@ describe('Kolejka serii w sesji', () => {
|
||||
await screen.findByRole('heading', { name: 'Uzupełnij serię 1' });
|
||||
await fillNormAndConfirmSlider(user);
|
||||
// „Norma spełniona” nie czyści komentarza
|
||||
await user.type(screen.getByRole('textbox', { name: 'Komentarz do serii' }), 'ostatnia seria ciężka');
|
||||
await user.type(
|
||||
screen.getByRole('textbox', { name: 'Komentarz do serii' }),
|
||||
'ostatnia seria ciężka',
|
||||
);
|
||||
await user.click(screen.getByRole('button', { name: 'Zapisz' }));
|
||||
|
||||
// komentarz musi być widoczny też na wierszu serii (dowód zapisu), nie tylko w oknie
|
||||
@@ -970,7 +1020,11 @@ describe('Porzucenie sesji', () => {
|
||||
|
||||
it('pokazuje „Rozpocznij sesję”, gdy dzień jest zaplanowany, a ostatnia sesja porzucona', async () => {
|
||||
// np. po auto-porzuceniu sesji przez scheduler — dzień pozostaje PLANNED
|
||||
mockApi({ 'ss-1': null, 'ss-2': null, 'ss-3': null }, {}, { abandoned: true, daySkipped: false, nextTraining: true });
|
||||
mockApi(
|
||||
{ 'ss-1': null, 'ss-2': null, 'ss-3': null },
|
||||
{},
|
||||
{ abandoned: true, daySkipped: false, nextTraining: true },
|
||||
);
|
||||
const user = userEvent.setup();
|
||||
renderApp();
|
||||
expect(await screen.findByRole('heading', { name: 'FitOS' })).toBeInTheDocument();
|
||||
@@ -983,7 +1037,9 @@ describe('Porzucenie sesji', () => {
|
||||
|
||||
// dashboard: „Wykonaj trening” prowadzi do dnia z porzuconą sesją
|
||||
await user.click(screen.getByRole('button', { name: 'Wykonaj trening' }));
|
||||
expect(await screen.findByRole('heading', { name: 'Poniedziałek · 24.08.2026' })).toBeInTheDocument();
|
||||
expect(
|
||||
await screen.findByRole('heading', { name: 'Poniedziałek · 24.08.2026' }),
|
||||
).toBeInTheDocument();
|
||||
|
||||
// porzucona sesja (read-only) + dzień zaplanowany => można rozpocząć nową sesję
|
||||
expect(await screen.findByText('Porzucona', { exact: true })).toBeInTheDocument();
|
||||
|
||||
@@ -128,9 +128,7 @@ describe('Login page', () => {
|
||||
await user.type(email, 'jan@test.local');
|
||||
await user.type(password, 'wrong');
|
||||
await user.click(screen.getByRole('button', { name: 'Zaloguj' }));
|
||||
expect(
|
||||
await screen.findByText('Sesja wygasła — zaloguj się ponownie.'),
|
||||
).toBeInTheDocument();
|
||||
expect(await screen.findByText('Sesja wygasła — zaloguj się ponownie.')).toBeInTheDocument();
|
||||
expect(useAuth.getState().user).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -134,8 +134,7 @@ function mockApi(capture: Capture, opts: MockOpts) {
|
||||
if (url.includes('/me/active-session')) return jsonResponse(200, { session: null });
|
||||
if (url.endsWith('/me'))
|
||||
return jsonResponse(200, { user: opts.user, memberships: opts.memberships ?? [] });
|
||||
if (url.includes('/me/trainers'))
|
||||
return jsonResponse(200, { trainers: opts.trainers ?? [] });
|
||||
if (url.includes('/me/trainers')) return jsonResponse(200, { trainers: opts.trainers ?? [] });
|
||||
if (url.includes('/trainer/trainees'))
|
||||
return jsonResponse(200, { trainees: opts.trainees ?? [] });
|
||||
if (url.includes('/dashboard'))
|
||||
@@ -147,8 +146,7 @@ function mockApi(capture: Capture, opts: MockOpts) {
|
||||
extra: null,
|
||||
missing: null,
|
||||
});
|
||||
if (url.includes('/exercises'))
|
||||
return jsonResponse(200, { exercises: [] });
|
||||
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: [] });
|
||||
if (url.includes('/plans/shared-with-me'))
|
||||
@@ -270,15 +268,12 @@ describe('PlanDetail — udostępnianie planów (WP4)', () => {
|
||||
|
||||
it('dialog „Udostępnij plan”: podopieczni z checkboxem, share = POST /plans/:id/share', async () => {
|
||||
const capture: Capture = {};
|
||||
mockApi(
|
||||
capture,
|
||||
{
|
||||
user: OWNER,
|
||||
memberships: [{ gymId: 'gym-1', roles: ['TRAINER'] }],
|
||||
plans: [planDetail()],
|
||||
trainees: [TRAINEE],
|
||||
},
|
||||
);
|
||||
mockApi(capture, {
|
||||
user: OWNER,
|
||||
memberships: [{ gymId: 'gym-1', roles: ['TRAINER'] }],
|
||||
plans: [planDetail()],
|
||||
trainees: [TRAINEE],
|
||||
});
|
||||
const user = userEvent.setup();
|
||||
renderApp();
|
||||
await loginAndOpenPlans(user, OWNER.email);
|
||||
@@ -293,9 +288,7 @@ describe('PlanDetail — udostępnianie planów (WP4)', () => {
|
||||
|
||||
const checkbox = within(dialog).getByRole('checkbox') as HTMLInputElement;
|
||||
await user.click(checkbox);
|
||||
await waitFor(() =>
|
||||
expect(capture.shareBody).toMatchObject({ userId: 'trainee-1' }),
|
||||
);
|
||||
await waitFor(() => expect(capture.shareBody).toMatchObject({ userId: 'trainee-1' }));
|
||||
});
|
||||
|
||||
it('właściciel z udostępnionym planem: etykieta „udostępnione: …” w meta', async () => {
|
||||
|
||||
@@ -12,8 +12,10 @@ import type { DayAvailability } from '../src/api/types';
|
||||
|
||||
const day = (start: string, end: string): DayAvailability => ({ start, end });
|
||||
|
||||
const week = (...days: (DayAvailability | null)[]): (DayAvailability | null)[] =>
|
||||
[...days, ...Array(Math.max(0, 7 - days.length)).fill(null)];
|
||||
const week = (...days: (DayAvailability | null)[]): (DayAvailability | null)[] => [
|
||||
...days,
|
||||
...Array(Math.max(0, 7 - days.length)).fill(null),
|
||||
];
|
||||
|
||||
describe('formatAvailability', () => {
|
||||
it('returns empty string for null, empty and all-null input', () => {
|
||||
@@ -28,27 +30,62 @@ describe('formatAvailability', () => {
|
||||
});
|
||||
|
||||
it('groups consecutive days with identical hours', () => {
|
||||
expect(formatAvailability(week(day('18:00', '20:00'), day('18:00', '20:00'), day('18:00', '20:00'), day('18:00', '20:00'), day('18:00', '20:00')))).toBe(
|
||||
'Pon–Pt 18:00–20:00',
|
||||
);
|
||||
expect(
|
||||
formatAvailability(
|
||||
week(
|
||||
day('18:00', '20:00'),
|
||||
day('18:00', '20:00'),
|
||||
day('18:00', '20:00'),
|
||||
day('18:00', '20:00'),
|
||||
day('18:00', '20:00'),
|
||||
),
|
||||
),
|
||||
).toBe('Pon–Pt 18:00–20:00');
|
||||
});
|
||||
|
||||
it('separates a trailing day with different hours', () => {
|
||||
expect(formatAvailability(week(day('18:00', '20:00'), day('18:00', '20:00'), day('18:00', '20:00'), day('18:00', '20:00'), day('18:00', '20:00'), day('12:00', '14:00')))).toBe(
|
||||
'Pon–Pt 18:00–20:00, Sob 12:00–14:00',
|
||||
);
|
||||
expect(
|
||||
formatAvailability(
|
||||
week(
|
||||
day('18:00', '20:00'),
|
||||
day('18:00', '20:00'),
|
||||
day('18:00', '20:00'),
|
||||
day('18:00', '20:00'),
|
||||
day('18:00', '20:00'),
|
||||
day('12:00', '14:00'),
|
||||
),
|
||||
),
|
||||
).toBe('Pon–Pt 18:00–20:00, Sob 12:00–14:00');
|
||||
});
|
||||
|
||||
it('groups all seven days', () => {
|
||||
expect(formatAvailability(week(day('18:00', '20:00'), day('18:00', '20:00'), day('18:00', '20:00'), day('18:00', '20:00'), day('18:00', '20:00'), day('18:00', '20:00'), day('18:00', '20:00')))).toBe(
|
||||
'Pon–Niedz 18:00–20:00',
|
||||
);
|
||||
expect(
|
||||
formatAvailability(
|
||||
week(
|
||||
day('18:00', '20:00'),
|
||||
day('18:00', '20:00'),
|
||||
day('18:00', '20:00'),
|
||||
day('18:00', '20:00'),
|
||||
day('18:00', '20:00'),
|
||||
day('18:00', '20:00'),
|
||||
day('18:00', '20:00'),
|
||||
),
|
||||
),
|
||||
).toBe('Pon–Niedz 18:00–20:00');
|
||||
});
|
||||
|
||||
it('splits runs broken by a gap in the middle', () => {
|
||||
expect(formatAvailability(week(day('18:00', '20:00'), day('18:00', '20:00'), null, day('18:00', '20:00'), day('18:00', '20:00')))).toBe(
|
||||
'Pon–Wt 18:00–20:00, Czw–Pt 18:00–20:00',
|
||||
);
|
||||
expect(
|
||||
formatAvailability(
|
||||
week(
|
||||
day('18:00', '20:00'),
|
||||
day('18:00', '20:00'),
|
||||
null,
|
||||
day('18:00', '20:00'),
|
||||
day('18:00', '20:00'),
|
||||
),
|
||||
),
|
||||
).toBe('Pon–Wt 18:00–20:00, Czw–Pt 18:00–20:00');
|
||||
});
|
||||
|
||||
it('does not group alternating hours', () => {
|
||||
@@ -59,9 +96,11 @@ describe('formatAvailability', () => {
|
||||
});
|
||||
|
||||
it('does not group a wrap-around range (Pt + Pon)', () => {
|
||||
expect(formatAvailability(week(null, null, null, null, day('18:00', '20:00'), null, day('18:00', '20:00')))).toBe(
|
||||
'Pt 18:00–20:00, Niedz 18:00–20:00',
|
||||
);
|
||||
expect(
|
||||
formatAvailability(
|
||||
week(null, null, null, null, day('18:00', '20:00'), null, day('18:00', '20:00')),
|
||||
),
|
||||
).toBe('Pt 18:00–20:00, Niedz 18:00–20:00');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -74,13 +113,26 @@ describe('formatAvailabilityParts', () => {
|
||||
it('returns one entry per run of consecutive same-time days', () => {
|
||||
expect(
|
||||
formatAvailabilityParts(
|
||||
week(day('18:00', '20:00'), day('18:00', '20:00'), day('18:00', '20:00'), day('18:00', '20:00'), day('18:00', '20:00'), day('12:00', '14:00')),
|
||||
week(
|
||||
day('18:00', '20:00'),
|
||||
day('18:00', '20:00'),
|
||||
day('18:00', '20:00'),
|
||||
day('18:00', '20:00'),
|
||||
day('18:00', '20:00'),
|
||||
day('12:00', '14:00'),
|
||||
),
|
||||
),
|
||||
).toEqual(['Pon–Pt 18:00–20:00', 'Sob 12:00–14:00']);
|
||||
});
|
||||
|
||||
it('joins to the same string as formatAvailability', () => {
|
||||
const value = week(day('18:00', '20:00'), day('18:00', '20:00'), null, day('18:00', '20:00'), day('18:00', '20:00'));
|
||||
const value = week(
|
||||
day('18:00', '20:00'),
|
||||
day('18:00', '20:00'),
|
||||
null,
|
||||
day('18:00', '20:00'),
|
||||
day('18:00', '20:00'),
|
||||
);
|
||||
expect(formatAvailabilityParts(value).join(', ')).toBe(formatAvailability(value));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -76,7 +76,8 @@ function mockApi(dash: unknown) {
|
||||
'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/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: null });
|
||||
@@ -173,9 +174,7 @@ describe('Dashboard — statystyki motywacyjne', () => {
|
||||
|
||||
expect(await screen.findByText('96', { exact: true })).toBeInTheDocument();
|
||||
// Wykres WeekBars: dokładnie 12 słupków.
|
||||
expect(
|
||||
container.querySelectorAll('[data-testid="week-bars"] rect'),
|
||||
).toHaveLength(12);
|
||||
expect(container.querySelectorAll('[data-testid="week-bars"] rect')).toHaveLength(12);
|
||||
});
|
||||
|
||||
it('kropki killstreaka: 30 dni, wypełnione = skuteczne sesje', async () => {
|
||||
@@ -190,7 +189,9 @@ describe('Dashboard — statystyki motywacyjne', () => {
|
||||
const on = [...dots].filter((el) => (el.getAttribute('class') ?? '').includes('bg-accent'));
|
||||
expect(on).toHaveLength(3);
|
||||
// Ostatnie trzy kropki (wczoraj, przedwczoraj, dziś) — zgodne z mockiem.
|
||||
expect([...dots].slice(-3).every((el) => (el.getAttribute('class') ?? '').includes('bg-accent'))).toBe(true);
|
||||
expect(
|
||||
[...dots].slice(-3).every((el) => (el.getAttribute('class') ?? '').includes('bg-accent')),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it('bez dorobku (same zera, brak sesji): sekcja „Historia” ukryta', async () => {
|
||||
|
||||
@@ -13,10 +13,18 @@ const ACTIVE_SESSION = {
|
||||
test('aktywna sesja — skrót „Trening” w menu bocznym i na dashboardzie', async ({ page }) => {
|
||||
mockApi(page, { activeSession: { session: ACTIVE_SESSION } });
|
||||
page.route('**/api/v1/days/day-1', (route) =>
|
||||
route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ day: TEST_DAY }) }),
|
||||
route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({ day: TEST_DAY }),
|
||||
}),
|
||||
);
|
||||
page.route('**/api/v1/sessions/sess-1', (route) =>
|
||||
route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ session: TEST_SESSION }) }),
|
||||
route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({ session: TEST_SESSION }),
|
||||
}),
|
||||
);
|
||||
|
||||
await page.goto('/login');
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { test, expect } from './fixtures';
|
||||
import { mockApi } from './mock-api';
|
||||
|
||||
test('dzień treningowy zapisany jako lokalna północ renderuje się w prawidłowej komórce', async ({ page }) => {
|
||||
test('dzień treningowy zapisany jako lokalna północ renderuje się w prawidłowej komórce', async ({
|
||||
page,
|
||||
}) => {
|
||||
const now = new Date();
|
||||
const localMidnight = new Date(now.getFullYear(), now.getMonth(), now.getDate());
|
||||
const month = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}`;
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
import { test, expect } from './fixtures';
|
||||
import { mockDayExecution, mockDayExecutionAbandon, mockDayExecutionAbandonedPlanned } from './mock-api';
|
||||
import {
|
||||
mockDayExecution,
|
||||
mockDayExecutionAbandon,
|
||||
mockDayExecutionAbandonedPlanned,
|
||||
} from './mock-api';
|
||||
|
||||
test('wyszczególnia założenia zaplanowanej serii i oznacza ćwiczenie dodane', async ({ page }) => {
|
||||
mockDayExecution(page);
|
||||
@@ -150,7 +154,9 @@ test('przycisk „Norma spełniona” wypełnia wartości z planu', async ({ pag
|
||||
await expect(page.getByRole('button', { name: /Powtórzenia/ })).toContainText('10');
|
||||
});
|
||||
|
||||
test('nie pokazuje „Usuń” dla ćwiczenia z planu, ale pokazuje dla dodanego ponad plan', async ({ page }) => {
|
||||
test('nie pokazuje „Usuń” dla ćwiczenia z planu, ale pokazuje dla dodanego ponad plan', async ({
|
||||
page,
|
||||
}) => {
|
||||
mockDayExecution(page);
|
||||
|
||||
await page.goto('/login');
|
||||
@@ -168,7 +174,9 @@ test('nie pokazuje „Usuń” dla ćwiczenia z planu, ale pokazuje dla dodanego
|
||||
await expect(page.getByRole('button', { name: 'Usuń', exact: true })).toHaveCount(1);
|
||||
});
|
||||
|
||||
test('porzucenie sesji oznacza dzień jako pominięty i blokuje ponowne wykonanie', async ({ page }) => {
|
||||
test('porzucenie sesji oznacza dzień jako pominięty i blokuje ponowne wykonanie', async ({
|
||||
page,
|
||||
}) => {
|
||||
mockDayExecutionAbandon(page);
|
||||
|
||||
// logowanie (sesja w pamięci — nie można page.goto po zalogowaniu, bo straciłaby się)
|
||||
|
||||
@@ -15,7 +15,9 @@ async function openOwnedGymDetail(page: import('@playwright/test').Page) {
|
||||
await page.getByRole('link', { name: 'Żelazna Świątynia' }).click();
|
||||
}
|
||||
|
||||
test('właściciel zarządza galerią zdjęć siłowni REAL (upload/okładka/usuwanie)', async ({ page }) => {
|
||||
test('właściciel zarządza galerią zdjęć siłowni REAL (upload/okładka/usuwanie)', async ({
|
||||
page,
|
||||
}) => {
|
||||
const { mockApi } = await import('./mock-api');
|
||||
mockApi(page);
|
||||
await openOwnedGymDetail(page);
|
||||
|
||||
@@ -12,7 +12,12 @@ async function loginToInvitations(page: import('@playwright/test').Page) {
|
||||
}
|
||||
|
||||
test('lista zaproszeń: otrzymane i wysłane', async ({ page }) => {
|
||||
mockApi(page, { me: { user: TEST_USER, memberships: [{ gymId: TEST_GYM_OWNED.id, roles: ['TRAINER'], gym: TEST_GYM_OWNED }] } });
|
||||
mockApi(page, {
|
||||
me: {
|
||||
user: TEST_USER,
|
||||
memberships: [{ gymId: TEST_GYM_OWNED.id, roles: ['TRAINER'], gym: TEST_GYM_OWNED }],
|
||||
},
|
||||
});
|
||||
await loginToInvitations(page);
|
||||
|
||||
await expect(page.getByText('Otrzymane')).toBeVisible();
|
||||
@@ -29,7 +34,12 @@ test('lista zaproszeń: otrzymane i wysłane', async ({ page }) => {
|
||||
});
|
||||
|
||||
test('przyjęcie zaproszenia', async ({ page }) => {
|
||||
mockApi(page, { me: { user: TEST_USER, memberships: [{ gymId: TEST_GYM_OWNED.id, roles: ['TRAINER'], gym: TEST_GYM_OWNED }] } });
|
||||
mockApi(page, {
|
||||
me: {
|
||||
user: TEST_USER,
|
||||
memberships: [{ gymId: TEST_GYM_OWNED.id, roles: ['TRAINER'], gym: TEST_GYM_OWNED }],
|
||||
},
|
||||
});
|
||||
await loginToInvitations(page);
|
||||
await expect(page.getByText('Marek Trener')).toBeVisible();
|
||||
|
||||
@@ -38,7 +48,12 @@ test('przyjęcie zaproszenia', async ({ page }) => {
|
||||
});
|
||||
|
||||
test('odrzucenie zaproszenia', async ({ page }) => {
|
||||
mockApi(page, { me: { user: TEST_USER, memberships: [{ gymId: TEST_GYM_OWNED.id, roles: ['TRAINER'], gym: TEST_GYM_OWNED }] } });
|
||||
mockApi(page, {
|
||||
me: {
|
||||
user: TEST_USER,
|
||||
memberships: [{ gymId: TEST_GYM_OWNED.id, roles: ['TRAINER'], gym: TEST_GYM_OWNED }],
|
||||
},
|
||||
});
|
||||
await loginToInvitations(page);
|
||||
await expect(page.getByText('Marek Trener')).toBeVisible();
|
||||
|
||||
@@ -47,7 +62,12 @@ test('odrzucenie zaproszenia', async ({ page }) => {
|
||||
});
|
||||
|
||||
test('wycofanie wysłanego zaproszenia', async ({ page }) => {
|
||||
mockApi(page, { me: { user: TEST_USER, memberships: [{ gymId: TEST_GYM_OWNED.id, roles: ['TRAINER'], gym: TEST_GYM_OWNED }] } });
|
||||
mockApi(page, {
|
||||
me: {
|
||||
user: TEST_USER,
|
||||
memberships: [{ gymId: TEST_GYM_OWNED.id, roles: ['TRAINER'], gym: TEST_GYM_OWNED }],
|
||||
},
|
||||
});
|
||||
await loginToInvitations(page);
|
||||
await expect(page.getByText('Piotr Podopieczny')).toBeVisible();
|
||||
|
||||
|
||||
@@ -55,7 +55,9 @@ test('komunikator: sortowanie wg nieprzeczytanych i nazwy', async ({ page }) =>
|
||||
await page.getByRole('button', { name: 'Sortuj: Brak' }).click();
|
||||
await page.getByRole('button', { name: 'Nieprzeczytane' }).click();
|
||||
await expect(page.getByRole('button', { name: 'Sortuj: Nieprzeczytane' })).toBeVisible();
|
||||
expect(await page.getByText('Anna Nowak').evaluate((el) => el.getBoundingClientRect().top)).toBeLessThan(
|
||||
expect(
|
||||
await page.getByText('Anna Nowak').evaluate((el) => el.getBoundingClientRect().top),
|
||||
).toBeLessThan(
|
||||
await page.getByText('Piotr Kowal').evaluate((el) => el.getBoundingClientRect().top),
|
||||
);
|
||||
|
||||
@@ -74,14 +76,22 @@ test('komunikator: grupowanie wg roli z zakładkami Podopieczni/Trenerzy', async
|
||||
coachingId: 'coaching-1',
|
||||
role: 'trainer',
|
||||
other: { id: 'trainee-1', firstName: 'Anna', lastName: 'Nowak', nickname: null },
|
||||
lastMessage: { body: 'Dobrze się czuję', createdAt: '2026-08-24T10:00:00.000Z', senderId: 'trainee-1' },
|
||||
lastMessage: {
|
||||
body: 'Dobrze się czuję',
|
||||
createdAt: '2026-08-24T10:00:00.000Z',
|
||||
senderId: 'trainee-1',
|
||||
},
|
||||
unreadCount: 0,
|
||||
},
|
||||
{
|
||||
coachingId: 'coaching-3',
|
||||
role: 'trainee',
|
||||
other: { id: 'trainer-2', firstName: 'Tomasz', lastName: 'Kowalczyk', nickname: null },
|
||||
lastMessage: { body: 'Hej, omówmy plan', createdAt: '2026-09-01T09:00:00.000Z', senderId: 'trainer-2' },
|
||||
lastMessage: {
|
||||
body: 'Hej, omówmy plan',
|
||||
createdAt: '2026-09-01T09:00:00.000Z',
|
||||
senderId: 'trainer-2',
|
||||
},
|
||||
unreadCount: 0,
|
||||
},
|
||||
],
|
||||
@@ -103,7 +113,9 @@ test('komunikator: grupowanie wg roli z zakładkami Podopieczni/Trenerzy', async
|
||||
await expect(page.getByText('Anna Nowak')).not.toBeVisible();
|
||||
});
|
||||
|
||||
test('komunikator: karta kontekstu treningowego podopiecznego i mostek do panelu', async ({ page }) => {
|
||||
test('komunikator: karta kontekstu treningowego podopiecznego i mostek do panelu', async ({
|
||||
page,
|
||||
}) => {
|
||||
mockApi(page, { me: trainerMe() });
|
||||
await login(page);
|
||||
await page.getByRole('link', { name: /Komunikator/ }).click();
|
||||
@@ -139,7 +151,9 @@ test('wątek: wysyłka wiadomości', async ({ page }) => {
|
||||
await expect(page.getByText('Cześć Anno')).toBeVisible();
|
||||
});
|
||||
|
||||
test('wątek: załącznik sesji + ćwiczenia, karta w dymce, klik → historia z otwartą sesją', async ({ page }) => {
|
||||
test('wątek: załącznik sesji + ćwiczenia, karta w dymce, klik → historia z otwartą sesją', async ({
|
||||
page,
|
||||
}) => {
|
||||
mockApi(page, { me: trainerMe() });
|
||||
await login(page);
|
||||
await page.getByRole('link', { name: /Komunikator/ }).click();
|
||||
|
||||
@@ -25,7 +25,8 @@ function mockOwnerPlans(page: Page) {
|
||||
me: { user: TEST_USER, memberships: [{ gymId: 'gym-1', roles: ['TRAINER'] }] },
|
||||
});
|
||||
// Stateful: udostępnienia widoczne w detalu po POST (jak w realnym API).
|
||||
const shares: { userId: string; user: { id: string; firstName: string; lastName: string } }[] = [];
|
||||
const shares: { userId: string; user: { id: string; firstName: string; lastName: string } }[] =
|
||||
[];
|
||||
page.route('**/api/v1/plans/plan-1/share', (route) => {
|
||||
const req = route.request();
|
||||
if (req.method() === 'POST') {
|
||||
@@ -36,14 +37,22 @@ function mockOwnerPlans(page: Page) {
|
||||
user: { id: body.userId, firstName: 'Anna', lastName: 'Nowak' },
|
||||
});
|
||||
}
|
||||
return route.fulfill({ status: 201, contentType: 'application/json', body: JSON.stringify({ ok: true }) });
|
||||
return route.fulfill({
|
||||
status: 201,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({ ok: true }),
|
||||
});
|
||||
}
|
||||
if (req.method() === 'DELETE') {
|
||||
const userId = req.url().split('/').slice(-2, -1)[0];
|
||||
const i = shares.findIndex((s) => s.userId === userId);
|
||||
if (i >= 0) shares.splice(i, 1);
|
||||
}
|
||||
return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ ok: true }) });
|
||||
return route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({ ok: true }),
|
||||
});
|
||||
});
|
||||
page.route('**/api/v1/plans/plan-1', (route) =>
|
||||
route.fulfill({
|
||||
|
||||
@@ -126,7 +126,9 @@ test('komentarz pod ćwiczeniem w panelu podopiecznego (trener)', async ({ page
|
||||
await expect(page.getByText('Dobre formowanie')).toBeVisible();
|
||||
});
|
||||
|
||||
test('menu kontekstowe: „Napisz wiadomość” otwiera wątek komunikatora z podopiecznym', async ({ page }) => {
|
||||
test('menu kontekstowe: „Napisz wiadomość” otwiera wątek komunikatora z podopiecznym', async ({
|
||||
page,
|
||||
}) => {
|
||||
mockApi(page, { me: trainerMe() });
|
||||
await loginToTrainees(page);
|
||||
await expect(page.getByText('Anna Nowak')).toBeVisible();
|
||||
@@ -141,7 +143,9 @@ test('menu kontekstowe: „Napisz wiadomość” otwiera wątek komunikatora z p
|
||||
await expect(page.getByText('Dobrze się czuję')).toBeVisible();
|
||||
});
|
||||
|
||||
test('zakładka Postępy: karty per ćwiczenie (1RM/objętość) i objętość per partia', async ({ page }) => {
|
||||
test('zakładka Postępy: karty per ćwiczenie (1RM/objętość) i objętość per partia', async ({
|
||||
page,
|
||||
}) => {
|
||||
mockApi(page, { me: trainerMe() });
|
||||
await loginToTrainees(page);
|
||||
await expect(page.getByText('Anna Nowak')).toBeVisible();
|
||||
@@ -183,7 +187,9 @@ test('zakładka Dyscyplina: heatmapa dni i log przesunięć', async ({ page }) =
|
||||
await expect(page.getByText('· choroba')).toBeVisible();
|
||||
});
|
||||
|
||||
test('zakładka Kalendarz: trener widzi kalendarz podopiecznego z dniami treningowymi', async ({ page }) => {
|
||||
test('zakładka Kalendarz: trener widzi kalendarz podopiecznego z dniami treningowymi', async ({
|
||||
page,
|
||||
}) => {
|
||||
mockApi(page, { me: trainerMe() });
|
||||
await loginToTrainees(page);
|
||||
await expect(page.getByText('Anna Nowak')).toBeVisible();
|
||||
|
||||
@@ -129,7 +129,11 @@ function stubContactFetch(options: ContactMockOptions) {
|
||||
});
|
||||
if (path === '/me') return jsonResponse(200, { user: ME, memberships: [] });
|
||||
if (/^\/gyms\/[^/]+$/.test(path))
|
||||
return jsonResponse(200, { gym: { ...GYM, photos: [] }, roles: ['MEMBER'], isAdmin: false });
|
||||
return jsonResponse(200, {
|
||||
gym: { ...GYM, photos: [] },
|
||||
roles: ['MEMBER'],
|
||||
isAdmin: false,
|
||||
});
|
||||
throw new Error(`Unexpected fetch: ${path}`);
|
||||
}),
|
||||
);
|
||||
@@ -229,9 +233,7 @@ describe('Kontakt z właścicielami — skrzynka właściciela', () => {
|
||||
|
||||
expect(await screen.findByRole('textbox', { name: 'Treść wiadomości' })).toBeInTheDocument();
|
||||
await user.type(screen.getByRole('textbox', { name: 'Treść wiadomości' }), 'Codziennie 6–22');
|
||||
await waitFor(() =>
|
||||
user.click(screen.getByRole('button', { name: /Wyślij/ })),
|
||||
);
|
||||
await waitFor(() => user.click(screen.getByRole('button', { name: /Wyślij/ })));
|
||||
expect(await screen.findByText('Codziennie 6–22')).toBeInTheDocument();
|
||||
expect(posts.some((p) => p.url.includes('/gym-contact/conversations/c1/messages'))).toBe(true);
|
||||
});
|
||||
|
||||
@@ -33,7 +33,12 @@ function statsBody(overrides: { presence?: Record<string, unknown> } = {}) {
|
||||
...overrides.presence,
|
||||
},
|
||||
members: { total: 12, byRole: { OWNER: 1, TRAINER: 2, MEMBER: 9 }, newInRange: 4 },
|
||||
activity: { sessionsStarted: 20, sessionsCompleted: 17, sessionsAbandoned: 3, uniqueExercisers: 6 },
|
||||
activity: {
|
||||
sessionsStarted: 20,
|
||||
sessionsCompleted: 17,
|
||||
sessionsAbandoned: 3,
|
||||
uniqueExercisers: 6,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,11 @@ const CONVERSATIONS: Conversation[] = [
|
||||
coachingId: 'coaching-1',
|
||||
role: 'trainer',
|
||||
other: { id: 'trainee-1', firstName: 'Anna', lastName: 'Nowak' },
|
||||
lastMessage: { body: 'Dobrze się czuję', createdAt: '2026-08-24T10:00:00.000Z', senderId: 'trainee-1' },
|
||||
lastMessage: {
|
||||
body: 'Dobrze się czuję',
|
||||
createdAt: '2026-08-24T10:00:00.000Z',
|
||||
senderId: 'trainee-1',
|
||||
},
|
||||
unreadCount: 2,
|
||||
},
|
||||
{
|
||||
@@ -46,7 +50,11 @@ const CONVERSATIONS: Conversation[] = [
|
||||
coachingId: 'coaching-3',
|
||||
role: 'trainee',
|
||||
other: { id: 'trainer-2', firstName: 'Tomasz', lastName: 'Kowalczyk' },
|
||||
lastMessage: { body: 'Hej, omówmy plan', createdAt: '2026-09-01T09:00:00.000Z', senderId: 'trainer-2' },
|
||||
lastMessage: {
|
||||
body: 'Hej, omówmy plan',
|
||||
createdAt: '2026-09-01T09:00:00.000Z',
|
||||
senderId: 'trainer-2',
|
||||
},
|
||||
unreadCount: 1,
|
||||
},
|
||||
];
|
||||
@@ -64,13 +72,19 @@ function mockApi(conversations: Conversation[]) {
|
||||
'fetch',
|
||||
vi.fn(async (input: RequestInfo | URL, init?: RequestInit) => {
|
||||
const url = String(input);
|
||||
if (url.includes('/auth/login')) return jsonResponse(200, { user: TRAINER, accessToken: 'tok-1' });
|
||||
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')) return jsonResponse(200, { conversations });
|
||||
if (url.includes('/me')) return jsonResponse(200, { user: TRAINER, memberships: [] });
|
||||
if (url.includes('/dashboard'))
|
||||
return jsonResponse(200, { killstreak: 0, activePlan: null, nextTraining: null, progress: null });
|
||||
return jsonResponse(200, {
|
||||
killstreak: 0,
|
||||
activePlan: null,
|
||||
nextTraining: null,
|
||||
progress: null,
|
||||
});
|
||||
if (url.includes('/trainer/trainees')) return jsonResponse(200, { trainees: [] });
|
||||
if (url.includes('/trainer/invitations')) return jsonResponse(200, { invitations: [] });
|
||||
if (url.includes('/gyms/invitations')) return jsonResponse(200, { invitations: [] });
|
||||
@@ -143,14 +157,22 @@ describe('Messages — lista rozmów', () => {
|
||||
coachingId: 'coaching-2',
|
||||
role: 'trainer',
|
||||
other: { id: 'trainee-2', firstName: 'Piotr', lastName: 'Kowal' },
|
||||
lastMessage: { body: 'Do zobaczenia', createdAt: '2026-08-25T09:00:00.000Z', senderId: 'trainer-1' },
|
||||
lastMessage: {
|
||||
body: 'Do zobaczenia',
|
||||
createdAt: '2026-08-25T09:00:00.000Z',
|
||||
senderId: 'trainer-1',
|
||||
},
|
||||
unreadCount: 0,
|
||||
},
|
||||
{
|
||||
coachingId: 'coaching-1',
|
||||
role: 'trainer',
|
||||
other: { id: 'trainee-1', firstName: 'Anna', lastName: 'Nowak' },
|
||||
lastMessage: { body: 'Dobrze się czuję', createdAt: '2026-08-24T10:00:00.000Z', senderId: 'trainee-1' },
|
||||
lastMessage: {
|
||||
body: 'Dobrze się czuję',
|
||||
createdAt: '2026-08-24T10:00:00.000Z',
|
||||
senderId: 'trainee-1',
|
||||
},
|
||||
unreadCount: 0,
|
||||
},
|
||||
];
|
||||
@@ -188,7 +210,9 @@ describe('Messages — lista rozmów', () => {
|
||||
|
||||
// domyślnie: kolejność z API (Anna, Piotr, Tomasz)
|
||||
const rows = () =>
|
||||
screen.getAllByRole('button').filter((b) => /Anna Nowak|Piotr Kowal|Tomasz Kowalczyk/.test(b.textContent ?? ''));
|
||||
screen
|
||||
.getAllByRole('button')
|
||||
.filter((b) => /Anna Nowak|Piotr Kowal|Tomasz Kowalczyk/.test(b.textContent ?? ''));
|
||||
expect(rows()[0]).toHaveTextContent('Anna Nowak');
|
||||
|
||||
await user.click(screen.getByRole('button', { name: 'Sortuj: Brak' }));
|
||||
@@ -210,7 +234,9 @@ describe('Messages — lista rozmów', () => {
|
||||
await user.click(screen.getByRole('button', { name: 'Sortuj: Brak' }));
|
||||
await user.click(screen.getByRole('button', { name: 'Nazwa' }));
|
||||
|
||||
const rows = screen.getAllByRole('button').filter((b) => /Anna Nowak|Piotr Kowal|Tomasz Kowalczyk/.test(b.textContent ?? ''));
|
||||
const rows = screen
|
||||
.getAllByRole('button')
|
||||
.filter((b) => /Anna Nowak|Piotr Kowal|Tomasz Kowalczyk/.test(b.textContent ?? ''));
|
||||
expect(rows[0]).toHaveTextContent('Anna Nowak');
|
||||
expect(rows[1]).toHaveTextContent('Piotr Kowal');
|
||||
expect(rows[2]).toHaveTextContent('Tomasz Kowalczyk');
|
||||
|
||||
@@ -99,7 +99,14 @@ function mockApi(opts: StubOpts = {}) {
|
||||
if (url.includes('/me/presence/history')) return jsonResponse(200, { visits: [] });
|
||||
if (url.includes('/me/presence/stats'))
|
||||
return jsonResponse(200, {
|
||||
stats: { visits: 0, avgStayMinutes: null, heatmap: [], topGyms: [], peak: 0, topEquipment: [] },
|
||||
stats: {
|
||||
visits: 0,
|
||||
avgStayMinutes: null,
|
||||
heatmap: [],
|
||||
topGyms: [],
|
||||
peak: 0,
|
||||
topEquipment: [],
|
||||
},
|
||||
});
|
||||
if (url.includes('/me/presence/check-out') && method === 'POST') {
|
||||
current = null;
|
||||
@@ -246,7 +253,9 @@ describe('Modal rozpoczęcia treningu', () => {
|
||||
/>,
|
||||
);
|
||||
const tester = userEvent.setup();
|
||||
await tester.click(await screen.findByRole('button', { name: 'Zmień siłownię planu na Mega Gym' }));
|
||||
await tester.click(
|
||||
await screen.findByRole('button', { name: 'Zmień siłownię planu na Mega Gym' }),
|
||||
);
|
||||
expect(onChangePlanGym).toHaveBeenCalledWith('gym-2');
|
||||
});
|
||||
|
||||
|
||||
@@ -49,7 +49,11 @@ const GYM_2 = {
|
||||
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 } },
|
||||
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'],
|
||||
@@ -62,7 +66,11 @@ const TRAINEE_DETAIL = {
|
||||
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' }] },
|
||||
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',
|
||||
@@ -120,7 +128,8 @@ function mockApi() {
|
||||
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/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'))
|
||||
@@ -136,7 +145,11 @@ function mockApi() {
|
||||
coachingId: 'coaching-1',
|
||||
role: 'trainer',
|
||||
other: { id: 'trainee-1', firstName: 'Anna', lastName: 'Nowak', nickname: null },
|
||||
lastMessage: { body: 'Dobrze się czuję', createdAt: '2026-08-24T10:00:00.000Z', senderId: 'trainee-1' },
|
||||
lastMessage: {
|
||||
body: 'Dobrze się czuję',
|
||||
createdAt: '2026-08-24T10:00:00.000Z',
|
||||
senderId: 'trainee-1',
|
||||
},
|
||||
unreadCount: 1,
|
||||
},
|
||||
],
|
||||
@@ -161,14 +174,26 @@ function mockApi() {
|
||||
{
|
||||
id: 'inv-1',
|
||||
direction: 'received',
|
||||
other: { id: 'trainer-2', firstName: 'Piotr', lastName: 'Trener', email: 'p.trener@test.local', phone: null },
|
||||
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 },
|
||||
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',
|
||||
},
|
||||
@@ -237,7 +262,15 @@ function mockApi() {
|
||||
name: 'Przysiady',
|
||||
muscle: 'legs',
|
||||
isExtra: false,
|
||||
sets: [{ index: 0, reps: 10, rir: 2, difficulty: 3, planned: { reps: 10, loadKg: 60, restSec: 90, rir: 2 } }],
|
||||
sets: [
|
||||
{
|
||||
index: 0,
|
||||
reps: 10,
|
||||
rir: 2,
|
||||
difficulty: 3,
|
||||
planned: { reps: 10, loadKg: 60, restSec: 90, rir: 2 },
|
||||
},
|
||||
],
|
||||
comments: [],
|
||||
},
|
||||
{
|
||||
@@ -264,7 +297,15 @@ function mockApi() {
|
||||
name: 'Przysiady',
|
||||
muscle: 'legs',
|
||||
isExtra: false,
|
||||
sets: [{ index: 0, reps: 8, rir: 3, difficulty: 3, planned: { reps: 10, loadKg: 60, restSec: 90, rir: 2 } }],
|
||||
sets: [
|
||||
{
|
||||
index: 0,
|
||||
reps: 8,
|
||||
rir: 3,
|
||||
difficulty: 3,
|
||||
planned: { reps: 10, loadKg: 60, restSec: 90, rir: 2 },
|
||||
},
|
||||
],
|
||||
comments: [],
|
||||
},
|
||||
],
|
||||
@@ -292,7 +333,10 @@ function mockApi() {
|
||||
],
|
||||
});
|
||||
if (url.includes('/trainer/trainees/trainee-1'))
|
||||
return jsonResponse(method === 'DELETE' ? 204 : 200, method === 'DELETE' ? {} : TRAINEE_DETAIL);
|
||||
return jsonResponse(
|
||||
method === 'DELETE' ? 204 : 200,
|
||||
method === 'DELETE' ? {} : TRAINEE_DETAIL,
|
||||
);
|
||||
if (url.includes('/trainer/trainees'))
|
||||
return jsonResponse(200, { trainees: [TRAINEE, TRAINEE_2, TRAINEE_3, TRAINEE_4] });
|
||||
if (url.includes('/trainer/search')) return jsonResponse(200, { users: [CANDIDATE] });
|
||||
@@ -413,23 +457,53 @@ describe('Trainees — lista i szczegóły', () => {
|
||||
|
||||
// lista płaska (grupowanie wyłączone) — sortowanie globalne
|
||||
// domyślnie: „Brak” — kolejność z API (Anna, Piotr, Zofia, Tomek)
|
||||
expect(rowOrder()).toEqual(['Anna Nowak', 'Piotr Kowal', 'Zofia Wiśniewska', 'Tomek Kowalczyk']);
|
||||
expect(rowOrder()).toEqual([
|
||||
'Anna Nowak',
|
||||
'Piotr Kowal',
|
||||
'Zofia Wiśniewska',
|
||||
'Tomek Kowalczyk',
|
||||
]);
|
||||
|
||||
await pickSort('Killstreak');
|
||||
expect(rowOrder()).toEqual(['Zofia Wiśniewska', 'Anna Nowak', 'Tomek Kowalczyk', 'Piotr Kowal']);
|
||||
expect(rowOrder()).toEqual([
|
||||
'Zofia Wiśniewska',
|
||||
'Anna Nowak',
|
||||
'Tomek Kowalczyk',
|
||||
'Piotr Kowal',
|
||||
]);
|
||||
|
||||
await pickSort('Nazwa');
|
||||
expect(rowOrder()).toEqual(['Anna Nowak', 'Piotr Kowal', 'Tomek Kowalczyk', 'Zofia Wiśniewska']);
|
||||
expect(rowOrder()).toEqual([
|
||||
'Anna Nowak',
|
||||
'Piotr Kowal',
|
||||
'Tomek Kowalczyk',
|
||||
'Zofia Wiśniewska',
|
||||
]);
|
||||
|
||||
await pickSort('Ostatnia sesja');
|
||||
expect(rowOrder()).toEqual(['Zofia Wiśniewska', 'Anna Nowak', 'Piotr Kowal', 'Tomek Kowalczyk']);
|
||||
expect(rowOrder()).toEqual([
|
||||
'Zofia Wiśniewska',
|
||||
'Anna Nowak',
|
||||
'Piotr Kowal',
|
||||
'Tomek Kowalczyk',
|
||||
]);
|
||||
|
||||
await pickSort('Flagi');
|
||||
expect(rowOrder()).toEqual(['Anna Nowak', 'Piotr Kowal', 'Tomek Kowalczyk', 'Zofia Wiśniewska']);
|
||||
expect(rowOrder()).toEqual([
|
||||
'Anna Nowak',
|
||||
'Piotr Kowal',
|
||||
'Tomek Kowalczyk',
|
||||
'Zofia Wiśniewska',
|
||||
]);
|
||||
|
||||
// „Brak” — powrót do kolejności z API
|
||||
await pickSort('Brak');
|
||||
expect(rowOrder()).toEqual(['Anna Nowak', 'Piotr Kowal', 'Zofia Wiśniewska', 'Tomek Kowalczyk']);
|
||||
expect(rowOrder()).toEqual([
|
||||
'Anna Nowak',
|
||||
'Piotr Kowal',
|
||||
'Zofia Wiśniewska',
|
||||
'Tomek Kowalczyk',
|
||||
]);
|
||||
});
|
||||
|
||||
it('grupowanie wg siłowni (toggle w filtrach): podopieczny z dwóch siłowni w obu grupach', async () => {
|
||||
@@ -581,7 +655,9 @@ describe('Trainees — lista i szczegóły', () => {
|
||||
await screen.findByRole('heading', { name: 'Anna Nowak' });
|
||||
await user.click(screen.getByRole('button', { name: 'Akcje' }));
|
||||
// akcja z topmenu (nie z karty Rozmowa w treści)
|
||||
await user.click(within(screen.getByRole('banner')).getByRole('button', { name: 'Napisz wiadomość' }));
|
||||
await user.click(
|
||||
within(screen.getByRole('banner')).getByRole('button', { name: 'Napisz wiadomość' }),
|
||||
);
|
||||
|
||||
// jesteśmy w wątku: pole pisania wiadomości
|
||||
expect(await screen.findByRole('textbox', { name: 'Treść wiadomości' })).toBeInTheDocument();
|
||||
|
||||
Reference in New Issue
Block a user