Skip to content

Commit

Permalink
Remove some duplicated test cases (#4493)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andarist authored Nov 24, 2023
1 parent 4b1c854 commit ac3ba5e
Showing 1 changed file with 2 additions and 172 deletions.
174 changes: 2 additions & 172 deletions packages/core/test/transient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,63 +255,6 @@ describe('transient states (eventless transitions)', () => {
expect(actorRef.getSnapshot().value).toEqual({ A: 'A4', B: 'B4' });
});

it('should execute all eventless transitions in the same microstep (with `always`)', () => {
const machine = createMachine({
type: 'parallel',
states: {
A: {
initial: 'A1',
states: {
A1: {
on: {
E: 'A2' // the external event
}
},
A2: {
always: 'A3'
},
A3: {
always: {
target: 'A4',
guard: stateIn({ B: 'B3' })
}
},
A4: {}
}
},

B: {
initial: 'B1',
states: {
B1: {
on: {
E: 'B2'
}
},
B2: {
always: {
target: 'B3',
guard: stateIn({ A: 'A2' })
}
},
B3: {
always: {
target: 'B4',
guard: stateIn({ A: 'A3' })
}
},
B4: {}
}
}
}
});

const actorRef = createActor(machine).start();
actorRef.send({ type: 'E' });

expect(actorRef.getSnapshot().value).toEqual({ A: 'A4', B: 'B4' });
});

it('should check for automatic transitions even after microsteps are done', () => {
const machine = createMachine({
type: 'parallel',
Expand Down Expand Up @@ -360,54 +303,6 @@ describe('transient states (eventless transitions)', () => {
expect(actorRef.getSnapshot().value).toEqual({ A: 'A2', B: 'B2', C: 'C2' });
});

it('should check for automatic transitions even after microsteps are done (with `always`)', () => {
const machine = createMachine({
type: 'parallel',
states: {
A: {
initial: 'A1',
states: {
A1: {
on: {
A: 'A2'
}
},
A2: { id: 'A2' }
}
},
B: {
initial: 'B1',
states: {
B1: {
always: {
target: 'B2',
guard: stateIn({ A: 'A2' })
}
},
B2: {}
}
},
C: {
initial: 'C1',
states: {
C1: {
always: {
target: 'C2',
guard: stateIn('#A2')
}
},
C2: {}
}
}
}
});

const actorRef = createActor(machine).start();
actorRef.send({ type: 'A' });

expect(actorRef.getSnapshot().value).toEqual({ A: 'A2', B: 'B2', C: 'C2' });
});

it('should determine the resolved initial state from the transient state', () => {
expect(createActor(greetingMachine).getSnapshot().value).toEqual('morning');
});
Expand Down Expand Up @@ -454,26 +349,6 @@ describe('transient states (eventless transitions)', () => {
expect(actorRef.getSnapshot().value).toBe('e');
});

it('should not select wildcard for eventless transition', () => {
const machine = createMachine({
initial: 'a',
states: {
a: {
on: { FOO: 'b' }
},
b: {
on: { '*': 'fail' }
},
fail: {}
}
});

const actorRef = createActor(machine).start();
actorRef.send({ type: 'FOO' });

expect(actorRef.getSnapshot().value).toBe('b');
});

it('should not select wildcard for eventless transition', () => {
const machine = createMachine({
initial: 'a',
Expand Down Expand Up @@ -532,41 +407,6 @@ describe('transient states (eventless transitions)', () => {
expect(actorRef.getSnapshot().status).toBe('done');
});

it('should work with transient transition on root (with `always`)', () => {
const machine = createMachine({
types: {} as { context: { count: number } },
id: 'machine',
initial: 'first',
context: { count: 0 },
states: {
first: {
on: {
ADD: {
actions: assign({ count: ({ context }) => context.count + 1 })
}
}
},
success: {
type: 'final'
}
},

always: [
{
target: '.success',
guard: ({ context }) => {
return context.count > 0;
}
}
]
});

const actorRef = createActor(machine).start();
actorRef.send({ type: 'ADD' });

expect(actorRef.getSnapshot().status).toBe('done');
});

it("shouldn't crash when invoking a machine with initial transient transition depending on custom data", () => {
const timerMachine = createMachine({
initial: 'initial',
Expand Down Expand Up @@ -615,42 +455,33 @@ describe('transient states (eventless transitions)', () => {
});

it('should be taken even in absence of other transitions', () => {
let shouldMatch = false;

const machine = createMachine({
initial: 'a',
states: {
a: {
always: {
target: 'b',
// TODO: in v5 remove `shouldMatch` and replace this guard with:
// guard: (ctx, ev) => ev.type === 'WHATEVER'
guard: () => shouldMatch
guard: ({ event }) => event.type === 'WHATEVER'
}
},
b: {}
}
});
const actorRef = createActor(machine).start();

shouldMatch = true;
actorRef.send({ type: 'WHATEVER' });

expect(actorRef.getSnapshot().value).toBe('b');
});

it('should select subsequent transient transitions even in absence of other transitions', () => {
let shouldMatch = false;

const machine = createMachine({
initial: 'a',
states: {
a: {
always: {
target: 'b',
// TODO: in v5 remove `shouldMatch` and replace this guard with:
// guard: (ctx, ev) => ev.type === 'WHATEVER'
guard: () => shouldMatch
guard: ({ event }) => event.type === 'WHATEVER'
}
},
b: {
Expand All @@ -665,7 +496,6 @@ describe('transient states (eventless transitions)', () => {

const actorRef = createActor(machine).start();

shouldMatch = true;
actorRef.send({ type: 'WHATEVER' });

expect(actorRef.getSnapshot().value).toBe('c');
Expand Down

0 comments on commit ac3ba5e

Please sign in to comment.