2019-07-25 01:24:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-15 05:41:01 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2018-07-05 02:32:05 -04:00
|
|
|
describe 'test coverage badge' do
|
|
|
|
let!(:user) { create(:user) }
|
|
|
|
let!(:project) { create(:project, :private) }
|
2016-08-15 05:41:01 -04:00
|
|
|
|
|
|
|
context 'when user has access to view badge' do
|
2018-07-05 02:32:05 -04:00
|
|
|
before do
|
2017-12-22 03:18:28 -05:00
|
|
|
project.add_developer(user)
|
2017-06-21 19:44:10 -04:00
|
|
|
sign_in(user)
|
2016-08-15 05:41:01 -04:00
|
|
|
end
|
|
|
|
|
2018-07-05 02:32:05 -04:00
|
|
|
it 'user requests coverage badge image for pipeline' do
|
2016-08-18 06:38:14 -04:00
|
|
|
create_pipeline do |pipeline|
|
|
|
|
create_build(pipeline, coverage: 100, name: 'test:1')
|
|
|
|
create_build(pipeline, coverage: 90, name: 'test:2')
|
|
|
|
end
|
2016-08-15 05:41:01 -04:00
|
|
|
|
|
|
|
show_test_coverage_badge
|
|
|
|
|
2017-03-20 09:34:47 -04:00
|
|
|
expect_coverage_badge('95.00%')
|
2016-08-15 05:41:01 -04:00
|
|
|
end
|
|
|
|
|
2018-07-05 02:32:05 -04:00
|
|
|
it 'user requests coverage badge for specific job' do
|
2016-08-18 06:38:14 -04:00
|
|
|
create_pipeline do |pipeline|
|
|
|
|
create_build(pipeline, coverage: 50, name: 'test:1')
|
|
|
|
create_build(pipeline, coverage: 50, name: 'test:2')
|
|
|
|
create_build(pipeline, coverage: 85, name: 'coverage')
|
|
|
|
end
|
2016-08-15 05:41:01 -04:00
|
|
|
|
|
|
|
show_test_coverage_badge(job: 'coverage')
|
|
|
|
|
2017-03-20 09:34:47 -04:00
|
|
|
expect_coverage_badge('85.00%')
|
2016-08-15 05:41:01 -04:00
|
|
|
end
|
|
|
|
|
2018-07-05 02:32:05 -04:00
|
|
|
it 'user requests coverage badge for pipeline without coverage' do
|
2016-08-18 06:38:14 -04:00
|
|
|
create_pipeline do |pipeline|
|
|
|
|
create_build(pipeline, coverage: nil, name: 'test')
|
|
|
|
end
|
2016-08-15 05:41:01 -04:00
|
|
|
|
|
|
|
show_test_coverage_badge
|
|
|
|
|
|
|
|
expect_coverage_badge('unknown')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user does not have access to view badge' do
|
2018-07-05 02:32:05 -04:00
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
end
|
2016-08-15 05:41:01 -04:00
|
|
|
|
2018-07-05 02:32:05 -04:00
|
|
|
it 'user requests test coverage badge image' do
|
2016-08-15 05:41:01 -04:00
|
|
|
show_test_coverage_badge
|
|
|
|
|
2020-01-24 10:09:00 -05:00
|
|
|
expect(page).to have_gitlab_http_status(:not_found)
|
2016-08-15 05:41:01 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-18 06:38:14 -04:00
|
|
|
def create_pipeline
|
2017-07-24 18:51:14 -04:00
|
|
|
opts = { project: project }
|
2016-08-18 06:38:14 -04:00
|
|
|
|
|
|
|
create(:ci_pipeline, opts).tap do |pipeline|
|
|
|
|
yield pipeline
|
2020-01-17 10:08:37 -05:00
|
|
|
pipeline.update_legacy_status
|
2016-08-18 06:38:14 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def create_build(pipeline, coverage:, name:)
|
|
|
|
opts = { pipeline: pipeline, coverage: coverage, name: name }
|
|
|
|
|
|
|
|
create(:ci_build, :success, opts)
|
2016-08-15 05:41:01 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def show_test_coverage_badge(job: nil)
|
2017-07-06 12:20:50 -04:00
|
|
|
visit coverage_project_badges_path(project, ref: :master, job: job, format: :svg)
|
2016-08-15 05:41:01 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def expect_coverage_badge(coverage)
|
|
|
|
svg = Nokogiri::XML.parse(page.body)
|
|
|
|
expect(page.response_headers['Content-Type']).to include('image/svg+xml')
|
|
|
|
expect(svg.at(%Q{text:contains("#{coverage}")})).to be_truthy
|
|
|
|
end
|
|
|
|
end
|