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

module QA
  module Page
    module Project
      module Settings
        class DeployTokens < Page::Base
          view 'app/views/shared/deploy_tokens/_form.html.haml' do
            element :deploy_token_name_field
            element :deploy_token_expires_at_field
            element :deploy_token_read_repository_checkbox
            element :deploy_token_read_package_registry_checkbox
            element :deploy_token_read_registry_checkbox
            element :create_deploy_token_button
          end

          view 'app/views/shared/deploy_tokens/_new_deploy_token.html.haml' do
            element :created_deploy_token_container
            element :deploy_token_user_field
            element :deploy_token_field
          end

          def fill_token_name(name)
            fill_element(:deploy_token_name_field, name)
          end

          def fill_token_expires_at(expires_at)
            fill_element(:deploy_token_expires_at_field, expires_at.to_s + "\n")
          end

          def fill_scopes(read_repository: false, read_registry: false, read_package_registry: false)
            check_element(:deploy_token_read_repository_checkbox) if read_repository
            check_element(:deploy_token_read_package_registry_checkbox) if read_package_registry
            check_element(:deploy_token_read_registry_checkbox) if read_registry
          end

          def add_token
            click_element(:create_deploy_token_button)
          end

          def token_username
            within_new_project_deploy_token do
              find_element(:deploy_token_user_field).value
            end
          end

          def token_password
            within_new_project_deploy_token do
              find_element(:deploy_token_field).value
            end
          end

          private

          def within_new_project_deploy_token
            has_element?(:created_deploy_token_container, wait: QA::Support::Repeater::DEFAULT_MAX_WAIT_TIME)

            within_element(:created_deploy_token_container) do
              yield
            end
          end
        end
      end
    end
  end
end