chore: change test for actions
This commit is contained in:
parent
25bca13265
commit
3218ca46cb
1 changed files with 12 additions and 4 deletions
16
fsm.test.ts
16
fsm.test.ts
|
@ -83,15 +83,20 @@ Deno.test("should change state", async function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
Deno.test("should trigger state actions", async function () {
|
Deno.test("should trigger state actions", async function () {
|
||||||
|
const triggeredTimes = {
|
||||||
|
beforeExit: 0,
|
||||||
|
onEntry: 0,
|
||||||
|
};
|
||||||
|
|
||||||
const sm = new fsm.StateMachineBuilder()
|
const sm = new fsm.StateMachineBuilder()
|
||||||
.withStates(
|
.withStates(
|
||||||
Object.values(ProjectStatus),
|
Object.values(ProjectStatus),
|
||||||
{
|
{
|
||||||
onEntry(fromState, toState) {
|
onEntry() {
|
||||||
console.log(`changing from ${fromState} to ${toState}`);
|
triggeredTimes.onEntry += 1;
|
||||||
},
|
},
|
||||||
beforeExit(fromState, toState) {
|
beforeExit() {
|
||||||
console.log(`before changing from ${fromState} to ${toState}`);
|
triggeredTimes.beforeExit += 1;
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -104,12 +109,15 @@ Deno.test("should trigger state actions", async function () {
|
||||||
|
|
||||||
const [, active, completed, archived] = sm[fsm._states];
|
const [, active, completed, archived] = sm[fsm._states];
|
||||||
|
|
||||||
|
assertEquals(triggeredTimes, { beforeExit: 0, onEntry: 0 });
|
||||||
assertEquals(sm.allowedTransitionStates(), [active, archived]);
|
assertEquals(sm.allowedTransitionStates(), [active, archived]);
|
||||||
|
|
||||||
await sm.changeState(ProjectStatus.Active);
|
await sm.changeState(ProjectStatus.Active);
|
||||||
|
assertEquals(triggeredTimes, { beforeExit: 1, onEntry: 1 });
|
||||||
assertEquals(sm.allowedTransitionStates(), [completed]);
|
assertEquals(sm.allowedTransitionStates(), [completed]);
|
||||||
|
|
||||||
await sm.changeState(ProjectStatus.Completed);
|
await sm.changeState(ProjectStatus.Completed);
|
||||||
|
assertEquals(triggeredTimes, { beforeExit: 2, onEntry: 2 });
|
||||||
assertEquals(sm.allowedTransitionStates(), []);
|
assertEquals(sm.allowedTransitionStates(), []);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue