usage_quotas_spec.rb 2.93 KB
Newer Older
nicolasdular's avatar
nicolasdular committed
1 2 3 4
# frozen_string_literal: true

require 'spec_helper'

5
RSpec.describe 'Profile > Usage Quota' do
nicolasdular's avatar
nicolasdular committed
6 7 8 9 10 11 12 13 14
  using RSpec::Parameterized::TableSyntax

  let_it_be(:user, reload: true) { create(:user) }
  let_it_be(:namespace, reload: true) { user.namespace }
  let_it_be(:statistics, reload: true) { create(:namespace_statistics, namespace: namespace) }
  let_it_be(:project, reload: true) { create(:project, namespace: namespace) }
  let_it_be(:other_project) { create(:project, namespace: namespace, shared_runners_enabled: false) }

  before do
15
    stub_feature_flags(additional_repo_storage_by_namespace: true)
nicolasdular's avatar
nicolasdular committed
16 17 18
    gitlab_sign_in(user)
  end

19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
  it 'pushes frontend feature flags' do
    visit profile_usage_quotas_path

    expect(page).to have_pushed_frontend_feature_flags(
      additionalRepoStorageByNamespace: true
    )
  end

  context 'when `additional_repo_storage_by_namespace` is disabled for a namespace' do
    before do
      stub_feature_flags(additional_repo_storage_by_namespace: false, thing: namespace)
    end

    it 'pushes disabled feature flag to the frontend' do
      visit profile_usage_quotas_path

      expect(page).to have_pushed_frontend_feature_flags(
        additionalRepoStorageByNamespace: false
      )
    end
  end

nicolasdular's avatar
nicolasdular committed
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
  it 'is linked within the profile page' do
    visit profile_path

    page.within('.nav-sidebar') do
      expect(page).to have_selector(:link_or_button, 'Usage Quotas')
    end
  end

  describe 'shared runners use' do
    where(:shared_runners_enabled, :used, :quota, :usage_class, :usage_text) do
      false | 300  | 500 | 'success' | '300 / Unlimited minutes 0% used'
      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'
    end

    with_them do
      let(:no_shared_runners_text) { 'Shared runners are disabled, so there are no limits set on pipeline usage' }

      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)

        visit profile_usage_quotas_path
      end

      it 'shows the correct quota status' do
        page.within('.pipeline-quota') do
          expect(page).to have_content(usage_text)
          expect(page).to have_selector(".bg-#{usage_class}")
        end
      end

      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
      end
    end
  end
end