aboutsummaryrefslogtreecommitdiff
path: root/test/console/app/reducer.test.ts
blob: eac20125e79bc97681b05216d63301773de6c636 (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
import reducer, { defaultState, State } from "../../../src/console/app/recuer";
import {
  hide,
  hideCommand,
  showCommand,
  showError,
  showFind,
  showInfo,
} from "../../../src/console/app/actions";

describe("app reducer", () => {
  describe("hide", () => {
    it("switches to none mode", () => {
      const initialState: State = {
        ...defaultState,
        mode: "info",
      };
      const nextState = reducer(initialState, hide());

      expect(nextState.mode).toHaveLength(0);
    });
  });

  describe("showCommand", () => {
    it("switches to command mode with a message", () => {
      const nextState = reducer(defaultState, showCommand("open "));

      expect(nextState.mode).toEqual("command");
      expect(nextState.consoleText).toEqual("open ");
    });
  });

  describe("showFind", () => {
    it("switches to find mode with a message", () => {
      const nextState = reducer(defaultState, showFind());

      expect(nextState.mode).toEqual("find");
    });
  });

  describe("showError", () => {
    it("switches to error message mode with a message", () => {
      const nextState = reducer(defaultState, showError("error occurs"));

      expect(nextState.mode).toEqual("error");
      expect(nextState.messageText).toEqual("error occurs");
    });
  });

  describe("showInfo", () => {
    it("switches to info message mode with a message", () => {
      const nextState = reducer(defaultState, showInfo("what's up"));

      expect(nextState.mode).toEqual("info");
      expect(nextState.messageText).toEqual("what's up");
    });
  });

  describe("hideCommand", () => {
    describe("when command mode", () => {
      it("switches to none mode", () => {
        const initialState: State = {
          ...defaultState,
          mode: "command",
        };
        const nextState = reducer(initialState, hideCommand());

        expect(nextState.mode).toHaveLength(0);
      });
    });

    describe("when info message mode", () => {
      it("does nothing", () => {
        const initialState: State = {
          ...defaultState,
          mode: "info",
        };
        const nextState = reducer(initialState, hideCommand());

        expect(nextState.mode).toEqual("info");
      });
    });
  });
});