From ca2998f2b7506859eda469b0bba8eb3ce0c2ae1c Mon Sep 17 00:00:00 2001 From: tisachi Date: Fri, 11 Sep 2026 20:32:59 +0200 Subject: [PATCH] =?UTF-8?q?Plany:=20zapis=20planu=20jako=20akcja=20'Zatwie?= =?UTF-8?q?rd=C5=BA=20plan'=20w=20menu=20kontekstowym=20(stopka=20zostawia?= =?UTF-8?q?=20Anuluj)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/pages/plans/PlanEditor.tsx | 21 ++++++++++++++------- app/test/PlanEditor.test.tsx | 7 +++---- app/test/e2e/plans-mobile.spec.ts | 4 +++- app/test/e2e/plans.spec.ts | 5 +++-- app/test/e2e/trainee-plans.spec.ts | 1 + app/test/trainee-plans.test.tsx | 2 +- 6 files changed, 25 insertions(+), 15 deletions(-) diff --git a/app/src/pages/plans/PlanEditor.tsx b/app/src/pages/plans/PlanEditor.tsx index daab1f6..ed0d9b7 100644 --- a/app/src/pages/plans/PlanEditor.tsx +++ b/app/src/pages/plans/PlanEditor.tsx @@ -12,7 +12,7 @@ import { useExercises, type PlanWeekInput, } from '../../api/queries'; -import { CalendarX } from 'lucide-react'; +import { CalendarX, Check } from 'lucide-react'; import { BackButton, Button, @@ -73,6 +73,8 @@ export default function PlanEditor() { ? `/plans/${planIdParam}` : '/plans'; + const [saving, setSaving] = useState(false); + const requestExit = () => { if (editor.dirty) setConfirmExit(true); else navigate(backPath); @@ -93,6 +95,15 @@ export default function PlanEditor() { : '/plans', // mobile „<” w dolnym pasku topmenu: potwierdzenie przy niezapisanych zmianach onBack: editor.dirty ? requestExit : undefined, + // akcja główna w menu kontekstowym (grupa ⋯; na lg+ inline w nagłówku) + actions: [ + { + label: 'Zatwierdź plan', + icon: Check, + onClick: () => save(), + disabled: saving, + }, + ], }); // Inicjalizacja trybu edycji po załadowaniu danych (useEffect, nie setState during render) @@ -103,7 +114,6 @@ export default function PlanEditor() { }, [isEdit, planData, editor]); const [error, setError] = useState(''); - const [saving, setSaving] = useState(false); const [activeWeek, setActiveWeek] = useState(0); const [resultsOpenKey, setResultsOpenKey] = useState(null); const [confirmExit, setConfirmExit] = useState(false); @@ -403,11 +413,8 @@ export default function PlanEditor() { · {weekCountLabel(totals.emptyWeeks)} bez ćwiczeń )} -
- -
diff --git a/app/test/PlanEditor.test.tsx b/app/test/PlanEditor.test.tsx index 5cb1dee..618ca82 100644 --- a/app/test/PlanEditor.test.tsx +++ b/app/test/PlanEditor.test.tsx @@ -51,8 +51,7 @@ function mockApi(capture: Capture) { 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 }); - if (url.endsWith('/me')) - return jsonResponse(200, { user: USER, memberships: [] }); + if (url.endsWith('/me')) return jsonResponse(200, { user: USER, memberships: [] }); if (url.includes('/exercises')) return jsonResponse(200, { exercises: EXERCISES }); if (url.includes('/dashboard')) return jsonResponse(200, { @@ -155,7 +154,7 @@ describe('PlanEditor — data startu i menu kontekstowe', () => { const title = screen.getByPlaceholderText('np. Plan masowy 8-tygodniowy'); await user.type(title, 'Plan testowy'); - await user.click(screen.getByRole('button', { name: 'Utwórz plan' })); + await user.click(screen.getByRole('button', { name: 'Zatwierdź plan' })); await waitFor(() => expect(capture.createPlanBody).toMatchObject({ title: 'Plan testowy', @@ -208,7 +207,7 @@ describe('PlanEditor — data startu i menu kontekstowe', () => { const title = screen.getByPlaceholderText('np. Plan masowy 8-tygodniowy'); await user.type(title, 'Plan szkic'); - await user.click(screen.getByRole('button', { name: 'Utwórz plan' })); + await user.click(screen.getByRole('button', { name: 'Zatwierdź plan' })); await waitFor(() => expect(capture.createPlanBody).toBeDefined()); expect(capture.createPlanBody).not.toHaveProperty('startDate'); }); diff --git a/app/test/e2e/plans-mobile.spec.ts b/app/test/e2e/plans-mobile.spec.ts index 6cfdbaf..05134a8 100644 --- a/app/test/e2e/plans-mobile.spec.ts +++ b/app/test/e2e/plans-mobile.spec.ts @@ -54,7 +54,9 @@ test('mobile: tworzenie planu — bezpieczny tap dnia, bottom sheet, edycja seri await page.getByRole('button', { name: '+ dodaj ćwiczenie…' }).click(); await page.getByRole('option', { name: /Wyciskanie/ }).click(); await page.getByPlaceholder('np. Plan masowy 8-tygodniowy').fill('Plan mobile'); - await page.getByRole('button', { name: 'Utwórz plan' }).click(); + // „Zatwierdź plan" w grupie „Akcje" dolnego paska + await page.getByRole('button', { name: 'Akcje' }).click(); + await page.getByRole('button', { name: 'Zatwierdź plan' }).click(); // po utworzeniu — szczegóły planu (mock zwraca „Plan e2e”) await expect(page.getByRole('heading', { name: 'Plan e2e' })).toBeVisible(); diff --git a/app/test/e2e/plans.spec.ts b/app/test/e2e/plans.spec.ts index 05b4e3a..8786669 100644 --- a/app/test/e2e/plans.spec.ts +++ b/app/test/e2e/plans.spec.ts @@ -43,7 +43,8 @@ test('formularz nowego planu ma wybór tygodnia startu i przycisk „Wstecz” w await page.getByPlaceholder('np. Plan masowy 8-tygodniowy').fill('Plan e2e'); await page.getByRole('button', { name: 'Następny miesiąc' }).click(); await page.getByRole('button', { name: '20', exact: true }).click(); - await page.getByRole('button', { name: 'Utwórz plan' }).click(); + // akcja główna w menu kontekstowym (lg+: inline w nagłówku) + await page.getByRole('button', { name: 'Zatwierdź plan' }).click(); // po utworzeniu — szczegóły planu (aktywowany z datą startu) await expect(page.getByRole('heading', { name: 'Plan e2e' })).toBeVisible(); @@ -58,7 +59,7 @@ test('walidacja tytułu i podsumowanie stopki', async ({ page }) => { await expect(page.getByRole('heading', { name: 'Nowy plan' })).toBeVisible(); // pusty tytuł → błąd inline pod polem (i w stopce — pierwszy w DOM) - await page.getByRole('button', { name: 'Utwórz plan' }).click(); + await page.getByRole('button', { name: 'Zatwierdź plan' }).click(); await expect(page.getByText('Podaj tytuł planu').first()).toBeVisible(); // podsumowanie stopki: 0 dni · 0 ćwiczeń · 0 serii + ostrzeżenie o pustych tygodniach diff --git a/app/test/e2e/trainee-plans.spec.ts b/app/test/e2e/trainee-plans.spec.ts index 77bad83..01bd91b 100644 --- a/app/test/e2e/trainee-plans.spec.ts +++ b/app/test/e2e/trainee-plans.spec.ts @@ -82,6 +82,7 @@ test('edytor planu podopiecznego: „Wstaw wyniki" prefylluje serie z ostatniej }) => { await openTraineePlansTab(page); await page.getByRole('button', { name: 'Utwórz plan' }).click(); + // (lista: akcja tworzenia w topbarze) — w edytorze zapis = „Zatwierdź plan" await expect(page.getByRole('heading', { name: 'Plan dla podopiecznego' })).toBeVisible(); // dodaj dzień (Poniedziałek) diff --git a/app/test/trainee-plans.test.tsx b/app/test/trainee-plans.test.tsx index ec0b6a5..cc1de70 100644 --- a/app/test/trainee-plans.test.tsx +++ b/app/test/trainee-plans.test.tsx @@ -377,7 +377,7 @@ describe('PlanEditor — tryb podopiecznego', () => { renderAt(`/trainees/${TRAINEE_ID}/plans/new`); await screen.findByRole('heading', { name: 'Plan dla podopiecznego' }); - await user.click(screen.getByRole('button', { name: 'Utwórz plan' })); + await user.click(screen.getByRole('button', { name: 'Zatwierdź plan' })); // błąd pod polem tytułu + w stopce expect(screen.getAllByText('Podaj tytuł planu').length).toBeGreaterThanOrEqual(1); });