pipeline_quota_spec.rb 2.15 KB
Newer Older
1 2
require 'spec_helper'

Nick Thomas's avatar
Nick Thomas committed
3 4 5
describe 'Profile > Pipeline Quota' do
  using RSpec::Parameterized::TableSyntax

6 7 8
  set(:user) { create(:user) }
  set(:namespace) { user.namespace }
  set(:statistics) { create(:namespace_statistics, namespace: namespace) }
Nick Thomas's avatar
Nick Thomas committed
9 10 11
  set(:project) { create(:project, namespace: namespace) }
  set(:other_project) { create(:project, namespace: namespace, shared_runners_enabled: false) }

12
  before do
Rémy Coutable's avatar
Rémy Coutable committed
13
    gitlab_sign_in(user)
14 15
  end

16 17 18
  it 'is linked within the profile page' do
    visit profile_path

19
    page.within('.nav-sidebar') do
20 21 22
      expect(page).to have_selector(:link_or_button, 'Pipeline quota')
    end
  end
23

Nick Thomas's avatar
Nick Thomas committed
24 25
  describe 'shared runners use' do
    where(:shared_runners_enabled, :used, :quota, :usage_class, :usage_text) do
26
      false | 300  | 500 | 'success' | '300 / Unlimited minutes 0% used'
Nick Thomas's avatar
Nick Thomas committed
27 28 29
      true  | 300  | nil | 'success' | '300 / Unlimited minutes Unlimited'
      true  | 300  | 500 | 'success' | '300 / 500 minutes 60% used'
      true  | 1000 | 500 | 'danger'  | '1000 / 500 minutes 200% used'
30 31
    end

Nick Thomas's avatar
Nick Thomas committed
32
    with_them do
33
      let(:no_shared_runners_text) { 'Shared runners are disabled, so there are no limits set on pipeline usage' }
34

Nick Thomas's avatar
Nick Thomas committed
35 36 37 38
      before do
        project.update!(shared_runners_enabled: shared_runners_enabled)
        statistics.update!(shared_runners_seconds: used.minutes.to_i)
        namespace.update!(shared_runners_minutes_limit: quota)
39

Nick Thomas's avatar
Nick Thomas committed
40
        visit profile_pipeline_quota_path
41 42
      end

Nick Thomas's avatar
Nick Thomas committed
43 44 45
      it 'shows the correct quota status' do
        page.within('.pipeline-quota') do
          expect(page).to have_content(usage_text)
Clement Ho's avatar
Clement Ho committed
46
          expect(page).to have_selector(".bg-#{usage_class}")
Nick Thomas's avatar
Nick Thomas committed
47
        end
48 49
      end

Nick Thomas's avatar
Nick Thomas committed
50 51 52 53 54 55 56 57 58 59 60 61
      it 'shows the correct per-project metrics' do
        page.within('.pipeline-project-metrics') do
          expect(page).not_to have_content(other_project.name)

          if shared_runners_enabled
            expect(page).to have_content(project.name)
            expect(page).not_to have_content(no_shared_runners_text)
          else
            expect(page).not_to have_content(project.name)
            expect(page).to have_content(no_shared_runners_text)
          end
        end
62 63 64 65
      end
    end
  end
end