debian-mirror-gitlab/spec/lib/gitlab/ci/badge/pipeline/template_spec.rb

141 lines
3.5 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2016-09-13 17:45:13 +05:30
require 'spec_helper'
2021-03-11 19:13:27 +05:30
RSpec.describe Gitlab::Ci::Badge::Pipeline::Template do
2020-06-23 00:09:42 +05:30
let(:badge) { double(entity: 'pipeline', status: 'success', customization: {}) }
2016-09-13 17:45:13 +05:30
let(:template) { described_class.new(badge) }
describe '#key_text' do
2020-06-23 00:09:42 +05:30
it 'says pipeline by default' do
2017-09-10 17:25:29 +05:30
expect(template.key_text).to eq 'pipeline'
2016-09-13 17:45:13 +05:30
end
2020-06-23 00:09:42 +05:30
context 'when custom key_text is defined' do
before do
allow(badge).to receive(:customization).and_return({ key_text: 'custom text' })
end
it 'returns custom value' do
expect(template.key_text).to eq 'custom text'
end
context 'when its size is larger than the max allowed value' do
before do
2020-11-24 15:15:51 +05:30
allow(badge).to receive(:customization).and_return({ key_text: 't' * 65 })
2020-06-23 00:09:42 +05:30
end
it 'returns default value' do
expect(template.key_text).to eq 'pipeline'
end
end
end
2016-09-13 17:45:13 +05:30
end
describe '#value_text' do
it 'is status value' do
2017-09-10 17:25:29 +05:30
expect(template.value_text).to eq 'passed'
2016-09-13 17:45:13 +05:30
end
end
2020-06-23 00:09:42 +05:30
describe '#key_width' do
it 'is fixed by default' do
expect(template.key_width).to eq 62
end
context 'when custom key_width is defined' do
before do
allow(badge).to receive(:customization).and_return({ key_width: 101 })
end
it 'returns custom value' do
expect(template.key_width).to eq 101
end
context 'when it is larger than the max allowed value' do
before do
2020-11-24 15:15:51 +05:30
allow(badge).to receive(:customization).and_return({ key_width: 513 })
2020-06-23 00:09:42 +05:30
end
it 'returns default value' do
expect(template.key_width).to eq 62
end
end
end
end
2016-09-13 17:45:13 +05:30
describe 'widths and text anchors' do
it 'has fixed width and text anchors' do
2017-09-10 17:25:29 +05:30
expect(template.width).to eq 116
expect(template.key_width).to eq 62
2016-09-13 17:45:13 +05:30
expect(template.value_width).to eq 54
2017-09-10 17:25:29 +05:30
expect(template.key_text_anchor).to eq 31
expect(template.value_text_anchor).to eq 89
2016-09-13 17:45:13 +05:30
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
2019-07-07 11:18:12 +05:30
context 'when status is preparing' do
before do
allow(badge).to receive(:status).and_return('preparing')
end
it 'has expected color' do
2019-12-21 20:55:43 +05:30
expect(template.value_color).to eq '#a7a7a7'
2019-07-07 11:18:12 +05:30
end
end
2016-09-13 17:45:13 +05:30
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