From 8e280a4ca4847fda4351bbac0c3f0ab3f9422fce Mon Sep 17 00:00:00 2001 From: tisachi Date: Wed, 2 Dec 2026 17:53:56 +0100 Subject: [PATCH] App: kopia serii w edytorze planu nie dziedziczy id wiersza (duplicateSet i addSetCopy rzucaja id kopii; wczesniej kopia serii z bazy wysylala w payloadzie ten sam id co oryginal, a reconcileExerciseSets odrzucal zapis bledem duplicated set id in plan payload; + 2 testy regresji przez initFromPlan) --- .../plans/plan-editor/usePlanEditorState.ts | 9 +++- app/test/plan-editor-state.test.ts | 46 +++++++++++++++++++ 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/app/src/pages/plans/plan-editor/usePlanEditorState.ts b/app/src/pages/plans/plan-editor/usePlanEditorState.ts index 83604fc..dab4600 100644 --- a/app/src/pages/plans/plan-editor/usePlanEditorState.ts +++ b/app/src/pages/plans/plan-editor/usePlanEditorState.ts @@ -221,7 +221,12 @@ export function usePlanEditorState() { ? { ...d, exercises: d.exercises.map((ex, x) => - x === ei ? { ...ex, sets: [...ex.sets, { ...ex.sets[ex.sets.length - 1] }] } : ex, + x === ei + ? { + ...ex, + sets: [...ex.sets, { ...ex.sets[ex.sets.length - 1], id: undefined }], + } + : ex, ), } : d, @@ -244,7 +249,7 @@ export function usePlanEditorState() { ...ex, sets: [ ...ex.sets.slice(0, si + 1), - structuredClone(ex.sets[si]), + { ...structuredClone(ex.sets[si]), id: undefined }, ...ex.sets.slice(si + 1), ], } diff --git a/app/test/plan-editor-state.test.ts b/app/test/plan-editor-state.test.ts index e25cd81..30fbf76 100644 --- a/app/test/plan-editor-state.test.ts +++ b/app/test/plan-editor-state.test.ts @@ -68,6 +68,52 @@ describe('usePlanEditorState — akcje mutacji', () => { expect(added.restSec).toBe('180'); }); + // Reprodukcja "duplicated set id in plan payload": kopia serii z bazy nie może + // dziedziczyć id wiersza — inaczej payload ma dwa inputy z tym samym id. + const planWithSetId: PlanLike = { + title: 'P', + weeksCount: 1, + weeks: [ + { + index: 0, + days: [ + { + id: 'day-1', + dayOfWeek: 1, + exercises: [ + { + id: 'ex-1', + exerciseId: 'e1', + sets: [{ id: 'set-1', reps: 8, loadKg: 20, restSec: 180, rir: 2 }], + }, + ], + }, + ], + }, + ], + }; + + it('duplicateSet rzuca id kopii (kopia serii z bazy ≠ ten sam wiersz)', () => { + const { result } = renderHook(() => usePlanEditorState()); + act(() => result.current.initFromPlan(planWithSetId)); + act(() => result.current.duplicateSet(0, 0, 0, 0)); + const sets = result.current.weeks[0].days[0].exercises[0].sets; + expect(sets).toHaveLength(2); + expect(sets[0].id).toBe('set-1'); + expect(sets[1].id).toBeUndefined(); + expect(sets[1].reps).toBe('8'); + }); + + it('addSetCopy rzuca id kopii ostatniej serii z bazy', () => { + const { result } = renderHook(() => usePlanEditorState()); + act(() => result.current.initFromPlan(planWithSetId)); + act(() => result.current.addSetCopy(0, 0, 0)); + const sets = result.current.weeks[0].days[0].exercises[0].sets; + expect(sets).toHaveLength(2); + expect(sets[0].id).toBe('set-1'); + expect(sets[1].id).toBeUndefined(); + }); + it('detachWeek odłącza lustrzany tydzień (niezależna kopia dni z tygodnia 1)', () => { const { result } = renderHook(() => usePlanEditorState()); act(() => result.current.addDay(0, 1));