Eingebette Loops
This commit is contained in:
1 parent
684217bdf4
commit
5a171987b2
5 files changed
+722
-50
No files matched your search
@@ -9,6 +9,10 @@ import {
|
||||
moveItemUp,
|
||||
moveItemDown,
|
||||
clearDraft,
|
||||
setActiveItemStepIndex,
|
||||
itemNextStep,
|
||||
itemPrevStep,
|
||||
resetItemWizard,
|
||||
type LoopRuntimeState,
|
||||
} from "../../interview/loopState";
|
||||
|
||||
@@ -114,6 +118,7 @@ describe("loopState", () => {
|
||||
items: [{ field1: "old" }],
|
||||
draft: { field1: "new" },
|
||||
editIndex: 0,
|
||||
activeItemStepIndex: 0,
|
||||
};
|
||||
|
||||
const newState = commitDraft(state);
|
||||
@@ -146,6 +151,7 @@ describe("loopState", () => {
|
||||
items: [{ field1: "value1", field2: "value2" }],
|
||||
draft: {},
|
||||
editIndex: null,
|
||||
activeItemStepIndex: 0,
|
||||
};
|
||||
|
||||
const newState = startEdit(state, 0);
|
||||
@@ -160,6 +166,7 @@ describe("loopState", () => {
|
||||
items: [{ field1: "value1" }],
|
||||
draft: {},
|
||||
editIndex: null,
|
||||
activeItemStepIndex: 0,
|
||||
};
|
||||
|
||||
const newState = startEdit(state, 5);
|
||||
@@ -172,6 +179,7 @@ describe("loopState", () => {
|
||||
items: [{ field1: "value1" }],
|
||||
draft: {},
|
||||
editIndex: null,
|
||||
activeItemStepIndex: 0,
|
||||
};
|
||||
|
||||
startEdit(state, 0);
|
||||
@@ -186,6 +194,7 @@ describe("loopState", () => {
|
||||
items: [{ id: 1 }, { id: 2 }, { id: 3 }],
|
||||
draft: {},
|
||||
editIndex: null,
|
||||
activeItemStepIndex: 0,
|
||||
};
|
||||
|
||||
const newState = deleteItem(state, 1);
|
||||
@@ -200,6 +209,7 @@ describe("loopState", () => {
|
||||
items: [{ id: 1 }, { id: 2 }],
|
||||
draft: { id: 2 },
|
||||
editIndex: 1,
|
||||
activeItemStepIndex: 1,
|
||||
};
|
||||
|
||||
const newState = deleteItem(state, 1);
|
||||
@@ -214,6 +224,7 @@ describe("loopState", () => {
|
||||
items: [{ id: 1 }, { id: 2 }, { id: 3 }],
|
||||
draft: { id: 3 },
|
||||
editIndex: 2,
|
||||
activeItemStepIndex: 0,
|
||||
};
|
||||
|
||||
const newState = deleteItem(state, 1);
|
||||
@@ -227,6 +238,7 @@ describe("loopState", () => {
|
||||
items: [{ id: 1 }],
|
||||
draft: {},
|
||||
editIndex: null,
|
||||
activeItemStepIndex: 0,
|
||||
};
|
||||
|
||||
const newState = deleteItem(state, 5);
|
||||
@@ -240,6 +252,7 @@ describe("loopState", () => {
|
||||
items: [{ id: 1 }, { id: 2 }, { id: 3 }],
|
||||
draft: {},
|
||||
editIndex: null,
|
||||
activeItemStepIndex: 0,
|
||||
};
|
||||
|
||||
const newState = moveItemUp(state, 1);
|
||||
@@ -254,6 +267,7 @@ describe("loopState", () => {
|
||||
items: [{ id: 1 }, { id: 2 }],
|
||||
draft: { id: 2 },
|
||||
editIndex: 1,
|
||||
activeItemStepIndex: 0,
|
||||
};
|
||||
|
||||
const newState = moveItemUp(state, 1);
|
||||
@@ -267,6 +281,7 @@ describe("loopState", () => {
|
||||
items: [{ id: 1 }, { id: 2 }, { id: 3 }],
|
||||
draft: { id: 3 },
|
||||
editIndex: 2,
|
||||
activeItemStepIndex: 0,
|
||||
};
|
||||
|
||||
const newState = moveItemUp(state, 1);
|
||||
@@ -283,6 +298,7 @@ describe("loopState", () => {
|
||||
items: [{ id: 1 }, { id: 2 }],
|
||||
draft: {},
|
||||
editIndex: null,
|
||||
activeItemStepIndex: 0,
|
||||
};
|
||||
|
||||
const newState = moveItemUp(state, 0);
|
||||
@@ -294,6 +310,7 @@ describe("loopState", () => {
|
||||
items: [{ id: 1 }],
|
||||
draft: {},
|
||||
editIndex: null,
|
||||
activeItemStepIndex: 0,
|
||||
};
|
||||
|
||||
const newState = moveItemUp(state, 5);
|
||||
@@ -307,6 +324,7 @@ describe("loopState", () => {
|
||||
items: [{ id: 1 }, { id: 2 }, { id: 3 }],
|
||||
draft: {},
|
||||
editIndex: null,
|
||||
activeItemStepIndex: 0,
|
||||
};
|
||||
|
||||
const newState = moveItemDown(state, 1);
|
||||
@@ -321,6 +339,7 @@ describe("loopState", () => {
|
||||
items: [{ id: 1 }, { id: 2 }],
|
||||
draft: { id: 1 },
|
||||
editIndex: 0,
|
||||
activeItemStepIndex: 0,
|
||||
};
|
||||
|
||||
const newState = moveItemDown(state, 0);
|
||||
@@ -335,6 +354,7 @@ describe("loopState", () => {
|
||||
items: [{ id: 1 }, { id: 2 }],
|
||||
draft: {},
|
||||
editIndex: null,
|
||||
activeItemStepIndex: 0,
|
||||
};
|
||||
|
||||
const newState = moveItemDown(state, 1);
|
||||
@@ -346,6 +366,7 @@ describe("loopState", () => {
|
||||
items: [{ id: 1 }],
|
||||
draft: {},
|
||||
editIndex: null,
|
||||
activeItemStepIndex: 0,
|
||||
};
|
||||
|
||||
const newState = moveItemDown(state, 5);
|
||||
@@ -359,6 +380,7 @@ describe("loopState", () => {
|
||||
items: [{ id: 1 }],
|
||||
draft: { field1: "value1" },
|
||||
editIndex: 0,
|
||||
activeItemStepIndex: 2,
|
||||
};
|
||||
|
||||
const newState = clearDraft(state);
|
||||
@@ -373,11 +395,126 @@ describe("loopState", () => {
|
||||
items: [],
|
||||
draft: { field1: "value1" },
|
||||
editIndex: 0,
|
||||
activeItemStepIndex: 1,
|
||||
};
|
||||
|
||||
clearDraft(state);
|
||||
expect(state.draft).toEqual({ field1: "value1" });
|
||||
expect(state.editIndex).toBe(0);
|
||||
expect(state.activeItemStepIndex).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe("subwizard navigation", () => {
|
||||
it("should set active item step index", () => {
|
||||
const state = createLoopState();
|
||||
const newState = setActiveItemStepIndex(state, 2);
|
||||
expect(newState.activeItemStepIndex).toBe(2);
|
||||
expect(newState.items).toEqual([]);
|
||||
});
|
||||
|
||||
it("should not set negative index", () => {
|
||||
const state = createLoopState();
|
||||
const newState = setActiveItemStepIndex(state, -1);
|
||||
expect(newState).toBe(state); // Should return unchanged
|
||||
});
|
||||
|
||||
it("should move to next step", () => {
|
||||
const state = createLoopState();
|
||||
let newState = itemNextStep(state, 3);
|
||||
expect(newState.activeItemStepIndex).toBe(1);
|
||||
|
||||
newState = itemNextStep(newState, 3);
|
||||
expect(newState.activeItemStepIndex).toBe(2);
|
||||
});
|
||||
|
||||
it("should not move beyond last step", () => {
|
||||
const state: LoopRuntimeState = {
|
||||
items: [],
|
||||
draft: {},
|
||||
editIndex: null,
|
||||
activeItemStepIndex: 2,
|
||||
};
|
||||
|
||||
const newState = itemNextStep(state, 3);
|
||||
expect(newState).toBe(state); // Should return unchanged
|
||||
});
|
||||
|
||||
it("should move to previous step", () => {
|
||||
const state: LoopRuntimeState = {
|
||||
items: [],
|
||||
draft: {},
|
||||
editIndex: null,
|
||||
activeItemStepIndex: 2,
|
||||
};
|
||||
|
||||
let newState = itemPrevStep(state);
|
||||
expect(newState.activeItemStepIndex).toBe(1);
|
||||
|
||||
newState = itemPrevStep(newState);
|
||||
expect(newState.activeItemStepIndex).toBe(0);
|
||||
});
|
||||
|
||||
it("should not move before first step", () => {
|
||||
const state = createLoopState();
|
||||
const newState = itemPrevStep(state);
|
||||
expect(newState).toBe(state); // Should return unchanged
|
||||
});
|
||||
|
||||
it("should reset item wizard to first step", () => {
|
||||
const state: LoopRuntimeState = {
|
||||
items: [],
|
||||
draft: {},
|
||||
editIndex: null,
|
||||
activeItemStepIndex: 3,
|
||||
};
|
||||
|
||||
const newState = resetItemWizard(state);
|
||||
expect(newState.activeItemStepIndex).toBe(0);
|
||||
});
|
||||
|
||||
it("should reset to first step when starting edit", () => {
|
||||
const state: LoopRuntimeState = {
|
||||
items: [{ field1: "value1" }],
|
||||
draft: {},
|
||||
editIndex: null,
|
||||
activeItemStepIndex: 2,
|
||||
};
|
||||
|
||||
const newState = startEdit(state, 0);
|
||||
expect(newState.activeItemStepIndex).toBe(0);
|
||||
expect(newState.editIndex).toBe(0);
|
||||
});
|
||||
|
||||
it("should reset to first step when committing draft", () => {
|
||||
const state: LoopRuntimeState = {
|
||||
items: [],
|
||||
draft: { field1: "value1" },
|
||||
editIndex: null,
|
||||
activeItemStepIndex: 2,
|
||||
};
|
||||
|
||||
const newState = commitDraft(state);
|
||||
expect(newState.activeItemStepIndex).toBe(0);
|
||||
expect(newState.items.length).toBe(1);
|
||||
});
|
||||
|
||||
it("should allow commit:on_next even when not on last step", () => {
|
||||
// Test that commit logic works regardless of activeItemStepIndex
|
||||
const state: LoopRuntimeState = {
|
||||
items: [],
|
||||
draft: { field1: "value1", field2: "value2" },
|
||||
editIndex: null,
|
||||
activeItemStepIndex: 1, // Not on last step
|
||||
};
|
||||
|
||||
// Draft is dirty, should commit
|
||||
expect(isDraftDirty(state.draft)).toBe(true);
|
||||
|
||||
const newState = commitDraft(state);
|
||||
expect(newState.items.length).toBe(1);
|
||||
expect(newState.activeItemStepIndex).toBe(0);
|
||||
expect(newState.draft).toEqual({});
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user