summaryrefslogtreecommitdiff
path: root/spec/javascripts/jobs/components/sidebar_spec.js
blob: 26d9effcac5b9f8e6a952ae661519680cd8f3933 (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
import Vue from 'vue';
import sidebarDetailsBlock from '~/jobs/components/sidebar.vue';
import createStore from '~/jobs/store';
import job, { stages, jobsInStage } from '../mock_data';
import { mountComponentWithStore } from '../../helpers/vue_mount_component_helper';
import { trimText } from '../../helpers/text_helper';

describe('Sidebar details block', () => {
  const SidebarComponent = Vue.extend(sidebarDetailsBlock);
  let vm;
  let store;

  beforeEach(() => {
    store = createStore();
  });

  afterEach(() => {
    vm.$destroy();
  });

  describe('when there is no retry path retry', () => {
    it('should not render a retry button', () => {
      const copy = Object.assign({}, job);
      delete copy.retry_path;

      store.dispatch('receiveJobSuccess', copy);
      vm = mountComponentWithStore(SidebarComponent, {
        store,
      });

      expect(vm.$el.querySelector('.js-retry-button')).toBeNull();
    });
  });

  describe('without terminal path', () => {
    it('does not render terminal link', () => {
      store.dispatch('receiveJobSuccess', job);
      vm = mountComponentWithStore(SidebarComponent, { store });

      expect(vm.$el.querySelector('.js-terminal-link')).toBeNull();
    });
  });

  describe('with terminal path', () => {
    it('renders terminal link', () => {
      store.dispatch(
        'receiveJobSuccess',
        Object.assign({}, job, { terminal_path: 'job/43123/terminal' }),
      );
      vm = mountComponentWithStore(SidebarComponent, {
        store,
      });

      expect(vm.$el.querySelector('.js-terminal-link')).not.toBeNull();
    });
  });

  beforeEach(() => {
    store.dispatch('receiveJobSuccess', job);
    vm = mountComponentWithStore(SidebarComponent, { store });
  });

  describe('actions', () => {
    it('should render link to new issue', () => {
      expect(vm.$el.querySelector('.js-new-issue').getAttribute('href')).toEqual(
        job.new_issue_path,
      );

      expect(vm.$el.querySelector('.js-new-issue').textContent.trim()).toEqual('New issue');
    });

    it('should render link to retry job', () => {
      expect(vm.$el.querySelector('.js-retry-button').getAttribute('href')).toEqual(job.retry_path);
    });

    it('should render link to cancel job', () => {
      expect(vm.$el.querySelector('.js-cancel-job').getAttribute('href')).toEqual(job.cancel_path);
    });
  });

  describe('information', () => {
    it('should render job duration', () => {
      expect(trimText(vm.$el.querySelector('.js-job-duration').textContent)).toEqual(
        'Duration: 6 seconds',
      );
    });

    it('should render erased date', () => {
      expect(trimText(vm.$el.querySelector('.js-job-erased').textContent)).toEqual(
        'Erased: 3 weeks ago',
      );
    });

    it('should render finished date', () => {
      expect(trimText(vm.$el.querySelector('.js-job-finished').textContent)).toEqual(
        'Finished: 3 weeks ago',
      );
    });

    it('should render queued date', () => {
      expect(trimText(vm.$el.querySelector('.js-job-queued').textContent)).toEqual(
        'Queued: 9 seconds',
      );
    });

    it('should render runner ID', () => {
      expect(trimText(vm.$el.querySelector('.js-job-runner').textContent)).toEqual(
        'Runner: local ci runner (#1)',
      );
    });

    it('should render timeout information', () => {
      expect(trimText(vm.$el.querySelector('.js-job-timeout').textContent)).toEqual(
        'Timeout: 1m 40s (from runner)',
      );
    });

    it('should render coverage', () => {
      expect(trimText(vm.$el.querySelector('.js-job-coverage').textContent)).toEqual(
        'Coverage: 20%',
      );
    });

    it('should render tags', () => {
      expect(trimText(vm.$el.querySelector('.js-job-tags').textContent)).toEqual('Tags: tag');
    });
  });

  describe('stages dropdown', () => {
    beforeEach(() => {
      store.dispatch('receiveJobSuccess', job);
    });

    describe('while fetching stages', () => {
      it('it does not render dropdown', () => {
        store.dispatch('requestStages');
        vm = mountComponentWithStore(SidebarComponent, { store });

        expect(vm.$el.querySelector('.js-selected-stage')).toBeNull();
      });
    });

    describe('with stages', () => {
      beforeEach(() => {
        store.dispatch('receiveStagesSuccess', stages);
        vm = mountComponentWithStore(SidebarComponent, { store });
      });

      it('renders value provided as selectedStage as selected', () => {
        expect(vm.$el.querySelector('.js-selected-stage').textContent.trim()).toEqual(
          vm.selectedStage,
        );
      });
    });

    describe('without jobs for stages', () => {
      beforeEach(() => {
        store.dispatch('receiveJobSuccess', job);
        store.dispatch('receiveStagesSuccess', stages);
        vm = mountComponentWithStore(SidebarComponent, { store });
      });

      it('does not render job container', () => {
        expect(vm.$el.querySelector('.js-jobs-container')).toBeNull();
      });
    });

    describe('with jobs for stages', () => {
      beforeEach(() => {
        store.dispatch('receiveJobSuccess', job);
        store.dispatch('receiveStagesSuccess', stages);
        store.dispatch('receiveJobsForStageSuccess', jobsInStage.latest_statuses);
        vm = mountComponentWithStore(SidebarComponent, { store });
      });

      it('renders list of jobs', () => {
        expect(vm.$el.querySelector('.js-jobs-container')).not.toBeNull();
      });
    });
  });
});