2019-07-25 01:24:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-07-19 07:31:47 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-16 14:09:01 -04:00
|
|
|
RSpec.describe 'Pipeline Badge' do
|
2020-02-26 13:09:24 -05:00
|
|
|
let_it_be(:project) { create(:project, :repository, :public) }
|
2021-04-21 02:09:28 -04:00
|
|
|
|
2017-07-21 08:36:22 -04:00
|
|
|
let(:ref) { project.default_branch }
|
2017-07-19 07:31:47 -04:00
|
|
|
|
2017-07-21 08:36:22 -04:00
|
|
|
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-10-30 06:53:01 -04:00
|
|
|
context 'when the pipeline was successful' do
|
2019-10-23 05:06:03 -04:00
|
|
|
it 'displays so on the badge', :sidekiq_might_not_need_inline do
|
2017-07-21 08:36:22 -04:00
|
|
|
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-10-23 05:06:03 -04:00
|
|
|
it 'shows displays so on the badge', :sidekiq_might_not_need_inline do
|
2017-07-21 08:36:22 -04:00
|
|
|
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-02-26 21:13:06 -05:00
|
|
|
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)
|
2019-03-03 18:56:20 -05:00
|
|
|
allow(job).to receive(:prerequisites).and_return([double])
|
2019-02-26 21:13:06 -05:00
|
|
|
end
|
|
|
|
|
2019-10-23 05:06:03 -04:00
|
|
|
it 'displays the preparing badge', :sidekiq_might_not_need_inline do
|
2019-03-03 18:56:20 -05:00
|
|
|
job.enqueue
|
2019-02-26 21:13:06 -05:00
|
|
|
|
|
|
|
visit pipeline_project_badges_path(project, ref: ref, format: :svg)
|
|
|
|
|
|
|
|
expect(page.status_code).to eq(200)
|
|
|
|
expect_badge('preparing')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-21 08:36:22 -04:00
|
|
|
context 'when the pipeline is running' do
|
2019-10-23 05:06:03 -04:00
|
|
|
it 'shows displays so on the badge', :sidekiq_might_not_need_inline do
|
2017-07-21 08:36:22 -04:00
|
|
|
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-06-01 20:09:56 -04:00
|
|
|
expect(page.response_headers['Cache-Control']).to eq('no-store')
|
2017-07-21 08:36:22 -04:00
|
|
|
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
|
2017-07-19 07:31:47 -04:00
|
|
|
end
|
|
|
|
end
|