pipeline_spec.rb 8.42 KB
Newer Older
Filipa Lacerda's avatar
Filipa Lacerda committed
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
require 'spec_helper'

describe "Pipelines", feature: true, js: true do
  include GitlabRoutingHelper

  let(:project) { create(:empty_project) }
  let(:user) { create(:user) }

  before do
    login_as(user)
    project.team << [user, :developer]
  end

  describe 'GET /:project/pipelines/:id' do
    let(:project) { create(:project) }
    let(:pipeline) { create(:ci_pipeline, project: project, ref: 'master', sha: project.commit.id) }

    before do
      @success = create(:ci_build, :success, pipeline: pipeline, stage: 'build', name: 'build')
      @failed = create(:ci_build, :failed, pipeline: pipeline, stage: 'test', name: 'test', commands: 'test')
      @running = create(:ci_build, :running, pipeline: pipeline, stage: 'deploy', name: 'deploy')
      @manual = create(:ci_build, :manual, pipeline: pipeline, stage: 'deploy', name: 'manual build')
      @external = create(:generic_commit_status, status: 'success', pipeline: pipeline, name: 'jenkins', stage: 'external')
    end

    before { visit namespace_project_pipeline_path(project.namespace, project, pipeline) }

Filipa Lacerda's avatar
Filipa Lacerda committed
28 29 30
    it 'shows the pipeline graph' do
      expect(page).to have_selector('.pipeline-visualization')
      expect(page).to have_content('Build')
Filipa Lacerda's avatar
Filipa Lacerda committed
31 32 33 34 35 36 37 38 39 40
      expect(page).to have_content('Test')
      expect(page).to have_content('Deploy')
      expect(page).to have_content('Retry failed')
      expect(page).to have_content('Cancel running')
    end

    it 'shows Pipeline tab pane as active' do
      expect(page).to have_css('#js-tab-pipeline.active')
    end

Filipa Lacerda's avatar
Filipa Lacerda committed
41 42 43 44 45 46 47 48 49 50 51
    describe 'pipeline graph' do
      context 'when pipeline has running builds' do
        it 'shows a running icon and a cancel action for the running build' do
          page.within('a[data-title="deploy - running"]') do
            expect(page).to have_selector('.ci-status-icon-running')
            expect(page).to have_content('deploy')
          end

          page.within('a[data-title="deploy - running"] + .ci-action-icon-container') do
            expect(page).to have_selector('.ci-action-icon-container .fa-ban')
          end
Filipa Lacerda's avatar
Filipa Lacerda committed
52 53
        end

Filipa Lacerda's avatar
Filipa Lacerda committed
54 55
        it 'should be possible to cancel the running build' do
          find('a[data-title="deploy - running"] + .ci-action-icon-container').trigger('click')
Filipa Lacerda's avatar
Filipa Lacerda committed
56

Filipa Lacerda's avatar
Filipa Lacerda committed
57 58
          expect(page).not_to have_content('Cancel running')
        end
59 60
      end

Filipa Lacerda's avatar
Filipa Lacerda committed
61 62 63 64 65 66
      context 'when pipeline has successful builds' do
        it 'shows the success icon and a retry action for the successfull build' do
          page.within('a[data-title="build - passed"]') do
            expect(page).to have_selector('.ci-status-icon-success')
            expect(page).to have_content('build')
          end
Filipa Lacerda's avatar
Filipa Lacerda committed
67

Filipa Lacerda's avatar
Filipa Lacerda committed
68 69 70
          page.within('a[data-title="build - passed"] + .ci-action-icon-container') do
            expect(page).to have_selector('.ci-action-icon-container .fa-refresh')
          end
Filipa Lacerda's avatar
Filipa Lacerda committed
71 72
        end

Filipa Lacerda's avatar
Filipa Lacerda committed
73 74 75 76
        it 'should be possible to retry the success build' do
          find('a[data-title="build - passed"] + .ci-action-icon-container').trigger('click')

          expect(page).not_to have_content('Retry build')
77 78 79
        end
      end

Filipa Lacerda's avatar
Filipa Lacerda committed
80 81 82 83 84 85
      context 'when pipeline has failed builds' do
        it 'shows the failed icon and a retry action for the failed build' do
          page.within('a[data-title="test - failed"]') do
            expect(page).to have_selector('.ci-status-icon-failed')
            expect(page).to have_content('test')
          end
Filipa Lacerda's avatar
Filipa Lacerda committed
86

Filipa Lacerda's avatar
Filipa Lacerda committed
87 88 89
          page.within('a[data-title="test - failed"] + .ci-action-icon-container') do
            expect(page).to have_selector('.ci-action-icon-container .fa-refresh')
          end
Filipa Lacerda's avatar
Filipa Lacerda committed
90 91
        end

Filipa Lacerda's avatar
Filipa Lacerda committed
92 93 94 95
        it 'should be possible to retry the failed build' do
          find('a[data-title="test - failed"] + .ci-action-icon-container').trigger('click')

          expect(page).not_to have_content('Retry build')
96 97 98
        end
      end

Filipa Lacerda's avatar
Filipa Lacerda committed
99 100 101
      context 'when pipeline has manual builds' do
        it 'shows the skipped icon and a play action for the manual build' do
          page.within('a[data-title="manual build - manual play action"]') do
102
            expect(page).to have_selector('.ci-status-icon-manual')
Filipa Lacerda's avatar
Filipa Lacerda committed
103 104
            expect(page).to have_content('manual')
          end
Filipa Lacerda's avatar
Filipa Lacerda committed
105

Filipa Lacerda's avatar
Filipa Lacerda committed
106 107 108
          page.within('a[data-title="manual build - manual play action"] + .ci-action-icon-container') do
            expect(page).to have_selector('.ci-action-icon-container .fa-play')
          end
109 110
        end

Filipa Lacerda's avatar
Filipa Lacerda committed
111 112 113 114
        it 'should be possible to play the manual build' do
          find('a[data-title="manual build - manual play action"] + .ci-action-icon-container').trigger('click')

          expect(page).not_to have_content('Play build')
115 116
        end
      end
Filipa Lacerda's avatar
Filipa Lacerda committed
117

Filipa Lacerda's avatar
Filipa Lacerda committed
118 119 120 121 122
      context 'when pipeline has external build' do
        it 'shows the success icon and the generic comit status build' do
          expect(page).to have_selector('.ci-status-icon-success')
          expect(page).to have_content('jenkins')
        end
Filipa Lacerda's avatar
Filipa Lacerda committed
123
      end
124 125
    end

Filipa Lacerda's avatar
Filipa Lacerda committed
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 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
    context 'page tabs' do
      it 'shows Pipeline and Builds tabs with link' do
        expect(page).to have_link('Pipeline')
        expect(page).to have_link('Builds')
      end

      it 'shows counter in Builds tab' do
        expect(page.find('.js-builds-counter').text).to eq(pipeline.statuses.count.to_s)
      end

      it 'shows Pipeline tab as active' do
        expect(page).to have_css('.js-pipeline-tab-link.active')
      end
    end

    context 'retrying builds' do
      it { expect(page).not_to have_content('retried') }

      context 'when retrying' do
        before { click_on 'Retry failed' }

        it { expect(page).not_to have_content('Retry failed') }
      end
    end

    context 'canceling builds' do
      it { expect(page).not_to have_selector('.ci-canceled') }

      context 'when canceling' do
        before { click_on 'Cancel running' }

        it { expect(page).not_to have_content('Cancel running') }
      end
    end
  end

  describe 'GET /:project/pipelines/:id/builds' do
    let(:project) { create(:project) }
    let(:pipeline) { create(:ci_pipeline, project: project, ref: 'master', sha: project.commit.id) }

    before do
      @success = create(:ci_build, :success, pipeline: pipeline, stage: 'build', name: 'build')
      @failed = create(:ci_build, :failed, pipeline: pipeline, stage: 'test', name: 'test', commands: 'test')
      @running = create(:ci_build, :running, pipeline: pipeline, stage: 'deploy', name: 'deploy')
      @manual = create(:ci_build, :manual, pipeline: pipeline, stage: 'deploy', name: 'manual build')
      @external = create(:generic_commit_status, status: 'success', pipeline: pipeline, name: 'jenkins', stage: 'external')
    end

    before { visit builds_namespace_project_pipeline_path(project.namespace, project, pipeline)}

    it 'shows a list of builds' do
      expect(page).to have_content('Test')
      expect(page).to have_content(@success.id)
      expect(page).to have_content('Deploy')
      expect(page).to have_content(@failed.id)
      expect(page).to have_content(@running.id)
      expect(page).to have_content(@external.id)
      expect(page).to have_content('Retry failed')
      expect(page).to have_content('Cancel running')
      expect(page).to have_link('Play')
    end

    it 'shows Builds tab pane as active' do
      expect(page).to have_css('#js-tab-builds.active')
    end

    context 'page tabs' do
      it 'shows Pipeline and Builds tabs with link' do
        expect(page).to have_link('Pipeline')
        expect(page).to have_link('Builds')
      end

      it 'shows counter in Builds tab' do
        expect(page.find('.js-builds-counter').text).to eq(pipeline.statuses.count.to_s)
      end

      it 'shows Builds tab as active' do
        expect(page).to have_css('li.js-builds-tab-link.active')
      end
    end

    context 'retrying builds' do
      it { expect(page).not_to have_content('retried') }

      context 'when retrying' do
        before { click_on 'Retry failed' }

        it { expect(page).not_to have_content('Retry failed') }
        it { expect(page).to have_selector('.retried') }
      end
    end

    context 'canceling builds' do
      it { expect(page).not_to have_selector('.ci-canceled') }

      context 'when canceling' do
        before { click_on 'Cancel running' }

        it { expect(page).not_to have_content('Cancel running') }
        it { expect(page).to have_selector('.ci-canceled') }
      end
    end

    context 'playing manual build' do
      before do
        within '.pipeline-holder' do
          click_link('Play')
        end
      end

      it { expect(@manual.reload).to be_pending }
    end
  end
end