From afbdc305ab9077436e2776f6a746d1eddec43c06 Mon Sep 17 00:00:00 2001 From: tisachi Date: Tue, 27 Oct 2026 06:32:31 +0100 Subject: [PATCH] =?UTF-8?q?Formatowanie:=20prettier=20na=20testach=20admin?= =?UTF-8?q?a=20(zwijanie=20i=20zawijanie=20linii)=20=E2=80=94=20wylacznie?= =?UTF-8?q?=20zmiany=20prezentacyjne,=20zero=20zmian=20logicznych=20(unit?= =?UTF-8?q?=2091=20i=20e2e=2053=20przechodza)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin/test/Equipment.test.tsx | 20 ++++- admin/test/Exercises.test.tsx | 80 ++++++++++++++++--- admin/test/FocusAreas.test.tsx | 22 +++++- admin/test/GymsList.test.tsx | 4 +- admin/test/UsersList.test.tsx | 4 +- admin/test/auth-store.test.ts | 5 +- admin/test/client.test.ts | 4 +- admin/test/e2e/announcements.spec.ts | 6 +- admin/test/e2e/mock-api.ts | 112 ++++++++++++++++++++++----- admin/test/e2e/verifications.spec.ts | 4 +- 10 files changed, 215 insertions(+), 46 deletions(-) diff --git a/admin/test/Equipment.test.tsx b/admin/test/Equipment.test.tsx index 5954d67..6ad6ae3 100644 --- a/admin/test/Equipment.test.tsx +++ b/admin/test/Equipment.test.tsx @@ -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) { diff --git a/admin/test/Exercises.test.tsx b/admin/test/Exercises.test.tsx index a41a8b1..096532d 100644 --- a/admin/test/Exercises.test.tsx +++ b/admin/test/Exercises.test.tsx @@ -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'); diff --git a/admin/test/FocusAreas.test.tsx b/admin/test/FocusAreas.test.tsx index 3993714..8710709 100644 --- a/admin/test/FocusAreas.test.tsx +++ b/admin/test/FocusAreas.test.tsx @@ -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] }); } diff --git a/admin/test/GymsList.test.tsx b/admin/test/GymsList.test.tsx index 3786eed..d4a88cb 100644 --- a/admin/test/GymsList.test.tsx +++ b/admin/test/GymsList.test.tsx @@ -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] }); }), ); diff --git a/admin/test/UsersList.test.tsx b/admin/test/UsersList.test.tsx index ddec7c0..62d3e43 100644 --- a/admin/test/UsersList.test.tsx +++ b/admin/test/UsersList.test.tsx @@ -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(); }); diff --git a/admin/test/auth-store.test.ts b/admin/test/auth-store.test.ts index 45fdaee..214848b 100644 --- a/admin/test/auth-store.test.ts +++ b/admin/test/auth-store.test.ts @@ -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(); diff --git a/admin/test/client.test.ts b/admin/test/client.test.ts index 982d264..72f5f31 100644 --- a/admin/test/client.test.ts +++ b/admin/test/client.test.ts @@ -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'); diff --git a/admin/test/e2e/announcements.spec.ts b/admin/test/e2e/announcements.spec.ts index 825d4c1..f3cfef5 100644 --- a/admin/test/e2e/announcements.spec.ts +++ b/admin/test/e2e/announcements.spec.ts @@ -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(); diff --git a/admin/test/e2e/mock-api.ts b/admin/test/e2e/mock-api.ts index ca0dc52..91a6451 100644 --- a/admin/test/e2e/mock-api.ts +++ b/admin/test/e2e/mock-api.ts @@ -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> } | 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) => diff --git a/admin/test/e2e/verifications.spec.ts b/admin/test/e2e/verifications.spec.ts index e337e8c..20a727b 100644 --- a/admin/test/e2e/verifications.spec.ts +++ b/admin/test/e2e/verifications.spec.ts @@ -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' });