-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathnavigation_spec.rb
More file actions
320 lines (245 loc) · 11 KB
/
navigation_spec.rb
File metadata and controls
320 lines (245 loc) · 11 KB
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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
require 'rails_helper'
describe 'Navigation' do
before { @user = create(:user) }
describe 'items' do
before { create :page, creator: @user }
context 'as a guest' do
it 'offers the expected links' do
visit root_path
within 'nav' do
expect(page).to have_link 'Base'
within '#content_navigation' do
expect(page).to have_link 'Page test navigation title'
end
within '#meta_navigation' do
expect(page).not_to have_link 'List of Pages'
expect(page).not_to have_link 'Create Page'
expect(page).not_to have_link 'List of Users'
expect(page).not_to have_link 'Create User'
expect(page).not_to have_link 'Application configuration'
expect(page).not_to have_link 'Show account'
expect(page).not_to have_link 'Edit account'
expect(page).not_to have_link 'Log out'
expect(page).not_to have_link 'Admin'
end
end
end
end
context 'as a user' do
it 'offers the expected links' do
login_as @user
visit root_path
within 'nav' do
expect(page).to have_link 'Base'
within '#content_navigation' do
expect(page).to have_link 'Page test navigation title'
end
within '#meta_navigation' do
expect(page).not_to have_link 'List of Pages'
expect(page).not_to have_link 'Create Page'
expect(page).to have_link 'List of Users'
expect(page).not_to have_link 'Create User'
expect(page).to have_link 'Show account'
expect(page).not_to have_link 'Application configuration'
expect(page).to have_link 'Edit account'
expect(page).to have_link 'Log out'
expect(page).not_to have_link 'Admin'
end
end
end
end
context 'as an editor' do
it 'offers the expected links' do
login_as create :user, :editor
visit root_path
within 'nav' do
expect(page).to have_link 'Base'
within '#content_navigation' do
expect(page).to have_link 'Page test navigation title'
end
within '#meta_navigation' do
expect(page).to have_link 'List of Pages'
expect(page).to have_link 'Create Page'
expect(page).to have_link 'List of Users'
expect(page).not_to have_link 'Create User'
expect(page).not_to have_link 'Application configuration'
expect(page).to have_link 'Show account'
expect(page).to have_link 'Edit account'
expect(page).to have_link 'Log out'
expect(page).not_to have_link 'Admin'
end
end
end
end
context 'as an admin' do
it 'offers the expected links' do
login_as create :user, :admin
visit root_path
within 'nav' do
expect(page).to have_link 'Base'
within '#content_navigation' do
expect(page).to have_link 'Page test navigation title'
end
within '#meta_navigation' do
expect(page).to have_link 'List of Pages'
expect(page).to have_link 'Create Page'
expect(page).to have_link 'List of Users'
expect(page).to have_link 'Create User'
expect(page).to have_link 'Application configuration'
expect(page).to have_link 'Show account'
expect(page).to have_link 'Edit account'
expect(page).to have_link 'Log out'
end
end
end
end
end
it 'offers the possibility to switch locale' do
visit root_path
expect(page).to have_css '.dropdown-toggle', text: 'Choose locale' # Default locale is english
click_link 'Seite auf Deutsch anzeigen'
expect(page).to have_css '.dropdown-toggle', text: 'Sprache wählen'
click_link 'Show page in english'
expect(page).to have_css '.dropdown-toggle', text: 'Choose locale'
end
it 'shows the "Menu" button on small, medium, and large screens (and collapses it on extra small ones)', js: true do
visit root_path
within 'nav' do
screen_width :xs do
expect(page).to have_button 'Menu'
end
screen_width :sm do
expect(page).not_to have_button 'Menu'
end
screen_width :md do
expect(page).not_to have_button 'Menu'
end
screen_width :lg do
expect(page).not_to have_button 'Menu'
end
end
end
it 'reports the status of dropdowns (expanded/collapsed) to non-visual agents', js: true do
visit root_path
within '#locale_chooser' do
expect {
click_link 'Choose locale'
}.to change { find('.dropdown-toggle')['aria-expanded'].to_b }.from(false).to true
end
end
it 'reports the responsiveness status (expanded/collapsed) to non-visual agents', js: true do
visit root_path
within 'nav' do
screen_width :xs do
expect {
click_button 'Menu'
}.to change { find('#toggle_navigation')['aria-expanded'].to_b }.from(false).to true
end
end
end
it 'reports the activity status of menu groups and items visually and aurally' do
login_as create :user, :admin
visit root_path
active_menu_group_css = '.dropdown.active > a.dropdown-toggle'
active_menu_group_text = 'Users (current menu group)'
active_menu_item_css = '.dropdown.active > ul.dropdown-menu > li.active > a'
active_menu_item_text = 'List of Users (current menu item)'
within 'nav' do
expect(page).not_to have_css active_menu_group_css
expect(page).not_to have_text active_menu_group_text
expect(page).not_to have_css active_menu_item_css
expect(page).not_to have_text active_menu_item_text
end
click_link 'List of Users'
within 'nav' do
expect(page).to have_css active_menu_group_css, text: active_menu_group_text
expect(page).to have_css active_menu_item_css, text: active_menu_item_text
end
end
it "only uses root pages as menu groups" do
parent_page = create :page, creator: @user, title: 'Parent page', navigation_title: nil
@page = create :page, creator: @user, title: 'Cool page', navigation_title: nil, parent: parent_page
visit root_path
expect(page).to have_css 'a.dropdown-toggle', text: 'Parent page'
expect(page).to have_css '.dropdown > .dropdown-menu > li > a', text: 'Cool page'
end
# A menu group "Users" has a "List of Users" and a "Create User" item, but no "Edit User" item; for the latter, we still want the group to be marked up as active
it "reports the activity status of menu groups (that don't have an active item) visually and semantically" do
user = create :user, :admin
login_as user
visit root_path
active_menu_group_css = '.dropdown.active > a.dropdown-toggle'
active_menu_group_text = 'Users (current menu group)'
within 'nav' do
expect(page).not_to have_css active_menu_group_css
expect(page).not_to have_text active_menu_group_text
end
visit edit_user_path(user)
within 'nav' do
expect(page).to have_css active_menu_group_css, text: active_menu_group_text
end
end
it "reports the menu groups and menu items correctly as active" do
parent_page = create :page, creator: @user, title: 'Parent page', navigation_title: nil
@page = create :page, creator: @user, title: 'Cool page', navigation_title: nil, parent: parent_page
# First, none of the pages should be reported as active
visit root_path
expect(page).to have_css '.dropdown:not(.active) > a', text: 'Parent page'
expect(page).not_to have_link 'Parent page (current menu group)'
expect(page).to have_css '.dropdown:not(.active) > ul > li a:not(.active)', text: 'Overview'
expect(page).not_to have_link 'Overview (current menu item)'
expect(page).to have_css '.dropdown:not(.active) > ul > li a:not(.active)', text: 'Cool page'
expect(page).not_to have_link 'Cool page (current menu item)'
# Now, when visiting the menu group, it should be reported as active, and the overview menu item, too.
visit page_path(parent_page)
expect(page).to have_css '.dropdown.active > a', text: 'Parent page (current menu group)'
expect(page).to have_css '.dropdown.active > ul > li.active a', text: 'Overview (current menu item)'
expect(page).to have_css '.dropdown.active > ul > li:not(.active)', text: 'Cool page'
expect(page).not_to have_link 'Cool page (current menu item)'
# Now, when visiting the menu item, the menu group should be reported as active, and the menu item (but not the overview menu item anymore)
visit page_path(@page)
expect(page).to have_css '.dropdown.active > a', text: 'Parent page (current menu group)'
expect(page).to have_css '.dropdown.active > ul > li:not(.active)', text: 'Overview'
expect(page).not_to have_link 'Overview (current menu item)'
expect(page).to have_css '.dropdown.active > ul > li.active a', text: 'Cool page (current menu item)'
# GET params are not taken into account: /users?x=y is the same as /users.
# This makes sure that even when a Ransack query is active, the "List of X" item in the menu is still active.
login_as create :user, :admin
visit root_path
click_link 'List of Users'
expect(page).to have_css '.dropdown.active > a', text: 'Users (current menu group)'
expect(page).to have_css '.dropdown.active > ul > li.active > a', text: 'List of Users (current menu item)'
click_link 'Remove filter'
expect(page).to have_css '.dropdown.active > a', text: 'Users (current menu group)'
expect(page).to have_css '.dropdown.active > ul > li.active > a', text: 'List of Users (current menu item)'
end
context 'jump links' do
it 'visually displays them only on focus', js: true do
visit page_path(create :page, creator: @user)
['#jump_to_home_page', '#jump_to_content'].each do |selector|
expect(page).to have_selector("#{selector}[class='sr-only']")
focus_element("#{selector}")
expect(page).not_to have_selector("#{selector}[class='sr-only']")
unfocus_element("#{selector}")
expect(page).to have_selector("#{selector}[class='sr-only']")
end
end
it 'jumps to content when clicking jump to content link', js: true do
visit page_path(create :page, creator: @user)
focus_element('#jump_to_content')
click_link 'Jump to content'
expect(focused_element_id).to eq 'headline_title'
end
it 'offers access keys', js: true do
visit page_path(create :page, creator: @user)
expect(page).to have_css '#jump_to_home_page[accesskey="0"]'
expect(page).to have_css '#jump_to_content[accesskey="1"]'
end
it 'displays the link to the home page only on other pages' do
visit root_path
expect(page).not_to have_link 'Jump to home page'
visit page_path(create :page, creator: @user)
expect(page).to have_link 'Jump to home page'
end
end
end