All files / xstate/test/examples 6.9.test.ts

100% Statements 6/6
100% Branches 0/0
100% Functions 1/1
100% Lines 6/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 1091x 1x   1x 1x                                                                                               1x                                                                                                           1x    
import { Machine } from '../../src/index';
import { testAll } from '../utils';
 
describe('Example 6.9', () => {
  const machine = Machine({
    initial: 'A',
    states: {
      A: {
        on: {
          6: 'H'
        },
        initial: 'B',
        states: {
          B: {
            initial: 'E',
            on: {
              5: 'C'
            },
            states: {
              D: {},
              E: {
                on: { 3: 'D' }
              }
            }
          },
          C: {
            initial: 'G',
            on: {
              4: 'B.E'
            },
            states: {
              F: {},
              G: {
                on: {
                  2: 'F'
                }
              }
            }
          },
          hist: { history: true },
          deepHist: { history: 'deep' }
        }
      },
      H: {
        on: {
          1: 'A.hist',
          7: 'A.deepHist' // 6.10
        }
      }
    }
  });
 
  const expected = {
    A: {
      3: 'A.B.D',
      5: 'A.C.G',
      6: 'H',
      FAKE: undefined
    },
    'A.B': {
      3: 'A.B.D',
      5: 'A.C.G',
      6: 'H',
      FAKE: undefined,
 
      // history
      '5, 6, 1': 'A.C.G',
      '3, 6, 1': 'A.B.E' // not A.B.D because not deep history
      // '3, 6, 7': 'A.B.D'
    },
    'A.C': {
      2: 'A.C.F',
      4: 'A.B.E',
      6: 'H',
      FAKE: undefined,
      '6, 1': 'A.C.G',
      '4, 6, 1': 'A.B.E'
    },
    'A.B.D': {
      5: 'A.C.G',
      6: 'H',
      FAKE: undefined
    },
    'A.B.E': {
      3: 'A.B.D',
      5: 'A.C.G',
      6: 'H',
      FAKE: undefined
    },
    'A.C.F': {
      4: 'A.B.E',
      6: 'H',
      FAKE: undefined
    },
    'A.C.G': {
      2: 'A.C.F',
      4: 'A.B.E',
      6: 'H',
      FAKE: undefined
    },
    H: {
      1: 'A.B.E',
      FAKE: undefined
    }
  };
 
  testAll(machine, expected);
});