diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-02-18 12:45:46 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-02-18 12:45:46 +0300 |
commit | a7b3560714b4d9cc4ab32dffcd1f74a284b93580 (patch) | |
tree | 7452bd5c3545c2fa67a28aa013835fb4fa071baf /spec/lib/gitlab/ci/badge/release/template_spec.rb | |
parent | ee9173579ae56a3dbfe5afe9f9410c65bb327ca7 (diff) |
Add latest changes from gitlab-org/gitlab@14-8-stable-eev14.8.0-rc42
Diffstat (limited to 'spec/lib/gitlab/ci/badge/release/template_spec.rb')
-rw-r--r-- | spec/lib/gitlab/ci/badge/release/template_spec.rb | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/spec/lib/gitlab/ci/badge/release/template_spec.rb b/spec/lib/gitlab/ci/badge/release/template_spec.rb new file mode 100644 index 00000000000..2b66c296a94 --- /dev/null +++ b/spec/lib/gitlab/ci/badge/release/template_spec.rb @@ -0,0 +1,90 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::Ci::Badge::Release::Template do + let(:project) { create(:project) } + let(:ref) { 'v1.2.3' } + let(:user) { create(:user) } + let!(:release) { create(:release, tag: ref, project: project) } + let(:badge) { Gitlab::Ci::Badge::Release::LatestRelease.new(project, user) } + let(:template) { described_class.new(badge) } + + before do + project.add_guest(user) + end + + describe '#key_text' do + it 'defaults to latest release' do + expect(template.key_text).to eq 'Latest Release' + end + + it 'returns custom key text' do + key_text = 'Test Release' + badge = Gitlab::Ci::Badge::Release::LatestRelease.new(project, user, opts: { key_text: key_text }) + + expect(described_class.new(badge).key_text).to eq key_text + end + end + + describe '#value_text' do + context 'when a release exists' do + it 'returns the tag of the release' do + expect(template.value_text).to eq ref + end + end + + context 'no releases exist' do + before do + allow(badge).to receive(:tag).and_return(nil) + end + + it 'returns string that latest release is none' do + expect(template.value_text).to eq 'none' + end + end + end + + describe '#key_width' do + it 'returns the default key width' do + expect(template.key_width).to eq 90 + end + + it 'returns custom key width' do + key_width = 100 + badge = Gitlab::Ci::Badge::Release::LatestRelease.new(project, user, opts: { key_width: key_width }) + + expect(described_class.new(badge).key_width).to eq key_width + end + end + + describe '#value_width' do + it 'has a fixed value width' do + expect(template.value_width).to eq 54 + end + end + + describe '#key_color' do + it 'always has the same color' do + expect(template.key_color).to eq '#555' + end + end + + describe '#value_color' do + context 'when release exists' do + it 'is blue' do + expect(template.value_color).to eq '#3076af' + end + end + + context 'when release does not exist' do + before do + allow(badge).to receive(:tag).and_return(nil) + end + + it 'is red' do + expect(template.value_color).to eq '#e05d44' + end + end + end +end |