Plany: karta hero aktywnego planu z podgledem tygodnia - GET /plans zwieksza plans o summary (rozklad dni treningowych i liczba cwiczen tygodnia biezacego lub pierwszego), ActivePlanHero renderuje chipy dni i licznik cwiczen, helper dayShort w lib/format, swagger i i18n pl/en (testy unit api + integracyjne + unit i e2e app)
This commit is contained in:
@@ -196,6 +196,17 @@ export async function listPlans(prisma: PrismaClient, userId: string) {
|
||||
.filter((d) => d.status === 'PLANNED' && d.date)
|
||||
.sort((a, b) => a.date!.getTime() - b.date!.getTime());
|
||||
const next = pending.find((d) => d.date!.getTime() >= startOfToday.getTime());
|
||||
const currentWeek = pending.length > 0 ? pending[0].weekIndex : null;
|
||||
// Karta hero: podgląd tygodnia bieżącego (lub pierwszego) — rozkład dni
|
||||
// treningowych i liczba ćwiczeń w tygodniu.
|
||||
const orderedWeeks = [...(p.weeks ?? [])].sort((a, b) => a.index - b.index);
|
||||
const refWeek = orderedWeeks.find((w) => w.index === currentWeek) ?? orderedWeeks[0] ?? null;
|
||||
const summary = refWeek
|
||||
? {
|
||||
trainingDays: refWeek.days.map((d) => d.dayOfWeek).sort((a, b) => a - b),
|
||||
exercises: refWeek.days.reduce((sum, d) => sum + (d._count?.exercises ?? 0), 0),
|
||||
}
|
||||
: null;
|
||||
return {
|
||||
...rest,
|
||||
progress: {
|
||||
@@ -203,7 +214,7 @@ export async function listPlans(prisma: PrismaClient, userId: string) {
|
||||
total,
|
||||
percent: total > 0 ? Math.round((completed / total) * 100) : 0,
|
||||
},
|
||||
currentWeek: pending.length > 0 ? pending[0].weekIndex : null,
|
||||
currentWeek,
|
||||
nextDay: next
|
||||
? {
|
||||
date: next.date!.toISOString(),
|
||||
@@ -211,6 +222,7 @@ export async function listPlans(prisma: PrismaClient, userId: string) {
|
||||
exerciseCount: next._count.exercises,
|
||||
}
|
||||
: null,
|
||||
summary,
|
||||
};
|
||||
}),
|
||||
};
|
||||
|
||||
@@ -1352,6 +1352,8 @@ export const openapi: Record<string, unknown> = {
|
||||
get: {
|
||||
tags: ['Plans'],
|
||||
summary: "User's plans",
|
||||
description:
|
||||
'List fields per plan: progress { completed, total, percent }, currentWeek (week of the nearest unresolved dated day), nextDay { date, dayOfWeek, exerciseCount } (first PLANNED day today or later), summary { trainingDays (dayOfWeek of the current or first week), exercises (weekly exercise count) } for the hero card',
|
||||
security: [{ bearerAuth: [] }],
|
||||
},
|
||||
post: {
|
||||
|
||||
@@ -533,6 +533,8 @@ describe('plan templates (kind=TEMPLATE)', () => {
|
||||
expect(new Date(plan.nextDay.date).getTime()).toBe(at(1).getTime());
|
||||
expect(plan.nextDay.dayOfWeek).toBe(3);
|
||||
expect(plan.nextDay.exerciseCount).toBe(1);
|
||||
// podgląd tygodnia 0: rozkład dni (pon + śr) i ćwiczenia w tygodniu
|
||||
expect(plan.summary).toEqual({ trainingDays: [1, 3], exercises: 1 });
|
||||
});
|
||||
|
||||
it('PLANNED today counts as nextDay', async () => {
|
||||
|
||||
@@ -971,7 +971,15 @@ describe('listPlans', () => {
|
||||
prisma.trainingPlan.findMany.mockResolvedValue([
|
||||
{
|
||||
id: 'p1',
|
||||
weeks: [{ days: [{ status: 'COMPLETED' }, { status: 'PLANNED' }] }],
|
||||
weeks: [
|
||||
{
|
||||
index: 0,
|
||||
days: [
|
||||
{ status: 'COMPLETED', date: null, dayOfWeek: 3, _count: { exercises: 1 } },
|
||||
{ status: 'PLANNED', date: null, dayOfWeek: 1, _count: { exercises: 2 } },
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
]);
|
||||
const result = await listPlans(prisma, 'u1');
|
||||
@@ -1004,10 +1012,27 @@ describe('listPlans', () => {
|
||||
progress: { completed: 1, total: 2, percent: 50 },
|
||||
currentWeek: null,
|
||||
nextDay: null,
|
||||
summary: { trainingDays: [1, 3], exercises: 3 },
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it('summary falls back to the first week when no dated pending day exists', async () => {
|
||||
const { prisma } = mockPrisma();
|
||||
prisma.trainingPlan.findMany.mockResolvedValue([
|
||||
{
|
||||
id: 'p2',
|
||||
weeks: [
|
||||
{ index: 1, days: [{ status: 'PLANNED', date: null, dayOfWeek: 5, _count: { exercises: 4 } }] },
|
||||
{ index: 0, days: [{ status: 'PLANNED', date: null, dayOfWeek: 2, _count: { exercises: 2 } }] },
|
||||
],
|
||||
},
|
||||
]);
|
||||
const result = await listPlans(prisma, 'u1');
|
||||
expect(result.plans[0].currentWeek).toBeNull();
|
||||
expect(result.plans[0].summary).toEqual({ trainingDays: [2], exercises: 2 });
|
||||
});
|
||||
});
|
||||
|
||||
describe('assertPlanAccess (via getPlan)', () => {
|
||||
|
||||
@@ -552,6 +552,8 @@ export interface Plan {
|
||||
currentWeek?: number | null;
|
||||
/** Hero listy: pierwszy dzień PLANNED z datą od dziś w górę (lista). */
|
||||
nextDay?: { date: string; dayOfWeek: number; exerciseCount: number } | null;
|
||||
/** Karta hero: podgląd tygodnia bieżącego (lub pierwszego) — dni treningowe i liczba ćwiczeń w tygodniu (lista). */
|
||||
summary?: { trainingDays: number[]; exercises: number } | null;
|
||||
/** Historia edycji aktywnego planu (detal, newest first); brak = plan nieaktywny. */
|
||||
edits?: PlanEdit[];
|
||||
weeks: PlanWeek[];
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { Link } from 'react-router-dom';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { CalendarDays, ChevronRight, Layers, MapPin } from 'lucide-react';
|
||||
import { CalendarDays, ChevronRight, Dumbbell, Layers, MapPin } from 'lucide-react';
|
||||
import { PLAN_STATUS } from '../../lib/labels';
|
||||
import { dayName, fmtDate } from '../../lib/format';
|
||||
import { dayName, dayShort, fmtDate } from '../../lib/format';
|
||||
import { Badge } from '../ui';
|
||||
import type { Plan } from '../../api/types';
|
||||
|
||||
@@ -16,7 +16,8 @@ function todayIso(): string {
|
||||
|
||||
/**
|
||||
* Hero zakładki „Aktualne”: wyeksponowana karta jedynego aktywnego planu —
|
||||
* postęp dni, „Tydzień X z Y”, następny trening, siłownia i autor.
|
||||
* postęp dni, „Tydzień X z Y”, podgląd tygodnia (chipy dni treningowych i liczba
|
||||
* ćwiczeń), następny trening, siłownia i autor.
|
||||
* Klik całej karty → szczegóły planu. Bez killstreaka i bez CTA startu dnia.
|
||||
*/
|
||||
export function ActivePlanHero({
|
||||
@@ -66,6 +67,22 @@ export function ActivePlanHero({
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
{plan.summary && (
|
||||
<div className="mt-3 flex flex-wrap items-center gap-1.5">
|
||||
{plan.summary.trainingDays.map((d) => (
|
||||
<span
|
||||
key={d}
|
||||
className="rounded-md border border-line bg-input px-2 py-0.5 text-[0.75rem] font-bold"
|
||||
>
|
||||
{dayShort(d)}
|
||||
</span>
|
||||
))}
|
||||
<span className="ml-1.5 inline-flex items-center gap-1.5 text-dim text-[0.875rem]">
|
||||
<Dumbbell className="h-4 w-4" aria-hidden="true" />
|
||||
{t('hero.weekExercises', { count: plan.summary.exercises })}
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
<div className="mt-3 flex flex-wrap items-center gap-x-4 gap-y-1 text-dim text-[0.875rem]">
|
||||
{next && (
|
||||
<span className="inline-flex flex-wrap items-center gap-x-1.5">
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
"shared": "Shared"
|
||||
},
|
||||
"hub": {
|
||||
"intro": "Your plans in one place — pick a category.",
|
||||
"countActive_one": "{{count}} active",
|
||||
"countActive_other": "{{count}} active",
|
||||
"countSuspended_one": "{{count}} suspended",
|
||||
@@ -36,7 +35,9 @@
|
||||
"nextPrefix": "Next workout:",
|
||||
"today": "today",
|
||||
"exercisesCount_one": "{{count}} exercise",
|
||||
"exercisesCount_other": "{{count}} exercises"
|
||||
"exercisesCount_other": "{{count}} exercises",
|
||||
"weekExercises_one": "{{count}} exercise per week",
|
||||
"weekExercises_other": "{{count}} exercises per week"
|
||||
},
|
||||
"archive": {
|
||||
"emptyTitle": "The archive is empty",
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
"shared": "Udostępnione"
|
||||
},
|
||||
"hub": {
|
||||
"intro": "Twoje plany w jednym miejscu — wybierz kategorię.",
|
||||
"countActive_one": "{{count}} aktywny",
|
||||
"countActive_few": "{{count}} aktywne",
|
||||
"countActive_many": "{{count}} aktywnych",
|
||||
@@ -50,7 +49,11 @@
|
||||
"exercisesCount_one": "{{count}} ćwiczenie",
|
||||
"exercisesCount_few": "{{count}} ćwiczenia",
|
||||
"exercisesCount_many": "{{count}} ćwiczeń",
|
||||
"exercisesCount_other": "{{count}} ćwiczeń"
|
||||
"exercisesCount_other": "{{count}} ćwiczeń",
|
||||
"weekExercises_one": "{{count}} ćwiczenie w tygodniu",
|
||||
"weekExercises_few": "{{count}} ćwiczenia w tygodniu",
|
||||
"weekExercises_many": "{{count}} ćwiczeń w tygodniu",
|
||||
"weekExercises_other": "{{count}} ćwiczeń w tygodniu"
|
||||
},
|
||||
"archive": {
|
||||
"emptyTitle": "Archiwum jest puste",
|
||||
|
||||
@@ -227,6 +227,12 @@ export function dayName(dow: number): string {
|
||||
return capitalize(d.toLocaleDateString(currentTag(), { weekday: 'long' }));
|
||||
}
|
||||
|
||||
/** Skrót dnia tygodnia („Pon”) wg konwencji API (1 = poniedziałek … 7 = niedziela). */
|
||||
export function dayShort(dow: number): string {
|
||||
const d = new Date(2024, 0, 1 + (dow - 1)); // 2024-01-01 = poniedziałek
|
||||
return capitalize(d.toLocaleDateString(currentTag(), { weekday: 'short' }));
|
||||
}
|
||||
|
||||
/**
|
||||
* Nazwa dnia tygodnia w bierniku (PL: „Nadpisać środę?”; EN = mianownik).
|
||||
* Formy trzymane w common.json (`fmt.dayAcc`, tablica 7 elementów per język) —
|
||||
|
||||
@@ -45,6 +45,7 @@ const PLANS: Plan[] = [
|
||||
progress: { completed: 5, total: 10, percent: 50 },
|
||||
currentWeek: 2,
|
||||
nextDay: { date: '2026-11-20', dayOfWeek: 5, exerciseCount: 4 },
|
||||
summary: { trainingDays: [1, 3, 5], exercises: 6 },
|
||||
weeks: [],
|
||||
},
|
||||
{
|
||||
@@ -164,9 +165,10 @@ describe('Strona główna sekcji planów (/plans)', () => {
|
||||
|
||||
await user.click(archive);
|
||||
expect(await screen.findByRole('heading', { name: 'Ukończony' })).toBeInTheDocument();
|
||||
// brak paska zakładek — powrót do huba tylko przez „Wstecz” w topbarze
|
||||
// powrót do huba = „Wstecz”; podział kategorii = pasek statusów pod nagłówkiem
|
||||
expect(screen.getByRole('button', { name: 'Wstecz' })).toBeInTheDocument();
|
||||
expect(screen.queryByRole('button', { name: 'Aktualne' })).not.toBeInTheDocument();
|
||||
expect(screen.getByRole('button', { name: 'Wszystkie' })).toBeInTheDocument();
|
||||
expect(screen.getByRole('button', { name: 'Porzucony' })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('aktywny plan eksponowany jako hero także na stronie głównej', async () => {
|
||||
@@ -193,13 +195,20 @@ describe('Strona główna sekcji planów (/plans)', () => {
|
||||
});
|
||||
|
||||
describe('Podstrona „Aktualne” (/plans/current)', () => {
|
||||
it('podstrona ma „Wstecz” w topbarze, który wraca do huba z kafelkami', async () => {
|
||||
it('podstrona wraca do huba: „Wstecz” w treści (PC) i „<” w topbarze (telefon)', async () => {
|
||||
mockApi();
|
||||
const user = userEvent.setup();
|
||||
renderApp();
|
||||
await openCurrentPlans(user);
|
||||
|
||||
await user.click(screen.getByRole('button', { name: 'Wstecz' }));
|
||||
// nagłówek podstrony: kategoria po lewej
|
||||
expect(screen.getByRole('heading', { name: 'Aktualne' })).toBeInTheDocument();
|
||||
// telefon: „<” w topmenu (button); PC: „Wstecz” w treści (link) — ten sam powrót
|
||||
expect(screen.getByRole('button', { name: 'Wstecz' })).toBeInTheDocument();
|
||||
const back = screen.getByRole('link', { name: 'Wstecz' });
|
||||
expect(back).toHaveAttribute('href', '/plans');
|
||||
await user.click(back);
|
||||
|
||||
const templates = await screen.findByRole('link', { name: /^Szablony/ });
|
||||
expect(templates).toHaveAttribute('href', '/plans/templates');
|
||||
});
|
||||
@@ -218,6 +227,11 @@ describe('Podstrona „Aktualne” (/plans/current)', () => {
|
||||
// piątek, przyszła data + liczba ćwiczeń
|
||||
expect(within(hero).getByText('Piątek · 20.11.2026')).toBeInTheDocument();
|
||||
expect(within(hero).getByText('4 ćwiczenia')).toBeInTheDocument();
|
||||
// podgląd tygodnia: chipy dni treningowych + liczba ćwiczeń w tygodniu
|
||||
expect(within(hero).getByText(/Pon/)).toBeInTheDocument();
|
||||
expect(within(hero).getByText(/Śr/)).toBeInTheDocument();
|
||||
expect(within(hero).getByText(/Pt/)).toBeInTheDocument();
|
||||
expect(within(hero).getByText('6 ćwiczeń w tygodniu')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('gdy następny trening wypada dziś — hero pokazuje etykietę „dziś”', async () => {
|
||||
@@ -262,6 +276,22 @@ describe('Podstrona „Aktualne” (/plans/current)', () => {
|
||||
expect(screen.queryByRole('link', { name: /Plan masowy/ })).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('podział kategorii: pasek statusów zawęża listę do wybranej opcji', async () => {
|
||||
mockApi();
|
||||
const user = userEvent.setup();
|
||||
renderApp();
|
||||
await openCurrentPlans(user);
|
||||
|
||||
await user.click(await screen.findByRole('button', { name: 'Szkic' }));
|
||||
// tylko szkic — hero aktywnego planu znika
|
||||
expect(screen.getByRole('link', { name: /Szkic siłowy/ })).toBeInTheDocument();
|
||||
expect(screen.queryByRole('link', { name: /Plan masowy/ })).not.toBeInTheDocument();
|
||||
expect(screen.queryByText('Następny trening:')).not.toBeInTheDocument();
|
||||
|
||||
await user.click(screen.getByRole('button', { name: 'Wszystkie' }));
|
||||
expect(await screen.findByRole('link', { name: /Plan masowy/ })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('każdy kafelek jest linkiem otwierającym szczegóły planu', async () => {
|
||||
mockApi();
|
||||
const user = userEvent.setup();
|
||||
|
||||
@@ -128,6 +128,7 @@ function activePlan() {
|
||||
progress: { completed: 3, total: 8, percent: 38 },
|
||||
currentWeek: 2,
|
||||
nextDay: { date: tomorrow.toISOString().slice(0, 10), dayOfWeek: 3, exerciseCount: 4 },
|
||||
summary: { trainingDays: [1, 3], exercises: 5 },
|
||||
weeks: templateWeeks(true),
|
||||
};
|
||||
}
|
||||
@@ -333,6 +334,7 @@ test('hero aktywnego planu na „Aktualnych”: klik otwiera detal; bez ACTIVE
|
||||
await expect(page.getByText('Tydzień 2 z 4')).toBeVisible();
|
||||
await expect(page.getByText('Następny trening:')).toBeVisible();
|
||||
await expect(page.getByText('3/8 dni')).toBeVisible();
|
||||
await expect(page.getByText('5 ćwiczeń w tygodniu')).toBeVisible();
|
||||
|
||||
await page.getByRole('link', { name: /Plan aktywny e2e/ }).click();
|
||||
await expect(page.getByRole('heading', { name: 'Plan aktywny e2e' })).toBeVisible();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { test, expect, type Page } from './fixtures';
|
||||
import { mockPlans } from './mock-api';
|
||||
import { mockApi, mockPlans } from './mock-api';
|
||||
|
||||
async function login(page: Page) {
|
||||
await page.goto('/login');
|
||||
@@ -20,6 +20,80 @@ async function fillSetField(page: Page, fieldAria: string, value: string) {
|
||||
await expect(dialog).toBeHidden();
|
||||
}
|
||||
|
||||
test('kategorie: kafelki huba, podział statusów pod nagłówkiem i „Wstecz” do /plans', async ({
|
||||
page,
|
||||
}) => {
|
||||
mockApi(page);
|
||||
const nextWeek = new Date();
|
||||
nextWeek.setDate(nextWeek.getDate() + 7);
|
||||
page.route('**/api/v1/plans', (route) =>
|
||||
route.request().method() !== 'GET'
|
||||
? route.fallback()
|
||||
: route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({
|
||||
plans: [
|
||||
{
|
||||
id: 'k-plan-a',
|
||||
userId: 'user-test',
|
||||
kind: 'PLAN',
|
||||
canManage: true,
|
||||
title: 'Plan kategoria',
|
||||
status: 'ACTIVE',
|
||||
weeksCount: 4,
|
||||
startDate: '2026-10-05',
|
||||
gym: null,
|
||||
creator: null,
|
||||
progress: { completed: 1, total: 8, percent: 12 },
|
||||
currentWeek: 1,
|
||||
nextDay: { date: nextWeek.toISOString().slice(0, 10), dayOfWeek: 3, exerciseCount: 2 },
|
||||
summary: { trainingDays: [1, 3, 5], exercises: 6 },
|
||||
weeks: [],
|
||||
},
|
||||
{
|
||||
id: 'k-plan-d',
|
||||
userId: 'user-test',
|
||||
kind: 'PLAN',
|
||||
canManage: true,
|
||||
title: 'Szkic kategoria',
|
||||
status: 'DRAFT',
|
||||
weeksCount: 2,
|
||||
startDate: null,
|
||||
gym: null,
|
||||
creator: null,
|
||||
weeks: [],
|
||||
},
|
||||
],
|
||||
}),
|
||||
}),
|
||||
);
|
||||
await login(page);
|
||||
|
||||
await page.getByRole('link', { name: 'Plany treningowe' }).click();
|
||||
await expect(page.getByRole('heading', { name: 'Plany treningowe' })).toBeVisible();
|
||||
|
||||
// kafelek kategorii → podstrona z nagłówkiem kategorii i paskiem podziału (statusy)
|
||||
await page.getByRole('link', { name: /^Aktualne/ }).click();
|
||||
await expect(page.getByRole('heading', { name: 'Aktualne', exact: true })).toBeVisible();
|
||||
await expect(page.getByRole('button', { name: 'Wszystkie', exact: true })).toBeVisible();
|
||||
await expect(page.getByText('Następny trening:')).toBeVisible();
|
||||
// podgląd planu w karcie hero: chipy dni treningowych + ćwiczenia w tygodniu
|
||||
await expect(page.getByText('6 ćwiczeń w tygodniu')).toBeVisible();
|
||||
|
||||
// podział w kategorii: zawężenie listy do statusu (hero znika)
|
||||
await page.getByRole('button', { name: 'Szkic', exact: true }).click();
|
||||
await expect(page.getByText('Następny trening:')).toHaveCount(0);
|
||||
await expect(page.getByRole('link', { name: /Szkic kategoria/ })).toBeVisible();
|
||||
await page.getByRole('button', { name: 'Wszystkie', exact: true }).click();
|
||||
await expect(page.getByText('Następny trening:')).toBeVisible();
|
||||
|
||||
// powrót do huba i zmiana kategorii kafelkiem (jedyne menu między kategoriami)
|
||||
await page.getByRole('link', { name: 'Wstecz' }).click();
|
||||
await page.getByRole('link', { name: /^Archiwum/ }).click();
|
||||
await expect(page.getByRole('heading', { name: 'Archiwum', exact: true })).toBeVisible();
|
||||
});
|
||||
|
||||
test('formularz nowego planu ma wybór tygodnia startu i przycisk „Wstecz” w treści', async ({
|
||||
page,
|
||||
}) => {
|
||||
|
||||
Reference in New Issue
Block a user