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

mutations_spec.js « pipelines « modules « stores « ide « javascripts « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6285c01d4839aecbf9b3bc03f65d98acceed678f (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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
import mutations from '~/ide/stores/modules/pipelines/mutations';
import state from '~/ide/stores/modules/pipelines/state';
import * as types from '~/ide/stores/modules/pipelines/mutation_types';
import { fullPipelinesResponse, stages, jobs } from '../../../mock_data';

describe('IDE pipelines mutations', () => {
  let mockedState;

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

  describe(types.REQUEST_LATEST_PIPELINE, () => {
    it('sets loading to true', () => {
      mutations[types.REQUEST_LATEST_PIPELINE](mockedState);

      expect(mockedState.isLoadingPipeline).toBe(true);
    });
  });

  describe(types.RECEIVE_LASTEST_PIPELINE_ERROR, () => {
    it('sets loading to false', () => {
      mutations[types.RECEIVE_LASTEST_PIPELINE_ERROR](mockedState);

      expect(mockedState.isLoadingPipeline).toBe(false);
    });
  });

  describe(types.RECEIVE_LASTEST_PIPELINE_SUCCESS, () => {
    it('sets loading to false on success', () => {
      mutations[types.RECEIVE_LASTEST_PIPELINE_SUCCESS](
        mockedState,
        fullPipelinesResponse.data.pipelines[0],
      );

      expect(mockedState.isLoadingPipeline).toBe(false);
    });

    it('sets latestPipeline', () => {
      mutations[types.RECEIVE_LASTEST_PIPELINE_SUCCESS](
        mockedState,
        fullPipelinesResponse.data.pipelines[0],
      );

      expect(mockedState.latestPipeline).toEqual({
        id: '51',
        path: 'test',
        commit: { id: '123' },
        details: { status: jasmine.any(Object) },
        yamlError: undefined,
      });
    });

    it('does not set latest pipeline if pipeline is null', () => {
      mutations[types.RECEIVE_LASTEST_PIPELINE_SUCCESS](mockedState, null);

      expect(mockedState.latestPipeline).toEqual(false);
    });

    it('sets stages', () => {
      mutations[types.RECEIVE_LASTEST_PIPELINE_SUCCESS](
        mockedState,
        fullPipelinesResponse.data.pipelines[0],
      );

      expect(mockedState.stages.length).toBe(2);
      expect(mockedState.stages).toEqual([
        {
          id: 0,
          dropdownPath: stages[0].dropdown_path,
          name: stages[0].name,
          status: stages[0].status,
          isCollapsed: false,
          isLoading: false,
          jobs: [],
        },
        {
          id: 1,
          dropdownPath: stages[1].dropdown_path,
          name: stages[1].name,
          status: stages[1].status,
          isCollapsed: false,
          isLoading: false,
          jobs: [],
        },
      ]);
    });
  });

  describe(types.REQUEST_JOBS, () => {
    beforeEach(() => {
      mockedState.stages = stages.map((stage, i) => ({
        ...stage,
        id: i,
      }));
    });

    it('sets isLoading on stage', () => {
      mutations[types.REQUEST_JOBS](mockedState, mockedState.stages[0].id);

      expect(mockedState.stages[0].isLoading).toBe(true);
    });
  });

  describe(types.RECEIVE_JOBS_ERROR, () => {
    beforeEach(() => {
      mockedState.stages = stages.map((stage, i) => ({
        ...stage,
        id: i,
      }));
    });

    it('sets isLoading on stage after error', () => {
      mutations[types.RECEIVE_JOBS_ERROR](mockedState, mockedState.stages[0].id);

      expect(mockedState.stages[0].isLoading).toBe(false);
    });
  });

  describe(types.RECEIVE_JOBS_SUCCESS, () => {
    let data;

    beforeEach(() => {
      mockedState.stages = stages.map((stage, i) => ({
        ...stage,
        id: i,
      }));

      data = {
        latest_statuses: [...jobs],
      };
    });

    it('updates loading', () => {
      mutations[types.RECEIVE_JOBS_SUCCESS](mockedState, { id: mockedState.stages[0].id, data });

      expect(mockedState.stages[0].isLoading).toBe(false);
    });

    it('sets jobs on stage', () => {
      mutations[types.RECEIVE_JOBS_SUCCESS](mockedState, { id: mockedState.stages[0].id, data });

      expect(mockedState.stages[0].jobs.length).toBe(jobs.length);
      expect(mockedState.stages[0].jobs).toEqual(
        jobs.map(job => ({
          id: job.id,
          name: job.name,
          status: job.status,
          path: job.build_path,
        })),
      );
    });
  });

  describe(types.TOGGLE_STAGE_COLLAPSE, () => {
    beforeEach(() => {
      mockedState.stages = stages.map((stage, i) => ({
        ...stage,
        id: i,
        isCollapsed: false,
      }));
    });

    it('toggles collapsed state', () => {
      mutations[types.TOGGLE_STAGE_COLLAPSE](mockedState, mockedState.stages[0].id);

      expect(mockedState.stages[0].isCollapsed).toBe(true);

      mutations[types.TOGGLE_STAGE_COLLAPSE](mockedState, mockedState.stages[0].id);

      expect(mockedState.stages[0].isCollapsed).toBe(false);
    });
  });
});