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

menu.rb « main « page « qa « qa - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8fd3a8ca52f28aabcc32dd2774dd56537917cab7 (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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# frozen_string_literal: true

module QA
  module Page
    module Main
      class Menu < Page::Base
        # We need to check phone_layout? instead of mobile_layout? here
        # since tablets have the regular top navigation bar
        include SubMenus::CreateNewMenu
        include SubMenus::SuperSidebar::GlobalSearchModal

        view 'app/assets/javascripts/super_sidebar/components/super_sidebar.vue' do
          element 'super-sidebar', required: true
        end

        view 'app/assets/javascripts/super_sidebar/components/user_bar.vue' do
          element 'canary-badge-link'
        end

        view 'app/assets/javascripts/super_sidebar/components/user_menu.vue' do
          element 'user-dropdown', required: !Runtime::Env.phone_layout?
          element 'user-avatar-content', required: !Runtime::Env.phone_layout?
          element 'sign-out-link'
          element 'edit-profile-link'
        end

        view 'app/assets/javascripts/super_sidebar/components/user_menu_profile_item.vue' do
          element 'user-profile-link'
        end

        view 'app/assets/javascripts/super_sidebar/components/user_bar.vue' do
          element 'stop-impersonation-btn'
          element 'issues-shortcut-button', required: !Runtime::Env.phone_layout?
          element 'merge-requests-shortcut-button', required: !Runtime::Env.phone_layout?
          element 'todos-shortcut-button', required: !Runtime::Env.phone_layout?
        end

        view 'lib/gitlab/nav/top_nav_menu_item.rb' do
          element 'menu-item-link'
        end

        view 'app/helpers/nav/new_dropdown_helper.rb' do
          element 'global-new-group-link'
          element 'global-new-project-link'
          element 'global-new-snippet-link'
        end

        def go_to_projects
          click_element('nav-item-link', submenu_item: 'Projects')
        end

        def go_to_groups
          # This needs to be fixed in the tests themselves. Fullfillment tests try to go to groups view from the
          # group. Instead of having a global hack, explicit test should navigate to correct view first.
          # see: https://gitlab.com/gitlab-org/gitlab/-/issues/403589#note_1383040061
          go_to_your_work unless has_element?('nav-item-link', submenu_item: 'Groups', wait: 0)
          click_element('nav-item-link', submenu_item: 'Groups')
        end

        def go_to_snippets
          click_element('nav-item-link', submenu_item: 'Snippets')
        end

        def go_to_workspaces
          click_element('nav-item-link', submenu_item: 'Workspaces')
        end

        def go_to_menu_dropdown_option(option_name)
          click_element(option_name)
        end

        def go_to_todos
          click_element('todos-shortcut-button')
        end

        def signed_in?
          return false if Page::Main::Login.perform(&:on_login_page?)

          has_personal_area?(wait: 0)
        end

        def signed_in_as_user?(user)
          return false unless signed_in?

          within_user_menu do
            has_element?('user-profile-link', text: /#{user.username}/)
          end
          # we need to close user menu because plain user link check will leave it open
          click_element 'user-avatar-content' if has_element?('user-profile-link', wait: 0)
        end

        def not_signed_in?
          return true if Page::Main::Login.perform(&:on_login_page?)

          has_no_personal_area?
        end

        def sign_out
          close_global_search_modal_if_shown

          retry_until do
            wait_if_retry_later

            break true unless signed_in?

            within_user_menu do
              click_element 'sign-out-link'
            end

            not_signed_in?
          end
        end

        def sign_out_if_signed_in
          sign_out if signed_in?
        end

        def click_edit_profile_link
          retry_until(reload: false) do
            within_user_menu do
              click_element('edit-profile-link')
            end

            has_text?('User Settings')
          end
        end

        def click_user_profile_link
          within_user_menu do
            click_element('user-profile-link')
          end
        end

        def has_personal_area?(wait: Capybara.default_max_wait_time)
          has_element?('user-avatar-content', wait: wait)
        end

        def has_no_personal_area?(wait: Capybara.default_max_wait_time)
          has_no_element?('user-avatar-content', wait: wait)
        end

        def click_stop_impersonation_link
          click_element('stop-impersonation-btn')
        end

        # To verify whether the user has been directed to a canary web node
        # @return [Boolean] result of checking existence of 'canary-badge-link' element
        # @example:
        #   Menu.perform do |menu|
        #     expect(menu.canary?).to be(true)
        #   end
        def canary?
          has_element?('canary-badge-link')
        end

        private

        def within_user_menu(&block)
          within_element('super-sidebar') do
            click_element 'user-avatar-content' unless has_element?('user-profile-link', wait: 1)

            within_element('user-dropdown', &block)
          end
        end
      end
    end
  end
end

QA::Page::Main::Menu.prepend_mod_with('Page::Main::Menu', namespace: QA)