summaryrefslogtreecommitdiff
path: root/spec/features/projects/settings/registry_settings_spec.rb
blob: 4e1b53ffc877bb9e87e885cf00332a73b70cd686 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Project > Settings > CI/CD > Container registry tag expiration policy', :js do
  using RSpec::Parameterized::TableSyntax

  let_it_be(:user) { create(:user) }
  let_it_be(:project, reload: true) { create(:project, namespace: user.namespace) }

  let(:container_registry_enabled) { true }
  let(:container_registry_enabled_on_project) { true }

  subject { visit project_settings_ci_cd_path(project) }

  before do
    project.update!(container_registry_enabled: container_registry_enabled_on_project)

    sign_in(user)
    stub_container_registry_config(enabled: container_registry_enabled)
    stub_feature_flags(new_variables_ui: false)
  end

  context 'as owner' do
    it 'shows available section' do
      subject

      settings_block = find('#js-registry-policies')
      expect(settings_block).to have_text 'Cleanup policy for tags'
    end

    it 'saves cleanup policy submit the form' do
      subject

      within '#js-registry-policies' do
        within '.card-body' do
          select('7 days until tags are automatically removed', from: 'Expiration interval:')
          select('Every day', from: 'Expiration schedule:')
          select('50 tags per image name', from: 'Number of tags to retain:')
          fill_in('Tags with names matching this regex pattern will expire:', with: '.*-production')
        end
        submit_button = find('.card-footer .btn.btn-success')
        expect(submit_button).not_to be_disabled
        submit_button.click
      end
      toast = find('.gl-toast')
      expect(toast).to have_content('Cleanup policy successfully saved.')
    end

    it 'does not save cleanup policy submit form with invalid regex' do
      subject

      within '#js-registry-policies' do
        within '.card-body' do
          fill_in('Tags with names matching this regex pattern will expire:', with: '*-production')
        end
        submit_button = find('.card-footer .btn.btn-success')
        expect(submit_button).not_to be_disabled
        submit_button.click
      end
      toast = find('.gl-toast')
      expect(toast).to have_content('Something went wrong while updating the cleanup policy.')
    end
  end

  context 'with a project without expiration policy' do
    where(:application_setting, :feature_flag, :result) do
      true  | true  | :available_section
      true  | false | :available_section
      false | true  | :available_section
      false | false | :disabled_message
    end

    with_them do
      before do
        project.container_expiration_policy.destroy!
        stub_feature_flags(container_expiration_policies_historic_entry: false)
        stub_application_setting(container_expiration_policies_enable_historic_entries: application_setting)
        stub_feature_flags(container_expiration_policies_historic_entry: project) if feature_flag
      end

      it 'displays the expected result' do
        subject

        within '#js-registry-policies' do
          case result
          when :available_section
            expect(find('.card-header')).to have_content('Tag expiration policy')
          when :disabled_message
            expect(find('.gl-alert-title')).to have_content('Cleanup policy for tags is disabled')
          end
        end
      end
    end
  end

  context 'when registry is disabled' do
    let(:container_registry_enabled) { false }

    it 'does not exists' do
      subject

      expect(page).not_to have_selector('#js-registry-policies')
    end
  end

  context 'when container registry is disabled on project' do
    let(:container_registry_enabled_on_project) { false }

    it 'does not exists' do
      subject

      expect(page).not_to have_selector('#js-registry-policies')
    end
  end
end