summaryrefslogtreecommitdiff
path: root/spec/javascripts/jobs/components/stages_dropdown_spec.js
blob: eccb4e13d67240d663384d62c817eedda0bb832f (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
164
165
166
167
import Vue from 'vue';
import component from '~/jobs/components/stages_dropdown.vue';
import { trimText } from 'spec/helpers/vue_component_helper';
import mountComponent from '../../helpers/vue_mount_component_helper';

describe('Stages Dropdown', () => {
  const Component = Vue.extend(component);
  let vm;

  const mockPipelineData = {
    id: 28029444,
    details: {
      status: {
        details_path: '/gitlab-org/gitlab-ce/pipelines/28029444',
        group: 'success',
        has_details: true,
        icon: 'status_success',
        label: 'passed',
        text: 'passed',
        tooltip: 'passed',
      },
    },
    path: 'pipeline/28029444',
    flags: {
      merge_request_pipeline: true,
      detached_merge_request_pipeline: false,
    },
    merge_request: {
      iid: 1234,
      path: '/root/detached-merge-request-pipelines/merge_requests/1',
      title: 'Update README.md',
      source_branch: 'feature-1234',
      source_branch_path: '/root/detached-merge-request-pipelines/branches/feature-1234',
      target_branch: 'master',
      target_branch_path: '/root/detached-merge-request-pipelines/branches/master',
    },
    ref: {
      name: 'test-branch',
    },
  };

  describe('without a merge request pipeline', () => {
    let pipeline;

    beforeEach(() => {
      pipeline = JSON.parse(JSON.stringify(mockPipelineData));
      delete pipeline.merge_request;
      delete pipeline.flags.merge_request_pipeline;
      delete pipeline.flags.detached_merge_request_pipeline;

      vm = mountComponent(Component, {
        pipeline,
        stages: [{ name: 'build' }, { name: 'test' }],
        selectedStage: 'deploy',
      });
    });

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

    it('renders pipeline status', () => {
      expect(vm.$el.querySelector('.js-ci-status-icon-success')).not.toBeNull();
    });

    it('renders pipeline link', () => {
      expect(vm.$el.querySelector('.js-pipeline-path').getAttribute('href')).toEqual(
        'pipeline/28029444',
      );
    });

    it('renders dropdown with stages', () => {
      expect(vm.$el.querySelector('.dropdown .js-stage-item').textContent).toContain('build');
    });

    it('rendes selected stage', () => {
      expect(vm.$el.querySelector('.dropdown .js-selected-stage').textContent).toContain('deploy');
    });

    it(`renders the pipeline info text like "Pipeline #123 for source_branch"`, () => {
      const expected = `Pipeline #${pipeline.id} for ${pipeline.ref.name}`;
      const actual = trimText(vm.$el.querySelector('.js-pipeline-info').innerText);

      expect(actual).toBe(expected);
    });
  });

  describe('with an "attached" merge request pipeline', () => {
    let pipeline;

    beforeEach(() => {
      pipeline = JSON.parse(JSON.stringify(mockPipelineData));
      pipeline.flags.merge_request_pipeline = true;
      pipeline.flags.detached_merge_request_pipeline = false;

      vm = mountComponent(Component, {
        pipeline,
        stages: [],
        selectedStage: 'deploy',
      });
    });

    it(`renders the pipeline info text like "Pipeline #123 for !456 with source_branch into target_branch"`, () => {
      const expected = `Pipeline #${pipeline.id} for !${pipeline.merge_request.iid} with ${
        pipeline.merge_request.source_branch
      } into ${pipeline.merge_request.target_branch}`;
      const actual = trimText(vm.$el.querySelector('.js-pipeline-info').innerText);

      expect(actual).toBe(expected);
    });

    it(`renders the correct merge request link`, () => {
      const actual = vm.$el.querySelector('.js-mr-link').href;

      expect(actual).toContain(pipeline.merge_request.path);
    });

    it(`renders the correct source branch link`, () => {
      const actual = vm.$el.querySelector('.js-source-branch-link').href;

      expect(actual).toContain(pipeline.merge_request.source_branch_path);
    });

    it(`renders the correct target branch link`, () => {
      const actual = vm.$el.querySelector('.js-target-branch-link').href;

      expect(actual).toContain(pipeline.merge_request.target_branch_path);
    });
  });

  describe('with a detached merge request pipeline', () => {
    let pipeline;

    beforeEach(() => {
      pipeline = JSON.parse(JSON.stringify(mockPipelineData));
      pipeline.flags.merge_request_pipeline = false;
      pipeline.flags.detached_merge_request_pipeline = true;

      vm = mountComponent(Component, {
        pipeline,
        stages: [],
        selectedStage: 'deploy',
      });
    });

    it(`renders the pipeline info like "Pipeline #123 for !456 with source_branch"`, () => {
      const expected = `Pipeline #${pipeline.id} for !${pipeline.merge_request.iid} with ${
        pipeline.merge_request.source_branch
      }`;
      const actual = trimText(vm.$el.querySelector('.js-pipeline-info').innerText);

      expect(actual).toBe(expected);
    });

    it(`renders the correct merge request link`, () => {
      const actual = vm.$el.querySelector('.js-mr-link').href;

      expect(actual).toContain(pipeline.merge_request.path);
    });

    it(`renders the correct source branch link`, () => {
      const actual = vm.$el.querySelector('.js-source-branch-link').href;

      expect(actual).toContain(pipeline.merge_request.source_branch_path);
    });
  });
});