summaryrefslogtreecommitdiff
path: root/spec/javascripts/pipelines/graph/graph_component_spec.js
blob: 024426acf05b66c41b121eced3d985b2cd7953d5 (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
import Vue from 'vue';
import graphComponent from '~/pipelines/components/graph/graph_component.vue';

describe('graph component', () => {
  preloadFixtures('static/graph.html.raw');

  let GraphComponent;

  beforeEach(() => {
    loadFixtures('static/graph.html.raw');
    GraphComponent = Vue.extend(graphComponent);
  });

  describe('while is loading', () => {
    it('should render a loading icon', () => {
      const component = new GraphComponent().$mount('#js-pipeline-graph-vue');
      expect(component.$el.querySelector('.loading-icon')).toBeDefined();
    });
  });

  describe('with a successfull response', () => {
    const graphJSON = {
      details: {
        stages: [{
          name: 'review',
          title: 'review: passed',
          groups: [{
            name: 'review_1',
            size: 1,
            status: {
              icon: 'icon_status_success',
              text: 'passed',
              label: 'passed',
              group: 'success',
              has_details: true,
              details_path: '/root/review-app/builds/4374',
              favicon: '/assets/ci_favicons/dev/favicon_status_success-308b4fc054cdd1b68d0865e6cfb7b02e92e3472f201507418f8eddb74ac11a59.ico',
              action: {
                icon: 'icon_action_retry',
                title: 'Retry',
                path: '/root/review-app/builds/4374/retry',
                method: 'post',
              },
            },
            jobs: [{
              id: 4374,
              name: 'review_1',
              build_path: '/root/review-app/builds/4374',
              retry_path: '/root/review-app/builds/4374/retry',
              playable: false,
              created_at: '2017-05-08T14:57:39.880Z',
              updated_at: '2017-05-08T14:57:52.639Z',
              status: {
                icon: 'icon_status_success',
                text: 'passed',
                label: 'passed',
                group: 'success',
                has_details: true,
                details_path: '/root/review-app/builds/4374',
                favicon: '/assets/ci_favicons/dev/favicon_status_success-308b4fc054cdd1b68d0865e6cfb7b02e92e3472f201507418f8eddb74ac11a59.ico',
                action: {
                  icon: 'icon_action_retry',
                  title: 'Retry',
                  path: '/root/review-app/builds/4374/retry',
                  method: 'post',
                },
              },
            }],
          },
          {
            name: 'test_1',
            title: 'test_1: passed',
            status: {
              icon: 'icon_status_success',
              text: 'passed',
              label: 'passed',
              details_path: '/root/ci-mock/pipelines/123#test',
            },
            path: '/root/ci-mock/pipelines/123#test',
            groups: [{
              name: 'test',
              size: 1,
              jobs: [{
                id: 4153,
                name: 'test',
                status: {
                  icon: 'icon_status_success',
                  text: 'passed',
                  label: 'passed',
                  details_path: '/root/ci-mock/builds/4153',
                  action: {
                    icon: 'icon_action_retry',
                    title: 'Retry',
                    path: '/root/ci-mock/builds/4153/retry',
                    method: 'post',
                  },
                },
              }],
            }, {
              name: 'test',
              size: 1,
              jobs: [{
                id: 4153,
                name: 'test',
                status: {
                  icon: 'icon_status_success',
                  text: 'passed',
                  label: 'passed',
                  details_path: '/root/ci-mock/builds/4153',
                  action: {
                    icon: 'icon_action_retry',
                    title: 'Retry',
                    path: '/root/ci-mock/builds/4153/retry',
                    method: 'post',
                  },
                },
              }],
            }],
          }],
        }],
      },
    };

    const interceptor = (request, next) => {
      next(request.respondWith(JSON.stringify(graphJSON), {
        status: 200,
      }));
    };

    beforeEach(() => {
      Vue.http.interceptors.push(interceptor);
    });

    afterEach(() => {
      Vue.http.interceptors = _.without(Vue.http.interceptors, interceptor);
    });

    it('should render the graph', (done) => {
      const component = new GraphComponent().$mount('#js-pipeline-graph-vue');

      setTimeout(() => {
        expect(component.$el.classList.contains('js-pipeline-graph')).toEqual(true);

        expect(
          component.$el.querySelector('.stage-column:first-child').classList.contains('no-margin'),
        ).toEqual(true);

        expect(
          component.$el.querySelector('.stage-column:nth-child(2)').classList.contains('left-margin'),
        ).toEqual(true);

        expect(
          component.$el.querySelector('.stage-column:nth-child(2) .build:nth-child(1)').classList.contains('left-connector'),
        ).toEqual(true);

        expect(component.$el.querySelector('loading-icon')).toBe(null);

        expect(component.$el.querySelector('.stage-column-list')).toBeDefined();
        done();
      }, 0);
    });
  });
});