deno.land / x / xstate@xstate@4.33.6 / test / multiple.test.ts
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201import { Machine } from '../src/index';
describe('multiple', () => { const machine = Machine({ key: 'machine', initial: 'simple', states: { simple: { on: { DEEP_M: 'para.K.M', DEEP_CM: [{ target: ['para.A.C', 'para.K.M'] }], DEEP_MR: [{ target: ['para.K.M', 'para.P.R'] }], DEEP_CMR: [{ target: ['para.A.C', 'para.K.M', 'para.P.R'] }], BROKEN_SAME_REGION: [{ target: ['para.A.C', 'para.A.B'] }], BROKEN_DIFFERENT_REGIONS: [ { target: ['para.A.C', 'para.K.M', 'other'] } ], BROKEN_DIFFERENT_REGIONS_2: [{ target: ['para.A.C', 'para2.K2.M2'] }], BROKEN_DIFFERENT_REGIONS_3: [ { target: ['para2.K2.L2.L2A', 'other'] } ], BROKEN_DIFFERENT_REGIONS_4: [ { target: ['para2.K2.L2.L2A.L2C', 'para2.K2.M2'] } ], INITIAL: 'para' } }, other: { initial: 'X', states: { X: {} } }, para: { type: 'parallel', states: { A: { initial: 'B', states: { B: {}, C: {} } }, K: { initial: 'L', states: { L: {}, M: {} } }, P: { initial: 'Q', states: { Q: {}, R: {} } } } }, para2: { type: 'parallel', states: { A2: { initial: 'B2', states: { B2: {}, C2: {} } }, K2: { initial: 'L2', states: { L2: { type: 'parallel', states: { L2A: { initial: 'L2B', states: { L2B: {}, L2C: {} } }, L2K: { initial: 'L2L', states: { L2L: {}, L2M: {} } }, L2P: { initial: 'L2Q', states: { L2Q: {}, L2R: {} } } } }, M2: { type: 'parallel', states: { M2A: { initial: 'M2B', states: { M2B: {}, M2C: {} } }, M2K: { initial: 'M2L', states: { M2L: {}, M2M: {} } }, M2P: { initial: 'M2Q', states: { M2Q: {}, M2R: {} } } } } } }, P2: { initial: 'Q2', states: { Q2: {}, R2: {} } } } } } });
describe('transitions to parallel states', () => { const stateSimple = machine.initialState; const stateInitial = machine.transition(stateSimple, 'INITIAL'); const stateM = machine.transition(stateSimple, 'DEEP_M');
it('should enter initial states of parallel states', () => { expect(stateInitial.value).toEqual({ para: { A: 'B', K: 'L', P: 'Q' } }); });
it('should enter specific states in one region', () => { expect(stateM.value).toEqual({ para: { A: 'B', K: 'M', P: 'Q' } }); });
it('should enter specific states in all regions', () => { const stateCMR = machine.transition(stateSimple, 'DEEP_CMR'); expect(stateCMR.value).toEqual({ para: { A: 'C', K: 'M', P: 'R' } }); });
it('should enter specific states in some regions', () => { const stateMR = machine.transition(stateSimple, 'DEEP_MR'); expect(stateMR.value).toEqual({ para: { A: 'B', K: 'M', P: 'R' } }); });
it.skip('should reject two targets in the same region', () => { expect(() => machine.transition(stateSimple, 'BROKEN_SAME_REGION') ).toThrow(); });
it.skip('should reject targets inside and outside a region', () => { expect(() => machine.transition(stateSimple, 'BROKEN_DIFFERENT_REGIONS') ).toThrow(); });
it.skip('should reject two targets in different regions', () => { expect(() => machine.transition(stateSimple, 'BROKEN_DIFFERENT_REGIONS_2') ).toThrow(); });
it.skip('should reject two targets in different regions at different levels', () => { expect(() => machine.transition(stateSimple, 'BROKEN_DIFFERENT_REGIONS_3') ).toThrow(); });
it.skip('should reject two deep targets in different regions at top level', () => { expect(() => machine.transition(stateSimple, 'BROKEN_DIFFERENT_REGIONS_3') ).toThrow(); });
it.skip('should reject two deep targets in different regions at different levels', () => { expect(() => machine.transition(stateSimple, 'BROKEN_DIFFERENT_REGIONS_4') ).toThrow(); }); });});
Version Info