summaryrefslogtreecommitdiff
path: root/spec/javascripts/commit/pipelines/pipelines_spec.js
blob: ebfd60198b28e4d28345af3c808f7caaf1780835 (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
import Vue from 'vue';
import PipelinesTable from '~/commit/pipelines/pipelines_table';

describe('Pipelines table in Commits and Merge requests', () => {
  const jsonFixtureName = 'pipelines/pipelines.json';
  let pipeline;

  preloadFixtures('static/pipelines_table.html.raw');
  preloadFixtures(jsonFixtureName);

  beforeEach(() => {
    loadFixtures('static/pipelines_table.html.raw');
    const pipelines = getJSONFixture(jsonFixtureName).pipelines;
    pipeline = pipelines.find(p => p.id === 1);
  });

  describe('successful request', () => {
    describe('without pipelines', () => {
      const pipelinesEmptyResponse = (request, next) => {
        next(request.respondWith(JSON.stringify([]), {
          status: 200,
        }));
      };

      beforeEach(function () {
        Vue.http.interceptors.push(pipelinesEmptyResponse);

        this.component = new PipelinesTable({
          el: document.querySelector('#commit-pipeline-table-view'),
        });
      });

      afterEach(function () {
        Vue.http.interceptors = _.without(
          Vue.http.interceptors, pipelinesEmptyResponse,
        );
        this.component.$destroy();
      });

      it('should render the empty state', function (done) {
        setTimeout(() => {
          expect(this.component.$el.querySelector('.empty-state')).toBeDefined();
          expect(this.component.$el.querySelector('.realtime-loading')).toBe(null);
          expect(this.component.$el.querySelector('.js-pipelines-error-state')).toBe(null);
          done();
        }, 1);
      });
    });

    describe('with pipelines', () => {
      const pipelinesResponse = (request, next) => {
        next(request.respondWith(JSON.stringify([pipeline]), {
          status: 200,
        }));
      };

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

        this.component = new PipelinesTable({
          el: document.querySelector('#commit-pipeline-table-view'),
        });
      });

      afterEach(() => {
        Vue.http.interceptors = _.without(
          Vue.http.interceptors, pipelinesResponse,
        );
        this.component.$destroy();
      });

      it('should render a table with the received pipelines', (done) => {
        setTimeout(() => {
          expect(this.component.$el.querySelectorAll('.ci-table .commit').length).toEqual(1);
          expect(this.component.$el.querySelector('.realtime-loading')).toBe(null);
          expect(this.component.$el.querySelector('.empty-state')).toBe(null);
          expect(this.component.$el.querySelector('.js-pipelines-error-state')).toBe(null);
          done();
        }, 0);
      });
    });
  });

  describe('unsuccessfull request', () => {
    const pipelinesErrorResponse = (request, next) => {
      next(request.respondWith(JSON.stringify([]), {
        status: 500,
      }));
    };

    beforeEach(function () {
      Vue.http.interceptors.push(pipelinesErrorResponse);

      this.component = new PipelinesTable({
        el: document.querySelector('#commit-pipeline-table-view'),
      });
    });

    afterEach(function () {
      Vue.http.interceptors = _.without(
        Vue.http.interceptors, pipelinesErrorResponse,
      );
      this.component.$destroy();
    });

    it('should render error state', function (done) {
      setTimeout(() => {
        expect(this.component.$el.querySelector('.js-pipelines-error-state')).toBeDefined();
        expect(this.component.$el.querySelector('.realtime-loading')).toBe(null);
        expect(this.component.$el.querySelector('.js-empty-state')).toBe(null);
        expect(this.component.$el.querySelector('.ci-table')).toBe(null);
        done();
      }, 0);
    });
  });
});