gitlab-org--gitlab-foss/spec/lib/gitlab/badge/pipeline/template_spec.rb
Z.J. van de Weg 2086483b24 Rename build to pipeline for status badges
First commit in probably 2, for resolve gitlab-org/gitlab-ce#15582. This
commit is renaming files and classes from build to pipeline. Also
wording is editted to pipeline. Given `pipeline` had more characters
than `build`, I've made the field a bit wider. The width now matchers
the one for the coverage badge, so they look nice when in a table
format, or in a list.

As soon as this commit is merged to master, and released, the build.svg
is deprecated, meaning that all users which already placed a badge
should update it. However, to make sure it keeps working tests are added
for this case.
2017-07-21 10:22:09 +02:00

82 lines
2 KiB
Ruby

require 'spec_helper'
describe Gitlab::Badge::Pipeline::Template do
let(:badge) { double(entity: 'pipeline', status: 'success') }
let(:template) { described_class.new(badge) }
describe '#key_text' do
it 'is always says pipeline' do
expect(template.key_text).to eq 'pipeline'
end
end
describe '#value_text' do
it 'is status value' do
expect(template.value_text).to eq 'success'
end
end
describe 'widths and text anchors' do
it 'has fixed width and text anchors' do
expect(template.width).to eq 116
expect(template.key_width).to eq 62
expect(template.value_width).to eq 54
expect(template.key_text_anchor).to eq 31
expect(template.value_text_anchor).to eq 89
end
end
describe '#key_color' do
it 'is always the same' do
expect(template.key_color).to eq '#555'
end
end
describe '#value_color' do
context 'when status is success' do
it 'has expected color' do
expect(template.value_color).to eq '#4c1'
end
end
context 'when status is failed' do
before do
allow(badge).to receive(:status).and_return('failed')
end
it 'has expected color' do
expect(template.value_color).to eq '#e05d44'
end
end
context 'when status is running' do
before do
allow(badge).to receive(:status).and_return('running')
end
it 'has expected color' do
expect(template.value_color).to eq '#dfb317'
end
end
context 'when status is unknown' do
before do
allow(badge).to receive(:status).and_return('unknown')
end
it 'has expected color' do
expect(template.value_color).to eq '#9f9f9f'
end
end
context 'when status does not match any known statuses' do
before do
allow(badge).to receive(:status).and_return('invalid')
end
it 'has expected color' do
expect(template.value_color).to eq '#9f9f9f'
end
end
end
end