Trening: timer przerwy w oknie uzupelniania serii (wskazanie, ze zapis zrestartuje odliczanie)
This commit is contained in:
@@ -235,6 +235,11 @@ export type SetFieldValues = { reps: string; rir: string; difficulty: string };
|
||||
|
||||
export type PlannedValues = { reps: number | null; rir: number | null; difficulty: number | null };
|
||||
|
||||
/* Trwająca przerwa pokazana w oknie serii (timer + informacja, że zapis zrestartuje odliczanie). */
|
||||
export type SetEditRestInfo = { remaining: number; total: number; resetsOnSave: boolean };
|
||||
|
||||
const fmtRestSec = (sec: number) => `${Math.floor(sec / 60)}:${String(sec % 60).padStart(2, '0')}`;
|
||||
|
||||
/* Bulk set editor — fill in all set fields at once (each via the number pad). */
|
||||
export function SetEditDialog({
|
||||
open,
|
||||
@@ -242,6 +247,7 @@ export function SetEditDialog({
|
||||
values,
|
||||
planned,
|
||||
title,
|
||||
rest,
|
||||
onSave,
|
||||
onClose,
|
||||
}: {
|
||||
@@ -251,6 +257,8 @@ export function SetEditDialog({
|
||||
planned: PlannedValues;
|
||||
/** Tytuł okna — domyślnie „Uzupełnij serię N” (przekazuj „Edytuj serię N” dla uzupełnionych serii). */
|
||||
title?: string;
|
||||
/** Trwająca przerwa — timer odświeżany co sekundę przez rodzica. */
|
||||
rest?: SetEditRestInfo | null;
|
||||
onSave: (values: SetFieldValues) => void;
|
||||
onClose: () => void;
|
||||
}) {
|
||||
@@ -274,6 +282,23 @@ export function SetEditDialog({
|
||||
return (
|
||||
<>
|
||||
<Modal open={open} onClose={onClose} title={title ?? `Uzupełnij serię ${setIndex + 1}`}>
|
||||
{rest && rest.remaining > 0 && (
|
||||
<div className="mb-3 rounded-[10px] border border-line bg-input px-3.5 py-3">
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="live-dot" aria-hidden="true" />
|
||||
<span className="text-[0.8125rem] text-dim">przerwa</span>
|
||||
<b className="font-display text-[1rem] font-bold tabular-nums text-ink">
|
||||
{fmtRestSec(rest.remaining)}
|
||||
</b>
|
||||
<span className="text-[0.8125rem] text-dim">/ {fmtRestSec(rest.total)}</span>
|
||||
</div>
|
||||
{rest.resetsOnSave && (
|
||||
<p className="text-dim text-[0.8125rem] mt-1.5">
|
||||
Zapisanie serii zrestartuje odliczanie przerwy.
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
{hasNorm && (
|
||||
<Button variant="secondary" size="sm" onClick={fillNorm} className="mb-3 w-full">
|
||||
Norma spełniona
|
||||
|
||||
@@ -722,6 +722,21 @@ export default function DayExecution() {
|
||||
? `Edytuj serię ${editSet.index + 1}`
|
||||
: undefined
|
||||
}
|
||||
rest={
|
||||
rest && restRemaining > 0
|
||||
? {
|
||||
remaining: restRemaining,
|
||||
total: rest.totalSec,
|
||||
// odliczanie restartuje tylko przy pierwszym uzupełnieniu serii z zaplanowaną przerwą
|
||||
resetsOnSave:
|
||||
editSet?.restSec != null &&
|
||||
(editSetData == null ||
|
||||
(editSetData.reps == null &&
|
||||
editSetData.rir == null &&
|
||||
editSetData.difficulty == null)),
|
||||
}
|
||||
: null
|
||||
}
|
||||
onClose={() => setEditSet(null)}
|
||||
onSave={(values) => {
|
||||
if (editSet) saveSetFields(editSet.setId, values);
|
||||
|
||||
@@ -75,7 +75,16 @@ function sessionBody(
|
||||
],
|
||||
},
|
||||
sets: [
|
||||
{ id: 'ss-1', planSetId: 'ps-1', index: indices['ss-1'] ?? 0, reps: reps['ss-1'], rir: 2, difficulty: 3, note: null },
|
||||
{
|
||||
id: 'ss-1',
|
||||
planSetId: 'ps-1',
|
||||
index: indices['ss-1'] ?? 0,
|
||||
reps: reps['ss-1'],
|
||||
// pusta seria nie ma wpisanych rir/trudności (wtedy przycisk to „Uzupełnij serię”, nie „Edytuj”)
|
||||
rir: reps['ss-1'] != null ? 2 : null,
|
||||
difficulty: reps['ss-1'] != null ? 3 : null,
|
||||
note: null,
|
||||
},
|
||||
{ id: 'ss-2', planSetId: 'ps-2', index: indices['ss-2'] ?? 1, reps: reps['ss-2'], rir: null, difficulty: null, note: null },
|
||||
],
|
||||
},
|
||||
@@ -438,6 +447,60 @@ describe('Kolejka serii w sesji', () => {
|
||||
expect(screen.getByText(/^\d+:\d{2}$/)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('pokazuje w oknie „Uzupełnij serię” timer trwającej przerwy z informacją o resecie', async () => {
|
||||
mockApi({ 'ss-1': null, 'ss-2': null, 'ss-3': null });
|
||||
const user = userEvent.setup();
|
||||
renderApp();
|
||||
await openActiveDay(user);
|
||||
|
||||
// uzupełnij ss-1 i zapisz — startuje odliczanie przerwy (90 s z planu)
|
||||
await user.click(screen.getAllByRole('button', { name: 'Uzupełnij serię' })[0]);
|
||||
await screen.findByRole('heading', { name: 'Uzupełnij serię 1' });
|
||||
await user.click(screen.getByRole('button', { name: 'Norma spełniona' }));
|
||||
await user.click(screen.getByRole('button', { name: 'Zapisz' }));
|
||||
expect(await screen.findByRole('button', { name: 'Zakończ' })).toBeInTheDocument();
|
||||
|
||||
// otwórz okno niezapisanej serii z zaplanowaną przerwą (mock nie utrzymuje zapisu,
|
||||
// więc ss-1 nadal jest pusta) — timer + informacja o resecie
|
||||
await user.click(screen.getAllByRole('button', { name: 'Uzupełnij serię' })[0]);
|
||||
const dialog = await screen.findByRole('dialog');
|
||||
expect(within(dialog).getByText('przerwa')).toBeInTheDocument();
|
||||
expect(within(dialog).getByText(/^\d+:\d{2}$/)).toBeInTheDocument();
|
||||
expect(within(dialog).getByText(/zrestartuje odliczanie przerwy/)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('w oknie serii bonusowej pokazuje timer przerwy bez informacji o resecie', async () => {
|
||||
mockApi({ 'ss-1': null, 'ss-2': null, 'ss-3': null });
|
||||
const user = userEvent.setup();
|
||||
renderApp();
|
||||
await openActiveDay(user);
|
||||
|
||||
// uzupełnij ss-1 i zapisz — startuje odliczanie przerwy
|
||||
await user.click(screen.getAllByRole('button', { name: 'Uzupełnij serię' })[0]);
|
||||
await screen.findByRole('heading', { name: 'Uzupełnij serię 1' });
|
||||
await user.click(screen.getByRole('button', { name: 'Norma spełniona' }));
|
||||
await user.click(screen.getByRole('button', { name: 'Zapisz' }));
|
||||
expect(await screen.findByRole('button', { name: 'Zakończ' })).toBeInTheDocument();
|
||||
|
||||
// ss-3 to bonus (bez zaplanowanej przerwy) — rozwijamy Wyciskanie i otwieramy okno
|
||||
await user.click(screen.getByRole('button', { name: /Wyciskanie/ }));
|
||||
await user.click(screen.getByRole('button', { name: 'Uzupełnij serię' }));
|
||||
const dialog = await screen.findByRole('dialog');
|
||||
expect(within(dialog).getByText('przerwa')).toBeInTheDocument();
|
||||
expect(within(dialog).queryByText(/zrestartuje odliczanie przerwy/)).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('nie pokazuje timera przerwy w oknie serii, gdy przerwa nie trwa', async () => {
|
||||
mockApi({ 'ss-1': null, 'ss-2': null, 'ss-3': null });
|
||||
const user = userEvent.setup();
|
||||
renderApp();
|
||||
await openActiveDay(user);
|
||||
|
||||
await user.click(screen.getAllByRole('button', { name: 'Uzupełnij serię' })[0]);
|
||||
const dialog = await screen.findByRole('dialog');
|
||||
expect(within(dialog).queryByText('przerwa')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('nie startuje odliczania przy edycji już uzupełnionej serii', async () => {
|
||||
mockApi({ 'ss-1': 10, 'ss-2': null, 'ss-3': null });
|
||||
const user = userEvent.setup();
|
||||
|
||||
@@ -63,6 +63,34 @@ test('uzupełnia serię wsadowo przez okno „Uzupełnij serię”', async ({ pa
|
||||
await expect(page.getByRole('button', { name: 'Zakończ' })).toBeVisible();
|
||||
});
|
||||
|
||||
test('okno „Uzupełnij serię” pokazuje timer trwającej przerwy', async ({ page }) => {
|
||||
mockDayExecution(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();
|
||||
|
||||
await page.getByRole('button', { name: 'Wykonaj trening' }).click();
|
||||
await expect(page.getByText('Przysiady')).toBeVisible();
|
||||
|
||||
// uzupełnij ss-1 i zapisz — startuje odliczanie przerwy (rest 90 s z planu)
|
||||
await page.getByRole('button', { name: 'Uzupełnij serię' }).first().click();
|
||||
await page.getByRole('button', { name: 'Norma spełniona' }).click();
|
||||
await page.getByRole('button', { name: 'Zapisz' }).click();
|
||||
await expect(page.getByRole('button', { name: 'Zakończ' })).toBeVisible();
|
||||
|
||||
// otwórz okno serii bonusowej (ss-2, bez zaplanowanej przerwy) —
|
||||
// rozwinięcie Wyciskania zwija Przysiady; w oknie widoczny timer przerwy,
|
||||
// ale bez informacji o resecie odliczania
|
||||
await page.getByRole('button', { name: /Wyciskanie/ }).click();
|
||||
await page.getByRole('button', { name: 'Uzupełnij serię' }).click();
|
||||
const dialog = page.getByRole('dialog');
|
||||
await expect(dialog.getByText('przerwa')).toBeVisible();
|
||||
await expect(dialog.getByText(/zrestartuje odliczanie przerwy/)).toBeHidden();
|
||||
});
|
||||
|
||||
test('przycisk „Norma spełniona” wypełnia wartości z planu', async ({ page }) => {
|
||||
mockDayExecution(page);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user