pipelines_spec.js 3.0 KB
Newer Older
1 2 3
import Vue from 'vue';
import PipelinesTable from '~/commit/pipelines/pipelines_table';
import pipeline from './mock_data';
4 5

describe('Pipelines table in Commits and Merge requests', () => {
6
  preloadFixtures('static/pipelines_table.html.raw');
7 8

  beforeEach(() => {
9
    loadFixtures('static/pipelines_table.html.raw');
10 11
  });

12
  describe('successful request', () => {
13 14 15 16 17 18 19
    describe('without pipelines', () => {
      const pipelinesEmptyResponse = (request, next) => {
        next(request.respondWith(JSON.stringify([]), {
          status: 200,
        }));
      };

20
      beforeEach(function () {
21
        Vue.http.interceptors.push(pipelinesEmptyResponse);
22 23 24 25

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

28
      afterEach(function () {
29 30 31
        Vue.http.interceptors = _.without(
          Vue.http.interceptors, pipelinesEmptyResponse,
        );
32
        this.component.$destroy();
33 34
      });

35
      it('should render the empty state', function (done) {
36
        setTimeout(() => {
37 38
          expect(this.component.$el.querySelector('.empty-state')).toBeDefined();
          expect(this.component.$el.querySelector('.realtime-loading')).toBe(null);
39 40 41 42 43 44 45 46 47 48 49 50 51 52
          done();
        }, 1);
      });
    });

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

      beforeEach(() => {
        Vue.http.interceptors.push(pipelinesResponse);
53 54 55 56

        this.component = new PipelinesTable({
          el: document.querySelector('#commit-pipeline-table-view'),
        });
57 58 59 60 61 62
      });

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

      it('should render a table with the received pipelines', (done) => {
        setTimeout(() => {
68 69
          expect(this.component.$el.querySelectorAll('table > tbody > tr').length).toEqual(1);
          expect(this.component.$el.querySelector('.realtime-loading')).toBe(null);
70 71 72 73 74 75 76 77 78 79 80 81 82
          done();
        }, 0);
      });
    });
  });

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

83
    beforeEach(function () {
84
      Vue.http.interceptors.push(pipelinesErrorResponse);
85 86 87 88

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

91
    afterEach(function () {
92 93 94
      Vue.http.interceptors = _.without(
        Vue.http.interceptors, pipelinesErrorResponse,
      );
95
      this.component.$destroy();
96 97
    });

98
    it('should render empty state', function (done) {
99
      setTimeout(() => {
100 101
        expect(this.component.$el.querySelector('.js-pipelines-error-state')).toBeDefined();
        expect(this.component.$el.querySelector('.realtime-loading')).toBe(null);
102 103 104 105 106
        done();
      }, 0);
    });
  });
});