summaryrefslogtreecommitdiff
path: root/spec/javascripts/jobs/store/getters_spec.js
blob: 34e9707eadd0da53fb899f7ec961de143212c4d7 (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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
import * as getters from '~/jobs/store/getters';
import state from '~/jobs/store/state';

describe('Job Store Getters', () => {
  let localState;

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

  describe('headerActions', () => {
    describe('with new issue path', () => {
      it('returns an array with action to create a new issue', () => {
        localState.job.new_issue_path = 'issues/new';

        expect(getters.headerActions(localState)).toEqual([
          {
            label: 'New issue',
            path: localState.job.new_issue_path,
            cssClass:
              'js-new-issue btn btn-success btn-inverted d-none d-md-block d-lg-block d-xl-block',
            type: 'link',
          },
        ]);
      });
    });

    describe('without new issue path', () => {
      it('returns an empty array', () => {
        expect(getters.headerActions(localState)).toEqual([]);
      });
    });
  });

  describe('headerTime', () => {
    describe('when the job has started key', () => {
      it('returns started key', () => {
        const started = '2018-08-31T16:20:49.023Z';
        localState.job.started = started;

        expect(getters.headerTime(localState)).toEqual(started);
      });
    });

    describe('when the job does not have started key', () => {
      it('returns created_at key', () => {
        const created = '2018-08-31T16:20:49.023Z';
        localState.job.created_at = created;

        expect(getters.headerTime(localState)).toEqual(created);
      });
    });
  });

  describe('shouldRenderCalloutMessage', () => {
    describe('with status and callout message', () => {
      it('returns true', () => {
        localState.job.callout_message = 'Callout message';
        localState.job.status = { icon: 'passed' };

        expect(getters.shouldRenderCalloutMessage(localState)).toEqual(true);
      });
    });

    describe('without status & with callout message', () => {
      it('returns false', () => {
        localState.job.callout_message = 'Callout message';

        expect(getters.shouldRenderCalloutMessage(localState)).toEqual(false);
      });
    });

    describe('with status & without callout message', () => {
      it('returns false', () => {
        localState.job.status = { icon: 'passed' };

        expect(getters.shouldRenderCalloutMessage(localState)).toEqual(false);
      });
    });
  });

  describe('shouldRenderTriggeredLabel', () => {
    describe('when started equals null', () => {
      it('returns false', () => {
        localState.job.started = null;

        expect(getters.shouldRenderTriggeredLabel(localState)).toEqual(false);
      });
    });

    describe('when started equals string', () => {
      it('returns true', () => {
        localState.job.started = '2018-08-31T16:20:49.023Z';

        expect(getters.shouldRenderTriggeredLabel(localState)).toEqual(true);
      });
    });
  });

  describe('hasEnvironment', () => {
    describe('without `deployment_status`', () => {
      it('returns false', () => {
        expect(getters.hasEnvironment(localState)).toEqual(false);
      });
    });

    describe('with an empty object for `deployment_status`', () => {
      it('returns false', () => {
        localState.job.deployment_status = {};

        expect(getters.hasEnvironment(localState)).toEqual(false);
      });
    });

    describe('when `deployment_status` is defined and not empty', () => {
      it('returns true', () => {
        localState.job.deployment_status = {
          status: 'creating',
          environment: {
            last_deployment: {},
          },
        };

        expect(getters.hasEnvironment(localState)).toEqual(true);
      });
    });
  });

  describe('hasTrace', () => {
    describe('when has_trace is true', () => {
      it('returns true', () => {
        localState.job.has_trace = true;
        localState.job.status = {};

        expect(getters.hasTrace(localState)).toEqual(true);
      });
    });

    describe('when job is running', () => {
      it('returns true', () => {
        localState.job.has_trace = false;
        localState.job.status = { group: 'running' };

        expect(getters.hasTrace(localState)).toEqual(true);
      });
    });

    describe('when has_trace is false and job is not running', () => {
      it('returns false', () => {
        localState.job.has_trace = false;
        localState.job.status = { group: 'pending' };

        expect(getters.hasTrace(localState)).toEqual(false);
      });
    });
  });

  describe('emptyStateIllustration', () => {
    describe('with defined illustration', () => {
      it('returns the state illustration object', () => {
        localState.job.status = {
          illustration: {
            path: 'foo',
          },
        };

        expect(getters.emptyStateIllustration(localState)).toEqual({ path: 'foo' });
      });
    });

    describe('when illustration is not defined', () => {
      it('returns an empty object', () => {
        expect(getters.emptyStateIllustration(localState)).toEqual({});
      });
    });
  });

  describe('hasRunnersForProject', () => {
    describe('with available and offline runners', () => {
      it('returns true', () => {
        localState.job.runners = {
          available: true,
          online: false
        };

        expect(getters.hasRunnersForProject(localState)).toEqual(true);
      });
    });

    describe('with non available runners', () => {
      it('returns false', () => {
        localState.job.runners = {
          available: false,
          online: false
        };

        expect(getters.hasRunnersForProject(localState)).toEqual(false);
      });
    });

    describe('with online runners', () => {
      it('returns false', () => {
        localState.job.runners = {
          available: false,
          online: true
        };

        expect(getters.hasRunnersForProject(localState)).toEqual(false);
      });
    });
  });
});