Formatowanie: prettier na testach admina (zwijanie i zawijanie linii) — wylacznie zmiany prezentacyjne, zero zmian logicznych (unit 91 i e2e 53 przechodza)

This commit is contained in:
tisachi
2026-10-27 06:32:31 +01:00
parent 151becd5c4
commit afbdc305ab
10 changed files with 215 additions and 46 deletions

View File

@@ -9,8 +9,24 @@ import { useTopbarStore } from '../src/topbar/store';
import { useListSearch } from '../src/store/list-search';
const SEED = [
{ id: 'eq-1', name: 'Sztanga', kind: 'BARBELL', spec: { maxLoadKg: 100 }, description: 'Sztanga z talerzami.', exercisesCount: 5, gymsCount: 2 },
{ id: 'eq-2', name: 'Dywan', kind: 'OTHER', spec: null, description: 'Dywan do ćwiczeń.', exercisesCount: 0, gymsCount: 0 },
{
id: 'eq-1',
name: 'Sztanga',
kind: 'BARBELL',
spec: { maxLoadKg: 100 },
description: 'Sztanga z talerzami.',
exercisesCount: 5,
gymsCount: 2,
},
{
id: 'eq-2',
name: 'Dywan',
kind: 'OTHER',
spec: null,
description: 'Dywan do ćwiczeń.',
exercisesCount: 0,
gymsCount: 0,
},
];
function jsonResponse(status: number, body: unknown) {

View File

@@ -10,20 +10,62 @@ import { useTopbarStore } from '../src/topbar/store';
/** Otwarcie modala tworzenia przez akcję zarejestrowaną w topbarze (Topbar nie jest renderowany w testach). */
function openCreateDialog() {
const action = useTopbarStore.getState().config?.actions?.find((a) => a.label === 'Nowe ćwiczenie');
const action = useTopbarStore
.getState()
.config?.actions?.find((a) => a.label === 'Nowe ćwiczenie');
expect(action?.onClick).toBeTypeOf('function');
action!.onClick!();
}
const EQUIPMENT = [
{ id: 'eq-1', name: 'Sztanga', kind: 'BARBELL', spec: { maxLoadKg: 100 }, description: 'Sztanga z talerzami.', exercisesCount: 1, gymsCount: 0 },
{ id: 'eq-2', name: 'Dywan', kind: 'OTHER', spec: null, description: 'Dywan do ćwiczeń.', exercisesCount: 0, gymsCount: 0 },
{
id: 'eq-1',
name: 'Sztanga',
kind: 'BARBELL',
spec: { maxLoadKg: 100 },
description: 'Sztanga z talerzami.',
exercisesCount: 1,
gymsCount: 0,
},
{
id: 'eq-2',
name: 'Dywan',
kind: 'OTHER',
spec: null,
description: 'Dywan do ćwiczeń.',
exercisesCount: 0,
gymsCount: 0,
},
];
const FOCUS_AREAS = [
{ id: 'fa-1', name: 'Klatka piersiowa', muscle: 'chest', description: null, setsMin: null, setsMax: null, exercisesCount: 1 },
{ id: 'fa-2', name: 'Triceps', muscle: 'triceps', description: null, setsMin: null, setsMax: null, exercisesCount: 0 },
{ id: 'fa-3', name: 'Nogi', muscle: 'quads', description: null, setsMin: null, setsMax: null, exercisesCount: 0 },
{
id: 'fa-1',
name: 'Klatka piersiowa',
muscle: 'chest',
description: null,
setsMin: null,
setsMax: null,
exercisesCount: 1,
},
{
id: 'fa-2',
name: 'Triceps',
muscle: 'triceps',
description: null,
setsMin: null,
setsMax: null,
exercisesCount: 0,
},
{
id: 'fa-3',
name: 'Nogi',
muscle: 'quads',
description: null,
setsMin: null,
setsMax: null,
exercisesCount: 0,
},
];
const EXERCISE = {
@@ -50,7 +92,13 @@ const EXERCISE = {
};
/** Ćwiczenie używane w planach — do testu ostrzeżenia przy zmianie flag. */
const EXERCISE_IN_PLANS = { ...EXERCISE, id: 'ex-2', slug: 'squat', name: 'Przysiad', planExercisesCount: 2 };
const EXERCISE_IN_PLANS = {
...EXERCISE,
id: 'ex-2',
slug: 'squat',
name: 'Przysiad',
planExercisesCount: 2,
};
function jsonResponse(status: number, body: unknown) {
return new Response(JSON.stringify(body), {
@@ -84,7 +132,14 @@ function mockApi(extraExercises: unknown[] = []) {
const id = url.match(/\/admin\/exercises\/([^/]+)$/)?.[1];
if (method === 'GET') return jsonResponse(200, { exercises: state.exercises });
if (method === 'POST') {
const created = { id: `ex-${state.exercises.length + 1}`, slug: 'nowe', source: 'BUILTIN', equipment: [], planExercisesCount: 0, ...body };
const created = {
id: `ex-${state.exercises.length + 1}`,
slug: 'nowe',
source: 'BUILTIN',
equipment: [],
planExercisesCount: 0,
...body,
};
state.exercises.push(created);
return jsonResponse(201, { exercise: created });
}
@@ -185,7 +240,9 @@ describe('admin Exercises page', () => {
openCreateDialog();
const dialog = await screen.findByRole('dialog');
const [primarySelect, typeSelect] = within(dialog).getAllByRole('combobox');
expect(within(primarySelect).getByRole('option', { name: 'Klatka piersiowa (chest)' })).toBeInTheDocument();
expect(
within(primarySelect).getByRole('option', { name: 'Klatka piersiowa (chest)' }),
).toBeInTheDocument();
expect(within(typeSelect).getByRole('option', { name: 'Cardio' })).toBeInTheDocument();
});
@@ -197,7 +254,10 @@ describe('admin Exercises page', () => {
openCreateDialog();
const dialog = await screen.findByRole('dialog');
await user.type(within(dialog).getByPlaceholderText('np. Wyciskanie sztangi leżąc'), 'Bieganie');
await user.type(
within(dialog).getByPlaceholderText('np. Wyciskanie sztangi leżąc'),
'Bieganie',
);
const [primarySelect, typeSelect] = within(dialog).getAllByRole('combobox');
await user.selectOptions(primarySelect, 'quads');
await user.selectOptions(typeSelect, 'cardio');

View File

@@ -101,7 +101,12 @@ describe('admin FocusAreas page', () => {
vi.fn(async (input: RequestInfo | URL, init?: RequestInit) => {
const url = String(input);
const method = init?.method || 'GET';
if (method !== 'GET') requests.push({ method, url, body: init?.body ? JSON.parse(String(init.body)) : undefined });
if (method !== 'GET')
requests.push({
method,
url,
body: init?.body ? JSON.parse(String(init.body)) : undefined,
});
if (url.includes('/admin/focus-areas') && method === 'GET') {
return jsonResponse(200, { focusAreas: [A1, A2] });
}
@@ -112,7 +117,9 @@ describe('admin FocusAreas page', () => {
renderFocusAreas();
await screen.findByText('Klatka piersiowa');
const action = useTopbarStore.getState().config?.actions?.find((a) => a.label === 'Nowy obszar');
const action = useTopbarStore
.getState()
.config?.actions?.find((a) => a.label === 'Nowy obszar');
action!.onClick!();
const dialog = await screen.findByRole('dialog');
await user.type(within(dialog).getByPlaceholderText('np. Klatka piersiowa'), 'Barki');
@@ -121,7 +128,9 @@ describe('admin FocusAreas page', () => {
await user.type(within(dialog).getByPlaceholderText('np. 20'), '10');
await user.click(within(dialog).getByRole('button', { name: 'Dodaj' }));
expect(await screen.findByText('Minimalna liczba serii musi być mniejsza lub równa maksymalnej.')).toBeInTheDocument();
expect(
await screen.findByText('Minimalna liczba serii musi być mniejsza lub równa maksymalnej.'),
).toBeInTheDocument();
expect(requests.some((r) => r.method === 'POST')).toBe(false);
});
@@ -132,7 +141,12 @@ describe('admin FocusAreas page', () => {
vi.fn(async (input: RequestInfo | URL, init?: RequestInit) => {
const url = String(input);
const method = init?.method || 'GET';
if (method !== 'GET') requests.push({ method, url, body: init?.body ? JSON.parse(String(init.body)) : undefined });
if (method !== 'GET')
requests.push({
method,
url,
body: init?.body ? JSON.parse(String(init.body)) : undefined,
});
if (url.includes('/admin/focus-areas') && method === 'GET') {
return jsonResponse(200, { focusAreas: [A1, A2] });
}

View File

@@ -97,7 +97,9 @@ describe('admin GymsList page', () => {
vi.fn(async (input: RequestInfo | URL) => {
const url = String(input);
if (url.includes('/admin/gyms/occupancy'))
return jsonResponse(200, { gyms: [{ gymId: 'g1', name: 'Gym A', capacity: 50, count: 3 }] });
return jsonResponse(200, {
gyms: [{ gymId: 'g1', name: 'Gym A', capacity: 50, count: 3 }],
});
return jsonResponse(200, { gyms: [realGym] });
}),
);

View File

@@ -113,7 +113,9 @@ describe('admin UsersList page', () => {
});
it('shows an error when the users request fails', async () => {
mockFetchSequence(jsonResponse(500, { error: { code: 'INTERNAL', message: 'Błąd wewnętrzny' } }));
mockFetchSequence(
jsonResponse(500, { error: { code: 'INTERNAL', message: 'Błąd wewnętrzny' } }),
);
renderUsers();
expect(await screen.findByText(/Błąd: Błąd wewnętrzny/)).toBeInTheDocument();
});

View File

@@ -84,7 +84,10 @@ describe('admin auth store', () => {
it('logout clears the user and the token even when the API call fails', async () => {
useAuth.setState({ user: ADMIN });
setAccessToken('tok-2');
vi.stubGlobal('fetch', vi.fn(async () => new Response('', { status: 500 })));
vi.stubGlobal(
'fetch',
vi.fn(async () => new Response('', { status: 500 })),
);
await useAuth.getState().logout();
expect(useAuth.getState().user).toBeNull();
expect(getAccessToken()).toBeNull();

View File

@@ -59,9 +59,7 @@ describe('admin api client', () => {
});
it('throws an ApiError with status and server message on failure', async () => {
mockFetchSequence(
jsonResponse(403, { error: { code: 'FORBIDDEN', message: 'Admin only' } }),
);
mockFetchSequence(jsonResponse(403, { error: { code: 'FORBIDDEN', message: 'Admin only' } }));
let caught: unknown;
try {
await api('/admin/users');

View File

@@ -65,10 +65,10 @@ test('ogłoszenia: utworzenie nowego ogłoszenia platformy', async ({ page }) =>
await expect(page.getByRole('heading', { name: 'Brak ogłoszeń' })).toBeVisible();
await page.getByRole('button', { name: 'Nowe ogłoszenie' }).click();
await page.getByPlaceholder('np. Przerwa techniczna platformy').fill('Konserwacja aplikacji');
await page
.getByPlaceholder('np. Przerwa techniczna platformy')
.fill('Konserwacja aplikacji');
await page.getByPlaceholder('Treść ogłoszenia…').fill('W niedzielę aplikacja może wolniej działać.');
.getByPlaceholder('Treść ogłoszenia…')
.fill('W niedzielę aplikacja może wolniej działać.');
await page.getByRole('button', { name: 'Opublikuj' }).click();
await expect(page.getByText('Konserwacja aplikacji')).toBeVisible();

View File

@@ -53,8 +53,18 @@ export const TEST_EQUIPMENT: Equipment[] = [
];
export const TEST_GYM_PHOTOS = [
{ id: 'photo-1', url: '/gyms/gym-1/photos/photo-1', order: 0, createdAt: '2026-01-01T00:00:00.000Z' },
{ id: 'photo-2', url: '/gyms/gym-1/photos/photo-2', order: 1, createdAt: '2026-01-02T00:00:00.000Z' },
{
id: 'photo-1',
url: '/gyms/gym-1/photos/photo-1',
order: 0,
createdAt: '2026-01-01T00:00:00.000Z',
},
{
id: 'photo-2',
url: '/gyms/gym-1/photos/photo-2',
order: 1,
createdAt: '2026-01-02T00:00:00.000Z',
},
];
export const TEST_GYM: Gym = {
@@ -117,9 +127,23 @@ export const TEST_CLAIM_VERIFICATION: GymClaim = {
rejectReason: null,
decidedAt: null,
createdAt: '2026-08-25T10:00:00.000Z',
user: { id: 'user-v1', firstName: 'Marek', lastName: 'Wirtualny', email: 'alfa@fitos.pl', phone: '+48 600 100 200' },
user: {
id: 'user-v1',
firstName: 'Marek',
lastName: 'Wirtualny',
email: 'alfa@fitos.pl',
phone: '+48 600 100 200',
},
documentCount: 1,
documents: [{ id: 'doc-v1', originalName: 'akt-y.pdf', mimeType: 'application/pdf', sizeBytes: 1024, createdAt: '2026-08-25T10:00:00.000Z' }],
documents: [
{
id: 'doc-v1',
originalName: 'akt-y.pdf',
mimeType: 'application/pdf',
sizeBytes: 1024,
createdAt: '2026-08-25T10:00:00.000Z',
},
],
};
/** Wniosek o nową realną siłownię (PENDING). */
@@ -142,7 +166,13 @@ export const TEST_CLAIM_NEW: GymClaim = {
rejectReason: null,
decidedAt: null,
createdAt: '2026-08-26T12:00:00.000Z',
user: { id: 'user-n1', firstName: 'Anna', lastName: 'Nowa', email: 'nowa@fitos.pl', phone: '+48 700 300 400' },
user: {
id: 'user-n1',
firstName: 'Anna',
lastName: 'Nowa',
email: 'nowa@fitos.pl',
phone: '+48 700 300 400',
},
documentCount: 0,
documents: [],
};
@@ -198,12 +228,30 @@ export const TEST_EXERCISES = [
];
export const TEST_FOCUS_AREAS = [
{ id: 'fa-1', name: 'Klatka piersiowa', muscle: 'chest', description: 'Wyciskanie, rozpiętki.', exercisesCount: 1, createdAt: '2026-01-01T00:00:00.000Z', updatedAt: '2026-01-01T00:00:00.000Z' },
{ id: 'fa-2', name: 'Nogi', muscle: 'legs', description: 'Przysiady, wykroki.', exercisesCount: 0, createdAt: '2026-01-01T00:00:00.000Z', updatedAt: '2026-01-01T00:00:00.000Z' },
{
id: 'fa-1',
name: 'Klatka piersiowa',
muscle: 'chest',
description: 'Wyciskanie, rozpiętki.',
exercisesCount: 1,
createdAt: '2026-01-01T00:00:00.000Z',
updatedAt: '2026-01-01T00:00:00.000Z',
},
{
id: 'fa-2',
name: 'Nogi',
muscle: 'legs',
description: 'Przysiady, wykroki.',
exercisesCount: 0,
createdAt: '2026-01-01T00:00:00.000Z',
updatedAt: '2026-01-01T00:00:00.000Z',
},
];
export const TEST_FOCUS_CHAIN = {
develop: [{ muscle: 'chest', name: 'Klatka piersiowa', exercises: [{ id: 'pz-2', name: 'Wyciskanie' }] }],
develop: [
{ muscle: 'chest', name: 'Klatka piersiowa', exercises: [{ id: 'pz-2', name: 'Wyciskanie' }] },
],
canDo: [],
difficult: [],
avoid: [{ muscle: 'legs', name: 'Nogi', exercises: [{ id: 'pz-1', name: 'Przysiady' }] }],
@@ -314,7 +362,11 @@ export function mockApi(page: Page, opts: MockApiOptions = {}) {
authorId: TEST_ADMIN.id,
gymId: body.gymId ?? null,
gymName:
body.gymId === TEST_GYM.id ? TEST_GYM.name : body.gymId === TEST_GYM_2.id ? TEST_GYM_2.name : null,
body.gymId === TEST_GYM.id
? TEST_GYM.name
: body.gymId === TEST_GYM_2.id
? TEST_GYM_2.name
: null,
title: body.title ?? '',
body: body.body ?? '',
createdAt: new Date().toISOString(),
@@ -491,12 +543,15 @@ export function mockApi(page: Page, opts: MockApiOptions = {}) {
page.route('**/api/v1/admin/gyms', (route) => {
const list = (gyms as { gyms?: Array<Record<string, unknown>> } | null)?.gyms;
const body = list && gyms
? {
...gyms,
gyms: list.map((g) => (g.id === TEST_GYM.id ? { ...g, equipment: gymEquipmentState } : g)),
}
: gyms;
const body =
list && gyms
? {
...gyms,
gyms: list.map((g) =>
g.id === TEST_GYM.id ? { ...g, equipment: gymEquipmentState } : g,
),
}
: gyms;
return route.fulfill({
status: 200,
contentType: 'application/json',
@@ -736,7 +791,10 @@ export function mockApi(page: Page, opts: MockApiOptions = {}) {
});
page.route('**/api/v1/admin/gyms/claims/*', (route) => {
const id = route.request().url().match(/claims\/([^/?]+)$/)?.[1];
const id = route
.request()
.url()
.match(/claims\/([^/?]+)$/)?.[1];
const claim = claimsState.find((c) => c.id === id);
if (!claim) {
return route.fulfill({
@@ -753,17 +811,27 @@ export function mockApi(page: Page, opts: MockApiOptions = {}) {
});
page.route('**/api/v1/admin/gyms/claims/*/approve', (route) => {
const id = route.request().url().match(/claims\/([^/]+)\/approve$/)?.[1];
const id = route
.request()
.url()
.match(/claims\/([^/]+)\/approve$/)?.[1];
const claim = claimsState.find((c) => c.id === id);
if (claim && claim.status === 'PENDING') {
claim.status = 'APPROVED';
claim.decidedAt = new Date().toISOString();
}
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/admin/gyms/claims/*/reject', (route) => {
const id = route.request().url().match(/claims\/([^/]+)\/reject$/)?.[1];
const id = route
.request()
.url()
.match(/claims\/([^/]+)\/reject$/)?.[1];
const body = JSON.parse(route.request().postData() || '{}');
const claim = claimsState.find((c) => c.id === id);
if (claim && claim.status === 'PENDING') {
@@ -771,7 +839,11 @@ export function mockApi(page: Page, opts: MockApiOptions = {}) {
claim.rejectReason = body.reason ?? null;
claim.decidedAt = new Date().toISOString();
}
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/admin/gyms/claims/*/documents/*', (route) =>

View File

@@ -89,7 +89,9 @@ test('odrzucenie wniosku z powodem', async ({ page }) => {
const postPromise = page.waitForRequest(
(req) => req.url().includes('/admin/gyms/claims/claim-n1/reject') && req.method() === 'POST',
);
await page.getByPlaceholder('np. Brak potwierdzenia adresu prowadzenia siłowni').fill('Brak adresu');
await page
.getByPlaceholder('np. Brak potwierdzenia adresu prowadzenia siłowni')
.fill('Brak adresu');
await page.getByRole('button', { name: 'Odrzuć' }).click();
const req = await postPromise;
expect(req.postDataJSON()).toEqual({ reason: 'Brak adresu' });