summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/ci/status/build/failed_allowed_spec.rb
blob: 015006896190e799636db7d1f11b385c988089ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# frozen_string_literal: true

require 'spec_helper'

describe Gitlab::Ci::Status::Build::FailedAllowed do
  let(:status) { double('core status') }
  let(:user) { double('user') }
  let(:build) { create(:ci_build, :failed, :allowed_to_fail) }

  subject do
    described_class.new(status)
  end

  describe '#text' do
    it 'does not override status text' do
      expect(status).to receive(:text)

      subject.text
    end
  end

  describe '#icon' do
    it 'returns a warning icon' do
      expect(subject.icon).to eq 'status_warning'
    end
  end

  describe '#label' do
    it 'returns information about failed but allowed to fail status' do
      expect(subject.label).to eq 'failed (allowed to fail)'
    end
  end

  describe '#group' do
    it 'returns status failed with warnings status group' do
      expect(subject.group).to eq 'failed-with-warnings'
    end
  end

  describe 'action details' do
    describe '#has_action?' do
      it 'does not decorate action details' do
        expect(status).to receive(:has_action?)

        subject.has_action?
      end
    end

    describe '#action_path' do
      it 'does not decorate action path' do
        expect(status).to receive(:action_path)

        subject.action_path
      end
    end

    describe '#action_icon' do
      it 'does not decorate action icon' do
        expect(status).to receive(:action_icon)

        subject.action_icon
      end
    end

    describe '#action_title' do
      it 'does not decorate action title' do
        expect(status).to receive(:action_title)

        subject.action_title
      end
    end
  end

  describe '#badge_tooltip' do
    let(:user) { create(:user) }
    let(:failed_status) { Gitlab::Ci::Status::Failed.new(build, user) }
    let(:build_status) { Gitlab::Ci::Status::Build::Failed.new(failed_status) }
    let(:status) { described_class.new(build_status) }

    it 'does override badge_tooltip' do
      expect(status.badge_tooltip).to eq('failed - (unknown failure)')
    end
  end

  describe '#status_tooltip' do
    let(:user) { create(:user) }
    let(:failed_status) { Gitlab::Ci::Status::Failed.new(build, user) }
    let(:build_status) { Gitlab::Ci::Status::Build::Failed.new(failed_status) }
    let(:status) { described_class.new(build_status) }

    it 'does override status_tooltip' do
      expect(status.status_tooltip).to eq 'failed - (unknown failure) (allowed to fail)'
    end
  end

  describe '.matches?' do
    subject { described_class.matches?(build, user) }

    context 'when build is failed' do
      context 'when build is allowed to fail' do
        let(:build) { create(:ci_build, :failed, :allowed_to_fail) }

        it 'is a correct match' do
          expect(subject).to be true
        end
      end

      context 'when build is not allowed to fail' do
        let(:build) { create(:ci_build, :failed) }

        it 'is not a correct match' do
          expect(subject).not_to be true
        end
      end
    end

    context 'when build did not fail' do
      context 'when build is allowed to fail' do
        let(:build) { create(:ci_build, :success, :allowed_to_fail) }

        it 'is not a correct match' do
          expect(subject).not_to be true
        end
      end

      context 'when build is not allowed to fail' do
        let(:build) { create(:ci_build, :success) }

        it 'is not a correct match' do
          expect(subject).not_to be true
        end
      end
    end
  end
end