aboutsummaryrefslogtreecommitdiff
path: root/test/console/reducers/completion.test.ts
blob: 6c76369b005cdf8864fedc2936e9869bdc2b7325 (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
91
92
93
94
95
96
97
98
99
100
101
102
import reducer, { State } from "../../../src/console/reducers/completion";
import { expect } from "chai";
import {
  COMPLETION_COMPLETION_NEXT,
  COMPLETION_COMPLETION_PREV,
  COMPLETION_SET_COMPLETIONS,
  CompletionAction,
} from "../../../src/console/actions/completion";

describe("completion reducer", () => {
  it("return next state for CONSOLE_SET_COMPLETIONS", () => {
    const initialState = reducer(undefined, {} as any);
    let state: State = {
      ...initialState,
      select: 0,
      completions: [],
    };
    const action: CompletionAction = {
      type: COMPLETION_SET_COMPLETIONS,
      completions: [
        {
          name: "Apple",
          items: [{}, {}, {}],
        },
        {
          name: "Banana",
          items: [{}, {}, {}],
        },
      ],
      completionSource: "",
    };
    state = reducer(state, action);
    expect(state).to.have.property("completions", action.completions);
    expect(state).to.have.property("select", -1);
  });

  it("return next state for CONSOLE_COMPLETION_NEXT", () => {
    const initialState = reducer(undefined, {} as any);
    const action: CompletionAction = {
      type: COMPLETION_COMPLETION_NEXT,
    };
    let state = {
      ...initialState,
      select: -1,
      completions: [
        {
          name: "Apple",
          items: [{}, {}],
        },
        {
          name: "Banana",
          items: [{}],
        },
      ],
    };

    state = reducer(state, action);
    expect(state).to.have.property("select", 0);

    state = reducer(state, action);
    expect(state).to.have.property("select", 1);

    state = reducer(state, action);
    expect(state).to.have.property("select", 2);

    state = reducer(state, action);
    expect(state).to.have.property("select", -1);
  });

  it("return next state for CONSOLE_COMPLETION_PREV", () => {
    const initialState = reducer(undefined, {} as any);
    const action: CompletionAction = {
      type: COMPLETION_COMPLETION_PREV,
    };
    let state = {
      ...initialState,
      select: -1,
      completions: [
        {
          name: "Apple",
          items: [{}, {}],
        },
        {
          name: "Banana",
          items: [{}],
        },
      ],
    };

    state = reducer(state, action);
    expect(state).to.have.property("select", 2);

    state = reducer(state, action);
    expect(state).to.have.property("select", 1);

    state = reducer(state, action);
    expect(state).to.have.property("select", 0);

    state = reducer(state, action);
    expect(state).to.have.property("select", -1);
  });
});