Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions core/src/activity-utils/makeActivityReducer.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { makeEvent } from "../event-utils";
import type { Activity } from "../Stack";
import { makeActivityReducer } from "./makeActivityReducer";

function makeActivity(): Activity {
const pushedEvent = makeEvent("Pushed", {
activityId: "a1",
activityName: "sample",
activityParams: { page: "1" },
});

const stepPushedEvent = makeEvent("StepPushed", {
stepId: "s2",
stepParams: { page: "2" },
});

return {
id: "a1",
name: "sample",
transitionState: "enter-done",
params: { page: "2" },
enteredBy: pushedEvent,
steps: [
{
id: "a1",
params: { page: "1" },
enteredBy: pushedEvent,
zIndex: -1,
},
{
id: "s2",
params: { page: "2" },
enteredBy: stepPushedEvent,
zIndex: -1,
},
],
isTop: true,
isActive: true,
isRoot: true,
zIndex: 0,
};
}

test("makeActivityReducer - StepPopped는 activity.steps를 변경하지 않고 새 배열을 반환합니다", () => {
const activity = makeActivity();
const originalSteps = activity.steps;

const reducer = makeActivityReducer({ transitionDuration: 300, now: 0 });
const stepPoppedEvent = makeEvent("StepPopped", {});

const nextActivity = reducer(activity, stepPoppedEvent);

expect(activity.steps).toBe(originalSteps);
expect(activity.steps.length).toBe(2);
expect(nextActivity.steps).not.toBe(originalSteps);
expect(nextActivity.steps.length).toBe(1);
expect(nextActivity.params).toEqual({ page: "1" });
});
5 changes: 3 additions & 2 deletions core/src/activity-utils/makeActivityReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,14 @@ export function makeActivityReducer(context: {
* If there are params in the previous step, set them as the new params
*/
StepPopped: (activity: Activity, event: StepPoppedEvent): Activity => {
activity.steps.pop();
const steps = activity.steps.slice(0, -1);

const beforeActivityParams = last(activity.steps)?.params;
const beforeActivityParams = last(steps)?.params;

return {
...activity,
params: beforeActivityParams ?? activity.params,
steps,
};
},

Expand Down