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

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

const mockFileTemplates = [['MIT'], ['CC']];
const mockTemplateType = 'test';

describe('IDE file templates mutations', () => {
  let state;

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

  describe(`${types.REQUEST_TEMPLATE_TYPES}`, () => {
    it('sets loading to true', () => {
      state.isLoading = false;

      mutations[types.REQUEST_TEMPLATE_TYPES](state);

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

    it('sets templates to an empty array', () => {
      state.templates = mockFileTemplates;

      mutations[types.REQUEST_TEMPLATE_TYPES](state);

      expect(state.templates).toEqual([]);
    });
  });

  describe(`${types.RECEIVE_TEMPLATE_TYPES_ERROR}`, () => {
    it('sets isLoading', () => {
      state.isLoading = true;

      mutations[types.RECEIVE_TEMPLATE_TYPES_ERROR](state);

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

  describe(`${types.RECEIVE_TEMPLATE_TYPES_SUCCESS}`, () => {
    it('sets isLoading to false', () => {
      state.isLoading = true;

      mutations[types.RECEIVE_TEMPLATE_TYPES_SUCCESS](state, mockFileTemplates);

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

    it('sets templates to payload', () => {
      state.templates = ['test'];

      mutations[types.RECEIVE_TEMPLATE_TYPES_SUCCESS](state, mockFileTemplates);

      expect(state.templates).toEqual(mockFileTemplates);
    });
  });

  describe(`${types.SET_SELECTED_TEMPLATE_TYPE}`, () => {
    it('sets templates type to selected type', () => {
      state.selectedTemplateType = '';

      mutations[types.SET_SELECTED_TEMPLATE_TYPE](state, mockTemplateType);

      expect(state.selectedTemplateType).toBe(mockTemplateType);
    });

    it('sets templates to empty array', () => {
      state.templates = mockFileTemplates;

      mutations[types.SET_SELECTED_TEMPLATE_TYPE](state, mockTemplateType);

      expect(state.templates).toEqual([]);
    });
  });

  describe(`${types.SET_UPDATE_SUCCESS}`, () => {
    it('sets updateSuccess', () => {
      state.updateSuccess = false;

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

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