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

mutations_spec.js « store « ci_variable_list « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c7d07ead09b1ef816298d523e738a4fe03050075 (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
import * as types from '~/ci_variable_list/store/mutation_types';
import mutations from '~/ci_variable_list/store/mutations';
import state from '~/ci_variable_list/store/state';

describe('CI variable list mutations', () => {
  let stateCopy;

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

  describe('TOGGLE_VALUES', () => {
    it('should toggle state', () => {
      const valuesHidden = false;

      mutations[types.TOGGLE_VALUES](stateCopy, valuesHidden);

      expect(stateCopy.valuesHidden).toEqual(valuesHidden);
    });
  });

  describe('VARIABLE_BEING_EDITED', () => {
    it('should set the variable that is being edited', () => {
      mutations[types.VARIABLE_BEING_EDITED](stateCopy);

      expect(stateCopy.variableBeingEdited).toBe(true);
    });
  });

  describe('RESET_EDITING', () => {
    it('should reset variableBeingEdited to false', () => {
      mutations[types.RESET_EDITING](stateCopy);

      expect(stateCopy.variableBeingEdited).toBe(false);
    });
  });

  describe('CLEAR_MODAL', () => {
    it('should clear modal state', () => {
      const modalState = {
        variable_type: 'Variable',
        key: '',
        secret_value: '',
        protected_variable: false,
        masked: false,
        environment_scope: 'All (default)',
      };

      mutations[types.CLEAR_MODAL](stateCopy);

      expect(stateCopy.variable).toEqual(modalState);
    });
  });

  describe('RECEIVE_ENVIRONMENTS_SUCCESS', () => {
    it('should set environments', () => {
      const environments = ['env1', 'env2'];

      mutations[types.RECEIVE_ENVIRONMENTS_SUCCESS](stateCopy, environments);

      expect(stateCopy.environments).toEqual(['All (default)', 'env1', 'env2']);
    });
  });

  describe('SET_ENVIRONMENT_SCOPE', () => {
    const environment = 'production';

    it('should set environment scope on variable', () => {
      mutations[types.SET_ENVIRONMENT_SCOPE](stateCopy, environment);

      expect(stateCopy.variable.environment_scope).toBe('production');
    });
  });

  describe('ADD_WILD_CARD_SCOPE', () => {
    it('should add wild card scope to environments array and sort', () => {
      stateCopy.environments = ['dev', 'staging'];
      mutations[types.ADD_WILD_CARD_SCOPE](stateCopy, 'production');

      expect(stateCopy.environments).toEqual(['dev', 'production', 'staging']);
    });
  });

  describe('SET_VARIABLE_PROTECTED', () => {
    it('should set protected value to true', () => {
      mutations[types.SET_VARIABLE_PROTECTED](stateCopy);

      expect(stateCopy.variable.protected_variable).toBe(true);
    });
  });

  describe('UPDATE_VARIABLE_KEY', () => {
    it('should update variable key value', () => {
      const key = 'new_var';
      mutations[types.UPDATE_VARIABLE_KEY](stateCopy, key);

      expect(stateCopy.variable.key).toBe(key);
    });
  });

  describe('UPDATE_VARIABLE_VALUE', () => {
    it('should update variable value', () => {
      const value = 'variable_value';
      mutations[types.UPDATE_VARIABLE_VALUE](stateCopy, value);

      expect(stateCopy.variable.secret_value).toBe(value);
    });
  });

  describe('UPDATE_VARIABLE_TYPE', () => {
    it('should update variable type value', () => {
      const type = 'File';
      mutations[types.UPDATE_VARIABLE_TYPE](stateCopy, type);

      expect(stateCopy.variable.variable_type).toBe(type);
    });
  });

  describe('UPDATE_VARIABLE_PROTECTED', () => {
    it('should update variable protected value', () => {
      const protectedValue = true;
      mutations[types.UPDATE_VARIABLE_PROTECTED](stateCopy, protectedValue);

      expect(stateCopy.variable.protected_variable).toBe(protectedValue);
    });
  });

  describe('UPDATE_VARIABLE_MASKED', () => {
    it('should update variable masked value', () => {
      const masked = true;
      mutations[types.UPDATE_VARIABLE_MASKED](stateCopy, masked);

      expect(stateCopy.variable.masked).toBe(masked);
    });
  });
});