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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
|
# frozen_string_literal: true
module QA
module Page
module Main
class Menu < Page::Base
prepend Mobile::Page::Main::Menu if Runtime::Env.mobile_layout?
view 'app/views/layouts/header/_current_user_dropdown.html.haml' do
element :sign_out_link
element :edit_profile_link
end
view 'app/views/layouts/header/_default.html.haml' do
element :navbar, required: true
element :canary_badge_link
element :user_avatar_content, required: !QA::Runtime::Env.mobile_layout?
element :user_menu, required: !QA::Runtime::Env.mobile_layout?
element :stop_impersonation_link
element :issues_shortcut_button, required: !QA::Runtime::Env.mobile_layout?
element :merge_requests_shortcut_button, required: !QA::Runtime::Env.mobile_layout?
element :todos_shortcut_button, required: !QA::Runtime::Env.mobile_layout?
end
view 'app/assets/javascripts/nav/components/top_nav_app.vue' do
element :navbar_dropdown
end
view 'app/assets/javascripts/nav/components/top_nav_dropdown_menu.vue' do
element :menu_subview_container
end
view 'lib/gitlab/nav/top_nav_menu_item.rb' do
element :menu_item_link
end
view 'app/helpers/nav/top_nav_helper.rb' do
element :admin_area_link
element :projects_dropdown
element :groups_dropdown
element :snippets_link
end
view 'app/views/layouts/_search.html.haml' do
element :search_term_field
end
view 'app/views/layouts/_header_search.html.haml' do
element :search_box
end
view 'app/assets/javascripts/header_search/components/app.vue' do
element :search_term_field
end
view 'app/views/layouts/header/_new_dropdown.html.haml' do
element :new_menu_toggle
end
view 'app/helpers/nav/new_dropdown_helper.rb' do
element :global_new_group_link
element :global_new_project_link
end
def go_to_groups
within_groups_menu do
# Remove if statement once :remove_extra_primary_submenu_options ff is enabled by default
if has_element?(:menu_item_link, title: 'Your groups')
click_element(:menu_item_link, title: 'Your groups')
else
click_element(:menu_item_link, title: 'View all groups')
end
end
end
def go_to_create_group
click_element(:new_menu_toggle)
click_element(:global_new_group_link)
end
def go_to_projects
within_projects_menu do
# Remove if statement once :remove_extra_primary_submenu_options ff is enabled by default
if has_element?(:menu_item_link, title: 'Your projects')
click_element(:menu_item_link, title: 'Your projects')
else
click_element(:menu_item_link, title: 'View all projects')
end
end
end
def go_to_create_project
click_element(:new_menu_toggle)
click_element(:global_new_project_link)
end
def go_to_menu_dropdown_option(option_name)
within_top_menu do
click_element(:navbar_dropdown, title: 'Menu')
click_element(option_name)
end
end
# To go to one of the popular pages using the provided shortcut buttons within top menu
# @param [Symbol] the name of the element (e.g: `:issues_shortcut button`)
# @example:
# Menu.perform do |menu|
# menu.go_to_page_by_shortcut(:issues_shortcut_button) #=> Go to Issues page using shortcut button
# end
def go_to_page_by_shortcut(button)
within_top_menu do
click_element(button)
end
end
def go_to_admin_area
click_admin_area
return unless has_text?('Enter Admin Mode', wait: 1.0)
Admin::NewSession.perform do |new_session|
new_session.set_password(Runtime::User.admin_password)
new_session.click_enter_admin_mode
end
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 if has_no_personal_area?
within_user_menu do
has_element?(:user_profile_link, text: /#{user.username}/)
end
end
def not_signed_in?
return true if Page::Main::Login.perform(&:on_login_page?)
has_no_personal_area?
end
def sign_out
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 search_for(term)
click_element(:search_box)
fill_element :search_term_field, "#{term}\n"
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 has_admin_area_link?(wait: Capybara.default_max_wait_time)
within_top_menu do
click_element(:navbar_dropdown, title: 'Menu')
has_element?(:admin_area_link, wait: wait)
end
end
def has_no_admin_area_link?(wait: Capybara.default_max_wait_time)
within_top_menu do
click_element(:navbar_dropdown, title: 'Menu')
has_no_element?(:admin_area_link, wait: wait)
end
end
def click_stop_impersonation_link
click_element(:stop_impersonation_link)
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_top_menu(&block)
within_element(:navbar, &block)
end
def within_user_menu(&block)
within_top_menu do
click_element :user_avatar_content unless has_element?(:user_profile_link, wait: 1)
within_element(:user_menu, &block)
end
end
def within_groups_menu(&block)
go_to_menu_dropdown_option(:groups_dropdown)
within_element(:menu_subview_container, &block)
end
def within_projects_menu(&block)
go_to_menu_dropdown_option(:projects_dropdown)
within_element(:menu_subview_container, &block)
end
def click_admin_area
go_to_menu_dropdown_option(:admin_area_link)
end
end
end
end
end
QA::Page::Main::Menu.prepend_mod_with('Page::Main::Menu', namespace: QA)
|