Plany: walidacja inline, podsumowanie stopki i badge grupy miesniowej (dopracowanie widoku)
This commit is contained in:
@@ -45,7 +45,13 @@ export function isPastWeek(monday: string): boolean {
|
||||
/* Wybór tygodnia startu: siatka miesiąca, w której kliknięcie dowolnego dnia zaznacza
|
||||
CAŁY tydzień (Pn–Nd) — data startu to poniedziałek zaznaczonego tygodnia.
|
||||
Minione tygodnie są zablokowane (start nie może być w przeszłości). */
|
||||
export function WeekPicker({ value, onChange }: { value: string; onChange: (monday: string) => void }) {
|
||||
export function WeekPicker({
|
||||
value,
|
||||
onChange,
|
||||
}: {
|
||||
value: string;
|
||||
onChange: (monday: string) => void;
|
||||
}) {
|
||||
const now = new Date();
|
||||
const [view, setView] = useState<[number, number]>(() => {
|
||||
if (value) {
|
||||
@@ -77,11 +83,25 @@ export function WeekPicker({ value, onChange }: { value: string; onChange: (mond
|
||||
return (
|
||||
<div className="w-full max-w-xs">
|
||||
<div className="flex items-center justify-between gap-2 mb-2">
|
||||
<Button size="sm" variant="ghost" onClick={() => shift(-1)} aria-label="Poprzedni miesiąc">
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
onClick={() => shift(-1)}
|
||||
aria-label="Poprzedni miesiąc"
|
||||
className="max-md:h-11 max-md:w-11 max-md:justify-center"
|
||||
>
|
||||
<ChevronLeft className="w-4 h-4" />
|
||||
</Button>
|
||||
<span className="text-[0.9rem] font-semibold">{formatMonth(`${y}-${String(m).padStart(2, '0')}`)}</span>
|
||||
<Button size="sm" variant="ghost" onClick={() => shift(1)} aria-label="Następny miesiąc">
|
||||
<span className="text-[0.9rem] font-semibold">
|
||||
{formatMonth(`${y}-${String(m).padStart(2, '0')}`)}
|
||||
</span>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
onClick={() => shift(1)}
|
||||
aria-label="Następny miesiąc"
|
||||
className="max-md:h-11 max-md:w-11 max-md:justify-center"
|
||||
>
|
||||
<ChevronRight className="w-4 h-4" />
|
||||
</Button>
|
||||
</div>
|
||||
@@ -103,7 +123,7 @@ export function WeekPicker({ value, onChange }: { value: string; onChange: (mond
|
||||
disabled={isPast}
|
||||
onClick={() => onChange(localDayKey(weekMonday))}
|
||||
aria-pressed={isSel}
|
||||
className={`h-8 rounded-md text-[0.8rem] transition-colors ${
|
||||
className={`h-8 max-md:h-10 rounded-md text-[0.8rem] transition-colors ${
|
||||
isPast
|
||||
? 'text-dim/40 cursor-not-allowed'
|
||||
: isSel
|
||||
@@ -120,7 +140,8 @@ export function WeekPicker({ value, onChange }: { value: string; onChange: (mond
|
||||
</div>
|
||||
{value && (
|
||||
<p className="text-dim text-[0.8rem] mt-2">
|
||||
Start: tydzień {fmtDate(value)} – {fmtDate(localDayKey(addDaysLocal(parseIsoLocal(value), 6)))}
|
||||
Start: tydzień {fmtDate(value)} –{' '}
|
||||
{fmtDate(localDayKey(addDaysLocal(parseIsoLocal(value), 6)))}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -34,6 +34,35 @@ export function exerciseCountLabel(n: number): string {
|
||||
return `${n} ćwiczeń`;
|
||||
}
|
||||
|
||||
export function dayCountLabel(n: number): string {
|
||||
return n === 1 ? '1 dzień' : `${n} dni`;
|
||||
}
|
||||
|
||||
export function setCountLabel(n: number): string {
|
||||
return n === 1 ? '1 seria' : `${n} serii`;
|
||||
}
|
||||
|
||||
export function weekCountLabel(n: number): string {
|
||||
if (n === 1) return '1 tydzień';
|
||||
const mod10 = n % 10;
|
||||
const mod100 = n % 100;
|
||||
if (mod10 >= 2 && mod10 <= 4 && (mod100 < 12 || mod100 > 14)) return `${n} tygodnie`;
|
||||
return `${n} tygodni`;
|
||||
}
|
||||
|
||||
/** Kolor badge'a grupy mięśniowej (wg primaryMuscle). */
|
||||
export const MUSCLE_COLORS: Record<string, BadgeColor> = {
|
||||
chest: 'red',
|
||||
back: 'blue',
|
||||
legs: 'green',
|
||||
shoulders: 'yellow',
|
||||
biceps: 'blue',
|
||||
triceps: 'yellow',
|
||||
core: 'gray',
|
||||
glutes: 'red',
|
||||
forearms: 'gray',
|
||||
};
|
||||
|
||||
export const PLAN_STATUS: Record<Plan['status'], { label: string; color: BadgeColor }> = {
|
||||
DRAFT: { label: 'Szkic', color: 'gray' },
|
||||
ACTIVE: { label: 'Aktywny', color: 'green' },
|
||||
|
||||
@@ -13,16 +13,24 @@ import {
|
||||
type PlanWeekInput,
|
||||
} from '../../api/queries';
|
||||
import type { Exercise, LatestExerciseResult } from '../../api/types';
|
||||
import { CalendarX } from 'lucide-react';
|
||||
import {
|
||||
BackButton,
|
||||
Button,
|
||||
ConfirmDialog,
|
||||
EmptyState,
|
||||
ErrorText,
|
||||
isPastWeek,
|
||||
Skeleton,
|
||||
type BadgeColor,
|
||||
} from '../../components/ui';
|
||||
import { DAY_NAMES, exerciseCountLabel } from '../../lib/labels';
|
||||
import {
|
||||
DAY_NAMES,
|
||||
dayCountLabel,
|
||||
exerciseCountLabel,
|
||||
setCountLabel,
|
||||
weekCountLabel,
|
||||
} from '../../lib/labels';
|
||||
import { useTopbar } from '../../topbar';
|
||||
import { displayedDaysOf, type EditorDay, type EditorWeek } from './plan-editor/types';
|
||||
import { usePlanEditorState } from './plan-editor/usePlanEditorState';
|
||||
@@ -101,10 +109,40 @@ export default function PlanEditor() {
|
||||
const [confirmExit, setConfirmExit] = useState(false);
|
||||
const [clearWeekIdx, setClearWeekIdx] = useState<number | null>(null);
|
||||
const [removeDayReq, setRemoveDayReq] = useState<{ wi: number; dow: number } | null>(null);
|
||||
const [titleTouched, setTitleTouched] = useState(false);
|
||||
|
||||
const exercises = exData?.exercises ?? [];
|
||||
const loading = isEdit && !editor.initialized;
|
||||
|
||||
// Walidacja inline: tytuł (po touch) + tydzień startu w przeszłości
|
||||
const titleError = titleTouched && !editor.title.trim() ? 'Podaj tytuł planu' : '';
|
||||
const startWeekError =
|
||||
!isEdit && editor.startDate && isPastWeek(editor.startDate)
|
||||
? 'Tydzień startu nie może być w przeszłości'
|
||||
: '';
|
||||
|
||||
// Podsumowanie stopki: dni/ćwiczenia/serie + tygodnie bez ćwiczeń (nie blokuje)
|
||||
const totals = useMemo(() => {
|
||||
let days = 0;
|
||||
let exerciseTotal = 0;
|
||||
let sets = 0;
|
||||
let emptyWeeks = 0;
|
||||
editor.weeks.forEach((_, i) => {
|
||||
const weekDays = displayedDaysOf(editor.weeks, i);
|
||||
days += weekDays.length;
|
||||
let weekExercises = 0;
|
||||
weekDays.forEach((d) => {
|
||||
weekExercises += d.exercises.length;
|
||||
d.exercises.forEach((e) => {
|
||||
sets += e.sets.length;
|
||||
});
|
||||
});
|
||||
exerciseTotal += weekExercises;
|
||||
if (weekExercises === 0) emptyWeeks += 1;
|
||||
});
|
||||
return { days, exercises: exerciseTotal, sets, emptyWeeks };
|
||||
}, [editor.weeks]);
|
||||
|
||||
// Guard niezapisanych zmian: F5/odświeżenie + wyjście (Anuluj/Wstecz/mobile „<”)
|
||||
useEffect(() => {
|
||||
if (!editor.dirty) return;
|
||||
@@ -125,8 +163,6 @@ export default function PlanEditor() {
|
||||
[progressData],
|
||||
);
|
||||
|
||||
const dayLabel = (n: number) => (n === 1 ? '1 dzień' : `${n} dni`);
|
||||
|
||||
const weekSummary = (
|
||||
wi: number,
|
||||
w: EditorWeek,
|
||||
@@ -138,11 +174,12 @@ export default function PlanEditor() {
|
||||
? { text: 'przerwa', color: 'blue' }
|
||||
: { text: 'odzwierciedla tyg. 1', color: 'yellow' };
|
||||
}
|
||||
return { text: dayLabel(days.length), color: 'green' };
|
||||
return { text: dayCountLabel(days.length), color: 'green' };
|
||||
};
|
||||
|
||||
const save = async () => {
|
||||
setError('');
|
||||
setTitleTouched(true);
|
||||
if (!editor.title.trim()) {
|
||||
setError('Podaj tytuł planu');
|
||||
return;
|
||||
@@ -227,10 +264,13 @@ export default function PlanEditor() {
|
||||
<PlanMetaForm
|
||||
title={editor.title}
|
||||
onTitleChange={editor.setTitle}
|
||||
onTitleBlur={() => setTitleTouched(true)}
|
||||
titleError={titleError}
|
||||
weeksCount={editor.weeksCount}
|
||||
onWeeksCountChange={editor.setWeeksCount}
|
||||
startDate={editor.startDate}
|
||||
onStartDateChange={editor.setStartDate}
|
||||
startWeekError={startWeekError}
|
||||
showStartWeek={!isEdit}
|
||||
/>
|
||||
|
||||
@@ -277,13 +317,17 @@ export default function PlanEditor() {
|
||||
/>
|
||||
|
||||
{days.length === 0 && (
|
||||
<p className="text-dim mt-3">
|
||||
{wi === 0
|
||||
? 'Wybierz dni treningowe powyżej — pozostałe tygodnie będą je odzwierciedlać.'
|
||||
: w.detached
|
||||
? 'Tydzień wolny (przerwa) — pozostanie pusty.'
|
||||
: 'Odzwierciedla tydzień 1. Kliknij dzień, aby edytować niezależnie.'}
|
||||
</p>
|
||||
<EmptyState
|
||||
icon={CalendarX}
|
||||
title="Brak dni treningowych"
|
||||
description={
|
||||
wi === 0
|
||||
? 'Wybierz dni treningowe powyżej — pozostałe tygodnie będą je odzwierciedlać.'
|
||||
: w.detached
|
||||
? 'Tydzień wolny (przerwa) — pozostanie pusty.'
|
||||
: 'Odzwierciedla tydzień 1. Kliknij dzień, aby edytować niezależnie.'
|
||||
}
|
||||
/>
|
||||
)}
|
||||
|
||||
{days.length > 0 && (
|
||||
@@ -330,6 +374,13 @@ export default function PlanEditor() {
|
||||
{/* sticky stopka; na mobile pod stałym dolnym paskiem topmenu (+ safe-area) */}
|
||||
<div className="sticky bottom-0 -mx-4 px-4 py-3 bg-bg/95 backdrop-blur border-t border-line mt-2 md:-mx-8 md:px-8 max-md:bottom-[calc(43px+max(0.5rem,env(safe-area-inset-bottom)))]">
|
||||
{error && <ErrorText>{error}</ErrorText>}
|
||||
<div className="mb-2 text-dim text-[0.8125rem]">
|
||||
{dayCountLabel(totals.days)} · {exerciseCountLabel(totals.exercises)} ·{' '}
|
||||
{setCountLabel(totals.sets)}
|
||||
{totals.emptyWeeks > 0 && (
|
||||
<span className="text-warn"> · {weekCountLabel(totals.emptyWeeks)} bez ćwiczeń</span>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex gap-3">
|
||||
<Button onClick={save} disabled={saving} className="flex-1">
|
||||
{saving ? 'Zapisywanie…' : isEdit ? 'Zapisz zmiany' : 'Utwórz plan'}
|
||||
|
||||
@@ -62,6 +62,7 @@ export function DayEditor({
|
||||
<ExerciseEditor
|
||||
key={ei}
|
||||
exercise={ex}
|
||||
exerciseMeta={exercises.find((p) => p.id === ex.exerciseId)}
|
||||
exerciseName={exerciseName}
|
||||
isTraineeMode={isTraineeMode}
|
||||
resultsOpen={resultsOpenKey === `${weekIndex}:${dayIndex}:${ei}`}
|
||||
|
||||
@@ -1,9 +1,20 @@
|
||||
import { Activity, ChevronDown, ChevronUp, Copy, Plus, X } from 'lucide-react';
|
||||
import { Button } from '../../../components/ui';
|
||||
import type { ExerciseProgressPoint, LatestExerciseResult } from '../../../api/types';
|
||||
import { Badge, Button } from '../../../components/ui';
|
||||
import { MUSCLE_COLORS, MUSCLE_NAMES } from '../../../lib/labels';
|
||||
import type { Exercise, ExerciseProgressPoint, LatestExerciseResult } from '../../../api/types';
|
||||
import type { EditorExercise, EditorSet } from './types';
|
||||
import { ExerciseResultsPanel } from './ExerciseResultsPanel';
|
||||
|
||||
/** Szybkie podsumowanie serii wg pierwszej: „3×10 @ 20 kg · RIR 2”. */
|
||||
function setsSummary(sets: EditorSet[]): string {
|
||||
if (sets.length === 0) return '';
|
||||
const first = sets[0];
|
||||
let text = `${sets.length}×${first.reps || '?'}`;
|
||||
if (first.loadKg) text += ` @ ${first.loadKg} kg`;
|
||||
if (first.rir !== '') text += ` · RIR ${first.rir}`;
|
||||
return text;
|
||||
}
|
||||
|
||||
const SET_INPUT_CLS =
|
||||
'w-full rounded-[10px] border border-line bg-input px-2.5 py-1.5 text-[0.9rem] text-ink shadow-(--inset-shadow) focus:border-accent-text focus:ring-[3px] focus:ring-accent/18 focus:outline-none';
|
||||
|
||||
@@ -19,6 +30,7 @@ const SET_COLUMNS: { key: keyof EditorSet; label: string; inputMode: 'numeric' |
|
||||
serii (wspólne nagłówki kolumn) + Dodaj serię / Kopiuj poprzednią (+ panel wyników). */
|
||||
export function ExerciseEditor({
|
||||
exercise,
|
||||
exerciseMeta,
|
||||
exerciseName,
|
||||
isTraineeMode,
|
||||
resultsOpen,
|
||||
@@ -37,6 +49,8 @@ export function ExerciseEditor({
|
||||
onPrefill,
|
||||
}: {
|
||||
exercise: EditorExercise;
|
||||
/** Pełny obiekt ćwiczenia (katalog) — badge grupy mięśniowej; undefined gdy katalog niezaładowany. */
|
||||
exerciseMeta?: Exercise;
|
||||
exerciseName: (eid: string) => string;
|
||||
isTraineeMode: boolean;
|
||||
resultsOpen: boolean;
|
||||
@@ -57,9 +71,19 @@ export function ExerciseEditor({
|
||||
return (
|
||||
<div className="rounded-[10px] border border-line bg-card/40 p-3">
|
||||
<div className="mb-2 flex items-center justify-between gap-2">
|
||||
<strong className="min-w-0 truncate text-[0.95rem]">
|
||||
{exerciseName(exercise.exerciseId)}
|
||||
</strong>
|
||||
<div className="flex min-w-0 flex-1 items-center gap-2">
|
||||
<strong className="min-w-0 truncate text-[0.95rem]">
|
||||
{exerciseName(exercise.exerciseId)}
|
||||
</strong>
|
||||
{exerciseMeta && (
|
||||
<Badge color={MUSCLE_COLORS[exerciseMeta.primaryMuscle] ?? 'gray'} className="shrink-0">
|
||||
{MUSCLE_NAMES[exerciseMeta.primaryMuscle] ?? exerciseMeta.primaryMuscle}
|
||||
</Badge>
|
||||
)}
|
||||
<span className="min-w-0 truncate text-dim text-[0.8rem] tabular-nums">
|
||||
{setsSummary(exercise.sets)}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex shrink-0 items-center gap-1">
|
||||
<Button
|
||||
variant="ghost"
|
||||
@@ -94,7 +118,8 @@ export function ExerciseEditor({
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="overflow-x-auto">
|
||||
{/* relative: sr-only (absolute) w nagłówku nie rozlewa dokumentu poza scroll container */}
|
||||
<div className="relative overflow-x-auto">
|
||||
<table className="w-full min-w-[460px] border-separate border-spacing-0">
|
||||
<thead>
|
||||
<tr>
|
||||
|
||||
@@ -1,21 +1,27 @@
|
||||
import { Card, Field, Input, Select, WeekPicker } from '../../../components/ui';
|
||||
import { Card, ErrorText, Field, Input, Select, WeekPicker } from '../../../components/ui';
|
||||
|
||||
/* Meta planu: tytuł, długość, tydzień startu (+ hint) — siatka pól. */
|
||||
/* Meta planu: tytuł, długość, tydzień startu (+ hint) — siatka pól, błędy inline. */
|
||||
export function PlanMetaForm({
|
||||
title,
|
||||
onTitleChange,
|
||||
onTitleBlur,
|
||||
titleError,
|
||||
weeksCount,
|
||||
onWeeksCountChange,
|
||||
startDate,
|
||||
onStartDateChange,
|
||||
startWeekError,
|
||||
showStartWeek,
|
||||
}: {
|
||||
title: string;
|
||||
onTitleChange: (v: string) => void;
|
||||
onTitleBlur?: () => void;
|
||||
titleError?: string;
|
||||
weeksCount: number;
|
||||
onWeeksCountChange: (n: number) => void;
|
||||
startDate: string;
|
||||
onStartDateChange: (v: string) => void;
|
||||
startWeekError?: string;
|
||||
showStartWeek: boolean;
|
||||
}) {
|
||||
return (
|
||||
@@ -25,8 +31,11 @@ export function PlanMetaForm({
|
||||
<Input
|
||||
value={title}
|
||||
onChange={(e) => onTitleChange(e.target.value)}
|
||||
onBlur={onTitleBlur}
|
||||
placeholder="np. Plan masowy 8-tygodniowy"
|
||||
aria-invalid={titleError ? true : undefined}
|
||||
/>
|
||||
{titleError && <ErrorText>{titleError}</ErrorText>}
|
||||
</Field>
|
||||
<Field label="Długość (tygodnie)">
|
||||
<Select value={weeksCount} onChange={(e) => onWeeksCountChange(parseInt(e.target.value))}>
|
||||
@@ -43,13 +52,14 @@ export function PlanMetaForm({
|
||||
<Field label="Tydzień startu">
|
||||
<WeekPicker value={startDate} onChange={onStartDateChange} />
|
||||
</Field>
|
||||
{startWeekError && <ErrorText>{startWeekError}</ErrorText>}
|
||||
</div>
|
||||
)}
|
||||
{showStartWeek && (
|
||||
<p className="mt-3 text-dim text-[0.875rem]">
|
||||
Opcjonalnie zaznacz tydzień startu — plan zostanie od razu aktywowany (start = poniedziałek
|
||||
zaznaczonego tygodnia), a daty dni treningowych wyliczone automatycznie. Bez tygodnia plan
|
||||
pozostanie szkicem.
|
||||
Opcjonalnie zaznacz tydzień startu — plan zostanie od razu aktywowany (start =
|
||||
poniedziałek zaznaczonego tygodnia), a daty dni treningowych wyliczone automatycznie. Bez
|
||||
tygodnia plan pozostanie szkicem.
|
||||
</p>
|
||||
)}
|
||||
</Card>
|
||||
|
||||
78
app/test/e2e/plans-mobile.spec.ts
Normal file
78
app/test/e2e/plans-mobile.spec.ts
Normal file
@@ -0,0 +1,78 @@
|
||||
import { test, expect, type Page } from './fixtures';
|
||||
import { mockPlans } from './mock-api';
|
||||
|
||||
/* Scenariusze mobilne edytora planu (M8): 375×667 + asercja braku poziomego
|
||||
scrolla na 320px (iPhone SE). */
|
||||
test.use({ viewport: { width: 375, height: 667 } });
|
||||
|
||||
async function login(page: Page) {
|
||||
await page.goto('/login');
|
||||
await page.locator('input[type="email"]').fill('test@fitos.pl');
|
||||
await page.locator('input[type="password"]').fill('haslo123');
|
||||
await page.getByRole('button', { name: 'Zaloguj' }).click();
|
||||
await expect(page.getByRole('heading', { name: 'Dashboard' })).toBeVisible();
|
||||
}
|
||||
|
||||
async function openNewPlan(page: Page) {
|
||||
// mobile: nawigacja przez hamburgera (drawer)
|
||||
await page.getByRole('button', { name: 'Otwórz menu' }).click();
|
||||
await page.getByRole('link', { name: 'Plany' }).click();
|
||||
await expect(page.getByRole('heading', { name: 'Plany' })).toBeVisible();
|
||||
// akcja „Nowy plan” (Link w grupie „Dodawanie”, nie CTA z topbara)
|
||||
await page.getByRole('link', { name: 'Nowy plan' }).click();
|
||||
await expect(page.getByRole('heading', { name: 'Nowy plan' })).toBeVisible();
|
||||
}
|
||||
|
||||
test('mobile: tworzenie planu — bezpieczny tap dnia, bottom sheet, edycja serii, zapis', async ({
|
||||
page,
|
||||
}) => {
|
||||
mockPlans(page);
|
||||
await login(page);
|
||||
await openNewPlan(page);
|
||||
|
||||
// dodaj dzień (Poniedziałek)
|
||||
await page.getByRole('button', { name: 'Pon' }).click();
|
||||
|
||||
// dodaj ćwiczenie przez bottom sheet (Radix Dialog na mobile)
|
||||
await page.getByRole('button', { name: '+ dodaj ćwiczenie…' }).click();
|
||||
await expect(page.getByRole('dialog')).toBeVisible();
|
||||
await page.getByRole('option', { name: /Przysiady/ }).click();
|
||||
await expect(page.getByRole('dialog')).toBeHidden();
|
||||
|
||||
// edycja serii
|
||||
await page.getByRole('textbox', { name: 'Seria 1: Powt.' }).fill('8');
|
||||
|
||||
// tap na dzień Z ćwiczeniami → potwierdzenie (nie destrukcyjne)
|
||||
await page.getByRole('button', { name: 'Pon' }).click();
|
||||
await expect(page.getByRole('heading', { name: 'Usunąć dzień?' })).toBeVisible();
|
||||
await expect(page.getByText(/Usunąć poniedziałek i jego 1 ćwiczenie/)).toBeVisible();
|
||||
await page.getByRole('button', { name: 'Usuń dzień' }).click();
|
||||
await expect(page.getByText('Przysiady')).toHaveCount(0);
|
||||
|
||||
// ponownie dodaj dzień + ćwiczenie, utwórz plan
|
||||
await page.getByRole('button', { name: 'Pon' }).click();
|
||||
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();
|
||||
|
||||
// po utworzeniu — szczegóły planu (mock zwraca „Plan e2e”)
|
||||
await expect(page.getByRole('heading', { name: 'Plan e2e' })).toBeVisible();
|
||||
});
|
||||
|
||||
test('mobile 320px: brak poziomego scrolla w edytorze', async ({ page }) => {
|
||||
await page.setViewportSize({ width: 320, height: 568 });
|
||||
mockPlans(page);
|
||||
await login(page);
|
||||
await openNewPlan(page);
|
||||
|
||||
// dodaj dzień + ćwiczenie — tabela serii (min-w) nie może przelewać strony
|
||||
await page.getByRole('button', { name: 'Pon' }).click();
|
||||
await page.getByRole('button', { name: '+ dodaj ćwiczenie…' }).click();
|
||||
await page.getByRole('option', { name: /Przysiady/ }).click();
|
||||
|
||||
const noHorizontalScroll = await page.evaluate(
|
||||
() => document.documentElement.scrollWidth <= window.innerWidth,
|
||||
);
|
||||
expect(noHorizontalScroll).toBe(true);
|
||||
});
|
||||
@@ -49,6 +49,30 @@ test('formularz nowego planu ma wybór tygodnia startu i przycisk „Wstecz” w
|
||||
await expect(page.getByRole('heading', { name: 'Plan e2e' })).toBeVisible();
|
||||
});
|
||||
|
||||
test('walidacja tytułu i podsumowanie stopki', async ({ page }) => {
|
||||
mockPlans(page);
|
||||
await login(page);
|
||||
|
||||
await page.getByRole('link', { name: 'Plany' }).click();
|
||||
await page.getByRole('button', { name: 'Nowy plan' }).first().click();
|
||||
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 expect(page.getByText('Podaj tytuł planu').first()).toBeVisible();
|
||||
|
||||
// podsumowanie stopki: 0 dni · 0 ćwiczeń · 0 serii + ostrzeżenie o pustych tygodniach
|
||||
await expect(page.getByText(/0 dni · 0 ćwiczeń · 0 serii/)).toBeVisible();
|
||||
await expect(page.getByText(/4 tygodnie bez ćwiczeń/)).toBeVisible();
|
||||
|
||||
// dodaj dzień + ćwiczenie → podsumowanie się zmienia (tyg. 2–4 odzwierciedlają tyg. 1)
|
||||
await page.getByRole('button', { name: 'Pon' }).click();
|
||||
await page.getByRole('button', { name: '+ dodaj ćwiczenie…' }).click();
|
||||
await page.getByRole('option', { name: /Przysiady/ }).click();
|
||||
await expect(page.getByText(/4 dni · 4 ćwiczenia · 4 serii/)).toBeVisible();
|
||||
await expect(page.getByText(/bez ćwiczeń/)).toHaveCount(0);
|
||||
});
|
||||
|
||||
test('pasek tygodni: klik chipa rozwija dany tydzień', async ({ page }) => {
|
||||
mockPlans(page);
|
||||
await login(page);
|
||||
|
||||
@@ -356,6 +356,32 @@ describe('PlanEditor — tryb podopiecznego', () => {
|
||||
expect(await screen.findByRole('heading', { name: 'Plany podopiecznego' })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('karta ćwiczenia: badge grupy mięśniowej i podsumowanie serii', async () => {
|
||||
mockApi();
|
||||
const user = userEvent.setup();
|
||||
renderAt(`/trainees/${TRAINEE_ID}/plans/new`);
|
||||
|
||||
await screen.findByRole('heading', { name: 'Plan dla podopiecznego' });
|
||||
await user.click(screen.getByRole('button', { name: 'Poniedziałek' }));
|
||||
await user.click(screen.getByRole('button', { name: '+ dodaj ćwiczenie…' }));
|
||||
await user.click(await screen.findByRole('option', { name: /Przysiady/ }));
|
||||
|
||||
// legs → badge „Nogi”; seria domyślna → „1×10 @ 20 kg · RIR 2”
|
||||
expect(screen.getByText('Nogi')).toBeInTheDocument();
|
||||
expect(screen.getByText(/1×10 @ 20 kg/)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('walidacja: pusty tytuł blokuje zapis (błąd inline)', async () => {
|
||||
mockApi();
|
||||
const user = userEvent.setup();
|
||||
renderAt(`/trainees/${TRAINEE_ID}/plans/new`);
|
||||
|
||||
await screen.findByRole('heading', { name: 'Plan dla podopiecznego' });
|
||||
await user.click(screen.getByRole('button', { name: 'Utwórz plan' }));
|
||||
// błąd pod polem tytułu + w stopce
|
||||
expect(screen.getAllByText('Podaj tytuł planu').length).toBeGreaterThanOrEqual(1);
|
||||
});
|
||||
|
||||
it('„Wstaw wyniki" prefylluje serie z ostatniej sesji', async () => {
|
||||
mockApi();
|
||||
const user = userEvent.setup();
|
||||
|
||||
Reference in New Issue
Block a user