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)
This commit is contained in:
@@ -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),
|
||||
],
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user