2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
RSpec.describe 'Pipeline Badge' do
|
2020-04-08 14:13:33 +05:30
|
|
|
let_it_be(:project) { create(:project, :repository, :public) }
|
2021-06-08 01:23:25 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
let(:ref) { project.default_branch }
|
|
|
|
|
|
|
|
context 'when the project has a pipeline' do
|
|
|
|
let!(:pipeline) { create(:ci_empty_pipeline, project: project, ref: ref, sha: project.commit(ref).sha) }
|
|
|
|
let!(:job) { create(:ci_build, pipeline: pipeline) }
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
context 'when the pipeline was successful' do
|
2019-12-26 22:10:19 +05:30
|
|
|
it 'displays so on the badge', :sidekiq_might_not_need_inline do
|
2017-09-10 17:25:29 +05:30
|
|
|
job.success
|
|
|
|
|
|
|
|
visit pipeline_project_badges_path(project, ref: ref, format: :svg)
|
|
|
|
|
|
|
|
expect(page.status_code).to eq(200)
|
|
|
|
expect_badge('passed')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the pipeline failed' do
|
2019-12-26 22:10:19 +05:30
|
|
|
it 'shows displays so on the badge', :sidekiq_might_not_need_inline do
|
2017-09-10 17:25:29 +05:30
|
|
|
job.drop
|
|
|
|
|
|
|
|
visit pipeline_project_badges_path(project, ref: ref, format: :svg)
|
|
|
|
|
|
|
|
expect(page.status_code).to eq(200)
|
|
|
|
expect_badge('failed')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
context 'when the pipeline is preparing' do
|
|
|
|
let!(:job) { create(:ci_build, status: 'created', pipeline: pipeline) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
# Prevent skipping directly to 'pending'
|
|
|
|
allow(Ci::BuildPrepareWorker).to receive(:perform_async)
|
|
|
|
allow(job).to receive(:prerequisites).and_return([double])
|
|
|
|
end
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
it 'displays the preparing badge', :sidekiq_might_not_need_inline do
|
2019-07-07 11:18:12 +05:30
|
|
|
job.enqueue
|
|
|
|
|
|
|
|
visit pipeline_project_badges_path(project, ref: ref, format: :svg)
|
|
|
|
|
|
|
|
expect(page.status_code).to eq(200)
|
|
|
|
expect_badge('preparing')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
context 'when the pipeline is running' do
|
2019-12-26 22:10:19 +05:30
|
|
|
it 'shows displays so on the badge', :sidekiq_might_not_need_inline do
|
2017-09-10 17:25:29 +05:30
|
|
|
create(:ci_build, pipeline: pipeline, name: 'second build', status_event: 'run')
|
|
|
|
|
|
|
|
visit pipeline_project_badges_path(project, ref: ref, format: :svg)
|
|
|
|
|
|
|
|
expect(page.status_code).to eq(200)
|
|
|
|
expect_badge('running')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a new pipeline is created' do
|
|
|
|
it 'shows a fresh badge' do
|
|
|
|
visit pipeline_project_badges_path(project, ref: ref, format: :svg)
|
|
|
|
|
|
|
|
expect(page.status_code).to eq(200)
|
2021-11-18 22:05:49 +05:30
|
|
|
expect(page.response_headers['Cache-Control']).to eq('private, no-store')
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def expect_badge(status)
|
|
|
|
svg = Nokogiri::XML.parse(page.body)
|
|
|
|
expect(page.response_headers['Content-Type']).to include('image/svg+xml')
|
|
|
|
expect(svg.at(%Q{text:contains("#{status}")})).to be_truthy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|