summaryrefslogtreecommitdiff
path: root/qa/qa/page/project/settings/protected_branches.rb
blob: 659fe198d49466c5380fb214bfca388c2dd48e1a (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
# frozen_string_literal: true

module QA
  module Page
    module Project
      module Settings
        class ProtectedBranches < Page::Base
          view 'app/views/protected_branches/shared/_dropdown.html.haml' do
            element :protected_branch_dropdown
            element :protected_branch_dropdown_content
          end

          view 'app/views/protected_branches/_create_protected_branch.html.haml' do
            element :allowed_to_push_dropdown
            element :allowed_to_push_dropdown_content
            element :allowed_to_merge_dropdown
            element :allowed_to_merge_dropdown_content
          end

          view 'app/views/protected_branches/shared/_create_protected_branch.html.haml' do
            element :protect_button
          end

          def select_branch(branch_name)
            click_element :protected_branch_dropdown

            within_element(:protected_branch_dropdown_content) do
              click_on branch_name
            end
          end

          def select_allowed_to_merge(allowed)
            select_allowed(:merge, allowed)
          end

          def select_allowed_to_push(allowed)
            select_allowed(:push, allowed)
          end

          def protect_branch
            click_element(:protect_button, wait: QA::Support::Repeater::DEFAULT_MAX_WAIT_TIME)
            wait_for_requests
          end

          private

          def select_allowed(action, allowed)
            click_element :"allowed_to_#{action}_dropdown"

            allowed[:roles] = Resource::ProtectedBranch::Roles::NO_ONE unless allowed.key?(:roles)

            within_element(:"allowed_to_#{action}_dropdown_content") do
              click_on allowed[:roles][:description]
              allowed[:users].each { |user| click_on user.username } if allowed.key?(:users)
              allowed[:groups].each { |group| click_on group.name } if allowed.key?(:groups)
            end
          end
        end
      end
    end
  end
end

QA::Page::Project::Settings::ProtectedBranches.prepend_mod_with('Page::Project::Settings::ProtectedBranches', namespace: QA)