Welcome to mirror list, hosted at ThFree Co, Russian Federation.

mutations_spec.js « terminal « modules « stores « ide « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e9933bdd7bebb7a17a88cd3470ab122a830d74a5 (plain)
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import {
  CHECK_CONFIG,
  CHECK_RUNNERS,
  RUNNING,
  STOPPING,
} from '~/ide/stores/modules/terminal/constants';
import createState from '~/ide/stores/modules/terminal/state';
import * as types from '~/ide/stores/modules/terminal/mutation_types';
import mutations from '~/ide/stores/modules/terminal/mutations';

describe('IDE store terminal mutations', () => {
  let state;

  beforeEach(() => {
    state = createState();
  });

  describe(types.SET_VISIBLE, () => {
    it('sets isVisible', () => {
      state.isVisible = false;

      mutations[types.SET_VISIBLE](state, true);

      expect(state.isVisible).toBe(true);
    });
  });

  describe(types.HIDE_SPLASH, () => {
    it('sets isShowSplash', () => {
      state.isShowSplash = true;

      mutations[types.HIDE_SPLASH](state);

      expect(state.isShowSplash).toBe(false);
    });
  });

  describe(types.SET_PATHS, () => {
    it('sets paths', () => {
      const paths = {
        test: 'foo',
      };

      mutations[types.SET_PATHS](state, paths);

      expect(state.paths).toBe(paths);
    });
  });

  describe(types.REQUEST_CHECK, () => {
    it('sets isLoading for check', () => {
      const type = CHECK_CONFIG;

      state.checks[type] = {};
      mutations[types.REQUEST_CHECK](state, type);

      expect(state.checks[type]).toEqual({
        isLoading: true,
      });
    });
  });

  describe(types.RECEIVE_CHECK_ERROR, () => {
    it('sets error for check', () => {
      const type = CHECK_RUNNERS;
      const message = 'lorem ipsum';

      state.checks[type] = {};
      mutations[types.RECEIVE_CHECK_ERROR](state, { type, message });

      expect(state.checks[type]).toEqual({
        isLoading: false,
        isValid: false,
        message,
      });
    });
  });

  describe(types.RECEIVE_CHECK_SUCCESS, () => {
    it('sets success for check', () => {
      const type = CHECK_CONFIG;

      state.checks[type] = {};
      mutations[types.RECEIVE_CHECK_SUCCESS](state, type);

      expect(state.checks[type]).toEqual({
        isLoading: false,
        isValid: true,
        message: null,
      });
    });
  });

  describe(types.SET_SESSION, () => {
    it('sets session', () => {
      const session = {
        terminalPath: 'terminal/foo',
        status: RUNNING,
      };

      mutations[types.SET_SESSION](state, session);

      expect(state.session).toBe(session);
    });
  });

  describe(types.SET_SESSION_STATUS, () => {
    it('sets session if a session does not exists', () => {
      const status = RUNNING;

      mutations[types.SET_SESSION_STATUS](state, status);

      expect(state.session).toEqual({
        status,
      });
    });

    it('sets session status', () => {
      state.session = {
        terminalPath: 'terminal/foo',
        status: RUNNING,
      };

      mutations[types.SET_SESSION_STATUS](state, STOPPING);

      expect(state.session).toEqual({
        terminalPath: 'terminal/foo',
        status: STOPPING,
      });
    });
  });

  describe(types.SET_SESSION_STATUS_INTERVAL, () => {
    it('sets sessionStatusInterval', () => {
      const val = 7;

      mutations[types.SET_SESSION_STATUS_INTERVAL](state, val);

      expect(state.sessionStatusInterval).toEqual(val);
    });
  });
});