require 'spec_helper' describe 'Pipeline', :js do include RoutesHelpers include ProjectForksHelper let(:project) { create(:project) } let(:user) { create(:user) } let(:role) { :developer } before do sign_in(user) project.add_role(user, role) end shared_context 'pipeline builds' do let!(:build_passed) do create(:ci_build, :success, pipeline: pipeline, stage: 'build', name: 'build') end let!(:build_failed) do create(:ci_build, :failed, pipeline: pipeline, stage: 'test', name: 'test') end let!(:build_preparing) do create(:ci_build, :preparing, pipeline: pipeline, stage: 'deploy', name: 'prepare') end let!(:build_running) do create(:ci_build, :running, pipeline: pipeline, stage: 'deploy', name: 'deploy') end let!(:build_manual) do create(:ci_build, :manual, pipeline: pipeline, stage: 'deploy', name: 'manual-build') end let!(:build_scheduled) do create(:ci_build, :scheduled, pipeline: pipeline, stage: 'deploy', name: 'delayed-job') end let!(:build_external) do create(:generic_commit_status, status: 'success', pipeline: pipeline, name: 'jenkins', stage: 'external', target_url: 'http://gitlab.com/status') end end describe 'GET /:project/pipelines/:id' do include_context 'pipeline builds' let(:project) { create(:project, :repository) } let(:pipeline) { create(:ci_pipeline, project: project, ref: 'master', sha: project.commit.id, user: user) } subject(:visit_pipeline) { visit project_pipeline_path(project, pipeline) } it 'shows the pipeline graph' do visit_pipeline expect(page).to have_selector('.pipeline-visualization') expect(page).to have_content('Build') expect(page).to have_content('Test') expect(page).to have_content('Deploy') expect(page).to have_content('Retry') expect(page).to have_content('Cancel running') end it 'shows Pipeline tab pane as active' do visit_pipeline expect(page).to have_css('#js-tab-pipeline.active') end it 'shows link to the pipeline ref' do visit_pipeline expect(page).to have_link(pipeline.ref) end it 'shows the pipeline information' do visit_pipeline within '.pipeline-info' do expect(page).to have_content("#{pipeline.statuses.count} jobs " \ "for #{pipeline.ref} ") expect(page).to have_link(pipeline.ref, href: project_commits_path(pipeline.project, pipeline.ref)) end end it_behaves_like 'showing user status' do let(:user_with_status) { pipeline.user } subject { visit project_pipeline_path(project, pipeline) } end describe 'pipeline graph' do before do visit_pipeline end context 'when pipeline has running builds' do it 'shows a running icon and a cancel action for the running build' do page.within('#ci-badge-deploy') do expect(page).to have_selector('.js-ci-status-icon-running') expect(page).to have_selector('.js-icon-cancel') expect(page).to have_content('deploy') end end it 'cancels the running build and does not show retry button' do find('#ci-badge-deploy .ci-action-icon-container').click page.within('#ci-badge-deploy') do expect(page).not_to have_css('.js-icon-retry') end end end context 'when pipeline has preparing builds' do it 'shows a preparing icon and a cancel action' do page.within('#ci-badge-prepare') do expect(page).to have_selector('.js-ci-status-icon-preparing') expect(page).to have_selector('.js-icon-cancel') expect(page).to have_content('prepare') end end it 'cancels the preparing build and does not show retry button' do find('#ci-badge-deploy .ci-action-icon-container').click page.within('#ci-badge-deploy') do expect(page).not_to have_css('.js-icon-retry') end end end context 'when pipeline has successful builds' do it 'shows the success icon and a retry action for the successful build' do page.within('#ci-badge-build') do expect(page).to have_selector('.js-ci-status-icon-success') expect(page).to have_content('build') end page.within('#ci-badge-build .ci-action-icon-container.js-icon-retry') do expect(page).to have_selector('svg') end end it 'is possible to retry the success job' do find('#ci-badge-build .ci-action-icon-container').click expect(page).not_to have_content('Retry job') end end context 'when pipeline has a delayed job' do it 'shows the scheduled icon and an unschedule action for the delayed job' do page.within('#ci-badge-delayed-job') do expect(page).to have_selector('.js-ci-status-icon-scheduled') expect(page).to have_content('delayed-job') end page.within('#ci-badge-delayed-job .ci-action-icon-container.js-icon-time-out') do expect(page).to have_selector('svg') end end it 'unschedules the delayed job and shows play button as a manual job' do find('#ci-badge-delayed-job .ci-action-icon-container').click page.within('#ci-badge-delayed-job') do expect(page).to have_css('.js-icon-play') end end end context 'when pipeline has failed builds' do it 'shows the failed icon and a retry action for the failed build' do page.within('#ci-badge-test') do expect(page).to have_selector('.js-ci-status-icon-failed') expect(page).to have_content('test') end page.within('#ci-badge-test .ci-action-icon-container.js-icon-retry') do expect(page).to have_selector('svg') end end it 'is possible to retry the failed build' do find('#ci-badge-test .ci-action-icon-container').click expect(page).not_to have_content('Retry job') end it 'includes the failure reason' do page.within('#ci-badge-test') do build_link = page.find('.js-pipeline-graph-job-link') expect(build_link['data-original-title']).to eq('test - failed - (unknown failure)') end end end context 'when pipeline has manual jobs' do it 'shows the skipped icon and a play action for the manual build' do page.within('#ci-badge-manual-build') do expect(page).to have_selector('.js-ci-status-icon-manual') expect(page).to have_content('manual') end page.within('#ci-badge-manual-build .ci-action-icon-container.js-icon-play') do expect(page).to have_selector('svg') end end it 'is possible to play the manual job' do find('#ci-badge-manual-build .ci-action-icon-container').click expect(page).not_to have_content('Play job') end end context 'when pipeline has external job' do it 'shows the success icon and the generic comit status build' do expect(page).to have_selector('.js-ci-status-icon-success') expect(page).to have_content('jenkins') expect(page).to have_link('jenkins', href: 'http://gitlab.com/status') end end end context 'when the pipeline has manual stage' do before do create(:ci_build, :manual, pipeline: pipeline, stage: 'publish', name: 'CentOS') create(:ci_build, :manual, pipeline: pipeline, stage: 'publish', name: 'Debian') create(:ci_build, :manual, pipeline: pipeline, stage: 'publish', name: 'OpenSUDE') visit_pipeline end it 'displays play all button' do expect(page).to have_selector('.js-stage-action') end end context 'page tabs' do before do visit_pipeline end it 'shows Pipeline, Jobs and Failed Jobs tabs with link' do expect(page).to have_link('Pipeline') expect(page).to have_link('Jobs') expect(page).to have_link('Failed Jobs') end it 'shows counter in Jobs tab' do expect(page.find('.js-builds-counter').text).to eq(pipeline.total_size.to_s) end it 'shows Pipeline tab as active' do expect(page).to have_css('.js-pipeline-tab-link .active') end context 'without permission to access builds' do let(:project) { create(:project, :public, :repository, public_builds: false) } let(:role) { :guest } it 'does not show failed jobs tab pane' do expect(page).to have_link('Pipeline') expect(page).not_to have_content('Failed Jobs') end end end context 'retrying jobs' do before do visit_pipeline end it { expect(page).not_to have_content('retried') } context 'when retrying' do before do find('.js-retry-button').click end it { expect(page).not_to have_content('Retry') } end end context 'canceling jobs' do before do visit_pipeline end it { expect(page).not_to have_selector('.ci-canceled') } context 'when canceling' do before do click_on 'Cancel running' end it { expect(page).not_to have_content('Cancel running') } end end context 'when pipeline ref does not exist in repository anymore' do let(:pipeline) do create(:ci_empty_pipeline, project: project, ref: 'non-existent', sha: project.commit.id, user: user) end before do visit_pipeline end it 'does not render link to the pipeline ref' do expect(page).not_to have_link(pipeline.ref) expect(page).to have_content(pipeline.ref) end it 'does not render render raw HTML to the pipeline ref' do page.within '.pipeline-info' do expect(page).not_to have_content('