summaryrefslogtreecommitdiff
path: root/spec/javascripts/pipelines/pipelines_table_spec.js
blob: ca2f9163313be4088cf7097b69d1818c40b6b95e (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
import Vue from 'vue';
import pipelinesTableComp from '~/pipelines/components/pipelines_table.vue';
import '~/lib/utils/datetime_utility';

describe('Pipelines Table', () => {
  const jsonFixtureName = 'pipelines/pipelines.json';

  let pipeline;
  let PipelinesTableComponent;

  preloadFixtures(jsonFixtureName);

  beforeEach(() => {
    PipelinesTableComponent = Vue.extend(pipelinesTableComp);
    const pipelines = getJSONFixture(jsonFixtureName).pipelines;
    pipeline = pipelines.find(p => p.id === 1);
  });

  describe('table', () => {
    let component;
    beforeEach(() => {
      component = new PipelinesTableComponent({
        propsData: {
          pipelines: [],
          autoDevopsHelpPath: 'foo',
          viewType: 'root',
        },
      }).$mount();
    });

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

    it('should render a table', () => {
      expect(component.$el.getAttribute('class')).toContain('ci-table');
    });

    it('should render table head with correct columns', () => {
      expect(component.$el.querySelector('.table-section.js-pipeline-status').textContent.trim()).toEqual('Status');
      expect(component.$el.querySelector('.table-section.js-pipeline-info').textContent.trim()).toEqual('Pipeline');
      expect(component.$el.querySelector('.table-section.js-pipeline-commit').textContent.trim()).toEqual('Commit');
      expect(component.$el.querySelector('.table-section.js-pipeline-stages').textContent.trim()).toEqual('Stages');
    });
  });

  describe('without data', () => {
    it('should render an empty table', () => {
      const component = new PipelinesTableComponent({
        propsData: {
          pipelines: [],
          autoDevopsHelpPath: 'foo',
          viewType: 'root',
        },
      }).$mount();
      expect(component.$el.querySelectorAll('.commit.gl-responsive-table-row').length).toEqual(0);
    });
  });

  describe('with data', () => {
    it('should render rows', () => {
      const component = new PipelinesTableComponent({
        propsData: {
          pipelines: [pipeline],
          autoDevopsHelpPath: 'foo',
          viewType: 'root',
        },
      }).$mount();

      expect(component.$el.querySelectorAll('.commit.gl-responsive-table-row').length).toEqual(1);
    });
  });
});