File: settings_shared_examples.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (54 lines) | stat: -rw-r--r-- 1,734 bytes parent folder | download
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
# frozen_string_literal: true

RSpec.shared_examples 'all project settings sections exist and have correct anchor links' do
  let(:settings) { Search::ProjectSettings.new(project).all }
  let_it_be(:project) { create(:project) }
  let_it_be(:user) { create(:user) }

  it 'has only valid settings sections' do
    sign_in(user)
    project.add_maintainer(user)

    current_href = nil
    settings.each do |setting|
      # This speeds up the spec by not repeatedly visiting the same page.
      if current_href != remove_anchor_from_url(setting[:href])
        visit setting[:href]
        current_href = remove_anchor_from_url(setting[:href])
      end

      expect(page).to have_content setting[:text]
      expect(page).to have_css "##{URI.parse(setting[:href]).fragment}"
    end
  end
end

RSpec.shared_examples 'all group settings sections exist and have correct anchor links' do
  let(:settings) { Search::GroupSettings.new(group).all }
  let_it_be(:group) { create(:group) }
  let_it_be(:user) { create(:admin) } # some group settings require instance admin rights

  it 'has only valid settings sections' do
    sign_in(user)
    enable_admin_mode!(user)
    group.add_owner(user)

    current_href = nil
    settings.each do |setting|
      # This speeds up the spec by not repeatedly visiting the same page.
      if current_href != remove_anchor_from_url(setting[:href])
        visit setting[:href]
        current_href = remove_anchor_from_url(setting[:href])
      end

      expect(page).to have_content setting[:text]
      expect(page).to have_css "##{URI.parse(setting[:href]).fragment}", visible: :all
    end
  end
end

def remove_anchor_from_url(url)
  uri = URI.parse(url)
  uri.fragment = nil
  uri.to_s
end