summaryrefslogtreecommitdiff
path: root/spec/javascripts/pipelines/graph/stage_column_component_spec.js
blob: dafb892da43f8c149bff3dabf9eb5bfb971f4c0f (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 stageColumnComponent from '~/pipelines/components/graph/stage_column_component.vue';
import mountComponent from 'spec/helpers/vue_mount_component_helper';

describe('stage column component', () => {
  let component;
  const StageColumnComponent = Vue.extend(stageColumnComponent);

  const mockJob = {
    id: 4250,
    name: 'test',
    status: {
      icon: 'status_success',
      text: 'passed',
      label: 'passed',
      group: 'success',
      details_path: '/root/ci-mock/builds/4250',
      action: {
        icon: 'retry',
        title: 'Retry',
        path: '/root/ci-mock/builds/4250/retry',
        method: 'post',
      },
    },
  };

  beforeEach(() => {
    const mockGroups = [];
    for (let i = 0; i < 3; i += 1) {
      const mockedJob = Object.assign({}, mockJob);
      mockedJob.id += i;
      mockGroups.push(mockedJob);
    }

    component = mountComponent(StageColumnComponent, {
      title: 'foo',
      groups: mockGroups,
      hasTriggeredBy: false,
    });
  });

  it('should render provided title', () => {
    expect(component.$el.querySelector('.stage-name').textContent.trim()).toEqual('foo');
  });

  it('should render the provided groups', () => {
    expect(component.$el.querySelectorAll('.builds-container > ul > li').length).toEqual(3);
  });

  describe('jobId', () => {
    it('escapes job name', () => {
      component = mountComponent(StageColumnComponent, {
        groups: [
          {
            id: 4259,
            name: '<img src=x onerror=alert(document.domain)>',
            status: {
              icon: 'icon_status_success',
              label: 'success',
              tooltip: '<img src=x onerror=alert(document.domain)>',
            },
          },
        ],
        title: 'test',
        hasTriggeredBy: false,
      });

      expect(component.$el.querySelector('.builds-container li').getAttribute('id')).toEqual(
        'ci-badge-&lt;img src=x onerror=alert(document.domain)&gt;',
      );
    });
  });
});