Welcome to mirror list, hosted at ThFree Co, Russian Federation.

access_tokens.rb « component « page « qa « qa - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c80df535aba9266c312811475f9ede40baa05a9a (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
# frozen_string_literal: true
require 'date'

module QA
  module Page
    module Component
      module AccessTokens
        extend QA::Page::PageConcern

        def self.included(base)
          super

          base.class_eval do
            include QA::Page::Component::ConfirmModal
          end

          base.view 'app/assets/javascripts/access_tokens/components/expires_at_field.vue' do
            element :expiry_date_field
          end

          base.view 'app/views/shared/access_tokens/_form.html.haml' do
            element :access_token_name_field
            element :create_token_button
          end

          base.view 'app/views/shared/tokens/_scopes_form.html.haml' do
            element 'api-label', '#{scope}-label' # rubocop:disable QA/ElementWithPattern, Lint/InterpolationCheck
          end

          base.view 'app/assets/javascripts/access_tokens/components/new_access_token_app.vue' do
            element :access_token_section
            element :created_access_token_field
          end

          base.view 'app/assets/javascripts/vue_shared/components/form/input_copy_toggle_visibility.vue' do
            element :toggle_visibility_button
          end

          base.view 'app/assets/javascripts/access_tokens/components/access_token_table_app.vue' do
            element :revoke_button
          end

          base.view 'app/views/profiles/personal_access_tokens/index.html.haml' do
            element 'add-new-token-button'
          end

          base.view 'app/views/projects/settings/access_tokens/index.html.haml' do
            element 'add-new-token-button'
          end

          base.view 'app/views/groups/settings/access_tokens/index.html.haml' do
            element 'add-new-token-button'
          end

          base.view 'app/views/admin/impersonation_tokens/index.html.haml' do
            element 'add-new-token-button'
          end
        end

        def click_add_new_token_button
          click_element('add-new-token-button')
        end

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

        def check_api
          click_element('api-label')
        end

        def click_create_token_button
          click_element(:create_token_button)
        end

        def created_access_token
          within_element(:access_token_section) do
            find_element(:created_access_token_field).value
          end
        end

        def fill_expiry_date(date)
          date = date.to_s if date.is_a?(Date)
          begin
            Date.strptime(date, '%Y-%m-%d')
          rescue ArgumentError
            raise "Expiry date must be in YYYY-MM-DD format"
          end

          fill_element(:expiry_date_field, date)
        end

        def has_token_row_for_name?(token_name)
          page.has_css?('tr', text: token_name, wait: 1.0)
        end

        def first_token_row_for_name(token_name)
          page.find('tr', text: token_name, match: :first, wait: 1.0)
        end

        def revoke_first_token_with_name(token_name)
          within first_token_row_for_name(token_name) do
            click_element(:revoke_button)
          end

          click_confirmation_ok_button
        end
      end
    end
  end
end