aboutsummaryrefslogtreecommitdiff
path: root/test/reducers/completion.test.js
blob: 79163bff6a9fa5469d0d2e60e2bddb44af3985d7 (plain) (blame)
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
import { expect } from "chai";
import actions from '../../src/actions';
import completionReducer from '../../src/reducers/completion';

describe("completion reducer", () => {
  it ('return the initial state', () => {
    let state = completionReducer(undefined, {});
    expect(state).to.have.property('groupSelection', -1);
    expect(state).to.have.property('itemSelection', -1);
    expect(state).to.have.deep.property('groups', []);
  });

  it ('return next state for COMPLETION_SET_ITEMS', () => {
    let state = {
      groupSelection: 0,
      itemSelection: 0,
      groups: [],
    }
    let action = {
      type: actions.COMPLETION_SET_ITEMS,
      groups: [{
        name: 'Apple',
        items: [1, 2, 3]
      }, {
        name: 'Banana',
        items: [4, 5, 6]
      }]
    }
    state = completionReducer(state, action);
    expect(state).to.have.property('groups', action.groups);
    expect(state).to.have.property('groupSelection', -1);
    expect(state).to.have.property('itemSelection', -1);
  });

  it ('return next state for COMPLETION_SELECT_NEXT', () => {
    let action = { type: actions.COMPLETION_SELECT_NEXT };
    let state = {
      groupSelection: -1,
      itemSelection: -1,
      groups: [{
        name: 'Apple',
        items: [1, 2]
      }, {
        name: 'Banana',
        items: [3]
      }]
    };

    state = completionReducer(state, action);
    expect(state).to.have.property('groupSelection', 0);
    expect(state).to.have.property('itemSelection', 0);

    state = completionReducer(state, action);
    expect(state).to.have.property('groupSelection', 0);
    expect(state).to.have.property('itemSelection', 1);

    state = completionReducer(state, action);
    state = completionReducer(state, action);
    expect(state).to.have.property('groupSelection', -1);
    expect(state).to.have.property('itemSelection', -1);
  });

  it ('return next state for COMPLETION_SELECT_PREV', () => {
    let action = { type: actions.COMPLETION_SELECT_PREV };
    let state = {
      groupSelection: -1,
      itemSelection: -1,
      groups: [{
        name: 'Apple',
        items: [1, 2]
      }, {
        name: 'Banana',
        items: [3]
      }]
    };

    state = completionReducer(state, action);
    expect(state).to.have.property('groupSelection', 1);
    expect(state).to.have.property('itemSelection', 0);

    state = completionReducer(state, action);
    expect(state).to.have.property('groupSelection', 0);
    expect(state).to.have.property('itemSelection', 1);

    state = completionReducer(state, action);
    state = completionReducer(state, action);
    expect(state).to.have.property('groupSelection', -1);
    expect(state).to.have.property('itemSelection', -1);
  });
});