Trening: nowo dodane cwiczenie rozwija sie automatycznie (przycisk "Dodaj serie" od razu widoczny)

This commit is contained in:
Tilumca
2026-10-14 22:07:33 +02:00
parent e7d344bc9e
commit 1bed564bfc
2 changed files with 13 additions and 2 deletions

View File

@@ -660,7 +660,9 @@ export default function DayExecution() {
if (!session || addingRef.current) return;
addingRef.current = true;
try {
await addSessionExercise(session.id, exerciseId);
const res = await addSessionExercise(session.id, exerciseId);
// nowe ćwiczenie rozwija się samo — „Dodaj serię” widoczne od razu, bez szukania
setExpandedIds((cur) => (cur.includes(res.exerciseId) ? cur : [...cur, res.exerciseId]));
await queryClient.invalidateQueries({ queryKey: ['sessions', session.id] });
} catch (e) {
setError(e instanceof Error ? e.message : 'Błąd');

View File

@@ -197,7 +197,8 @@ function mockApi(
const body = JSON.parse(String(init?.body)) as { exerciseId: string };
const ex = catalog.find((c) => c.id === body.exerciseId);
if (ex && !added.some((a) => a.id === ex.id)) added.push(ex);
return jsonResponse(200, { exerciseId: body.exerciseId });
// id wiersza sesji jak w fixture (se-x1, se-x2…) — front używa go do rozwinięcia akordeonu
return jsonResponse(200, { exerciseId: `se-x${added.length}` });
}
if (url.includes('/days/day-1'))
return jsonResponse(200, {
@@ -767,6 +768,14 @@ describe('Dodawanie ćwiczenia do sesji', () => {
await user.click(within(dialog).getByRole('button', { name: /Martwy ciąg/ }));
expect(await screen.findByRole('heading', { name: 'Martwy ciąg' })).toBeInTheDocument();
expect(screen.queryByRole('dialog')).not.toBeInTheDocument();
// dodane ćwiczenie rozwija się automatycznie — „Dodaj serię” od razu pod ręką
expect(screen.getByRole('button', { name: /Martwy ciąg/ })).toHaveAttribute(
'aria-expanded',
'true',
);
// otwarte akordeony: Wyciskanie (auto, następna seria) + Martwy ciąg => 2 przyciski
expect(screen.getAllByRole('button', { name: 'Dodaj serię' })).toHaveLength(2);
});
it('pusty katalog ćwiczeń pokazuje komunikat w modalu', async () => {