-
Notifications
You must be signed in to change notification settings - Fork 20
/
contextual_navigation_spec.rb
523 lines (438 loc) · 17.3 KB
/
contextual_navigation_spec.rb
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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
require "rails_helper"
describe "Contextual navigation" do
scenario "There's a step by step list" do
given_theres_a_page_with_a_step_by_step
and_i_visit_that_page
then_i_see_the_step_by_step
and_the_step_by_step_header
end
scenario "There's more than one step by step" do
given_theres_are_two_step_by_step_lists
and_i_visit_that_page
then_i_just_see_the_step_by_step_related_links
and_no_step_by_step_header
end
scenario "I see the step by step I am currently interacting with" do
given_theres_are_two_step_by_step_lists
and_i_visit_that_page_by_clicking_on_a_step_by_step_link
then_i_see_the_step_by_step_that_i_am_interacting_with
and_i_see_the_other_step_by_step_as_an_also_part_of_list
end
# scenario "There's a mainstream browse page with a browse parent" do
# given_theres_a_browse_page_with_a_browse_parent
# and_i_visit_that_page
# then_i_see_both_browse_pages_in_the_footer
# and_the_default_breadcrumbs
# end
scenario "Foreign travel advice content" do
given_theres_a_travel_advice_page
and_i_visit_that_page
then_i_see_parent_breadcrumbs
end
scenario "The page has curated related items" do
given_theres_a_page_with_related_items
and_i_visit_that_page
then_i_see_the_related_links_sidebar
and_the_default_breadcrumbs
end
scenario "It's a HTML Publication document" do
given_there_is_a_non_step_by_step_parent_page
and_the_page_is_an_html_publication_with_that_parent
and_i_visit_that_page
then_i_see_home_and_parent_links
end
scenario "It's a HTML Publication with a parent with breadcrumbs" do
given_there_is_a_parent_page_with_two_taxon
and_the_page_is_an_html_publication_with_that_parent
and_i_visit_that_page
then_i_see_home_and_parent_breadcrumbs
then_i_see_four_breadcrumb_links # home, 2 x taxon, parent
end
scenario "It's a HTML Publication with a parent tagged to a step by step" do
given_there_is_a_parent_page_with_a_step_by_step
and_the_page_is_an_html_publication_with_that_parent
and_i_visit_that_page
then_i_see_the_step_by_step_breadcrumbs
end
scenario "There's a taxon tagged" do
given_theres_a_guide_with_a_live_taxon_tagged_to_it
and_i_visit_that_page
then_i_see_the_taxon_in_the_related_navigation_footer
and_the_taxonomy_breadcrumbs
end
scenario "A page tagged to browse, without a browse parent" do
given_theres_a_page_tagged_to_browse_with_no_browse_parent
and_i_visit_that_page
then_i_see_the_browse_page_in_the_footer
and_the_taxonomy_breadcrumbs
end
scenario "There's a secondary step by step list and no primary step by step list" do
given_theres_a_page_with_a_secondary_step_by_step
and_i_visit_that_page
then_i_see_the_step_by_step
and_the_step_by_step_header
end
scenario "There's more than one secondary step by step list and no primary step by step list" do
given_there_are_two_secondary_step_by_step_lists
and_i_visit_that_page
then_i_just_see_the_step_by_step_related_links
end
scenario "There's 3 secondary step by steps and 2 primary step by step lists" do
given_there_are_three_secondary_step_by_steps_and_two_primary_to_step_navs
and_i_visit_that_page
then_i_just_see_the_step_by_step_related_links_with_just_two_links
and_i_dont_see_the_secondary_step_by_step_related_links
end
scenario "There's 1 primary step by step and 1 secondary step by step" do
given_there_are_one_primary_step_by_steps_and_one_secondary_to_step_navs
and_i_visit_that_page
then_i_see_the_step_by_step
then_i_see_the_primary_step_by_step
end
scenario "There's a related to step by step lists and no primary step by step list" do
given_there_is_a_related_to_step_nav
and_i_visit_that_page
then_theres_no_step_by_step_at_all
and_no_step_by_step_header
end
scenario "There are three related to step by step lists and no primary step by step list" do
given_there_are_three_related_to_step_nav
and_i_visit_that_page
then_theres_no_step_by_step_at_all
and_no_step_by_step_header
end
scenario "There are three related to step by step lists, no primary step by step list and one secondary to step nav" do
given_there_are_three_related_to_step_nav_and_one_secondary_to_step_nav
and_i_visit_that_page
then_theres_no_step_by_step_at_all
and_no_step_by_step_header
end
scenario "There's 2 primary step by step, 1 secondary step by step and I am interacting with one of the primary" do
given_there_are_two_primary_step_by_steps_and_one_secondary_to_step_navs
and_i_visit_that_page_by_clicking_on_a_step_by_step_link
then_i_see_the_step_by_step_that_i_am_interacting_with
and_i_see_the_other_step_by_step_as_an_also_part_of_list
and_i_dont_see_the_secondary_step_by_step_in_the_also_part_of_list
end
scenario "There is a page tagged to the 'Russian invasion of Ukraine: UK government response' topical event" do
given_theres_a_page_tagged_to_the_ukraine_topical_event
and_i_visit_that_page
then_i_see_the_ukraine_call_to_action
end
def given_theres_a_page_tagged_to_the_ukraine_topical_event
content_store_has_random_item(
schema: "news_article",
links: {
"topical_events" => [{
"content_id" => "bfa79635-ffda-4b5d-8266-a9cd3a03649c",
"title" => "Russian invasion of Ukraine: UK government response",
"locale" => "en",
"base_path" => "/government/topical-events/russian-invasion-of-ukraine-uk-government-response",
"document_type" => "topical_event",
}],
},
)
end
def then_i_see_the_ukraine_call_to_action
within ".gem-c-contextual-sidebar__cta" do
expect(page).to have_content("Invasion of Ukraine")
within ".gem-c-contextual-sidebar__list" do
expect(page).to have_link(href: /.+/)
end
end
end
include GdsApi::TestHelpers::ContentStore
def given_theres_a_page_with_a_step_by_step
content_store_has_random_item(links: { part_of_step_navs: [random_step_nav_item("step_by_step_nav")] })
end
def given_theres_are_two_step_by_step_lists
part_of_step_navs = 2.times.map { random_step_nav_item("step_by_step_nav") }
part_of_step_navs[0]["title"] = "PRIMARY STEP BY STEP - NOT INTERACTING WITH"
part_of_step_navs[1]["content_id"] = "8ad999bd-8603-40eb-97c0-999cb22047cd"
part_of_step_navs[1]["title"] = "PRIMARY STEP BY STEP - INTERACTING WITH"
content_store_has_random_item(links: { part_of_step_navs: })
end
def given_theres_a_page_with_a_secondary_step_by_step
content_store_has_random_item(links: { secondary_to_step_navs: [random_step_nav_item("step_by_step_nav")] })
end
def given_there_are_two_secondary_step_by_step_lists
content_store_has_random_item(links: { secondary_to_step_navs: 2.times.map { random_step_nav_item("step_by_step_nav") } })
end
def given_there_are_three_secondary_step_by_steps_and_two_primary_to_step_navs
secondary_to_step_navs = 3.times.map { random_step_nav_item("step_by_step_nav") }
secondary_to_step_navs[0]["title"] = "SECONDARY STEP BY STEP"
content_store_has_random_item(links: {
secondary_to_step_navs:,
part_of_step_navs: 2.times.map { random_step_nav_item("step_by_step_nav") },
})
end
def given_there_are_one_primary_step_by_steps_and_one_secondary_to_step_navs
part_of_step_nav = random_step_nav_item("step_by_step_nav")
part_of_step_nav["title"] = "PRIMARY STEP BY STEP"
content_store_has_random_item(links: {
secondary_to_step_navs: [random_step_nav_item("step_by_step_nav")],
part_of_step_navs: [part_of_step_nav],
})
end
def given_there_are_two_primary_step_by_steps_and_one_secondary_to_step_navs
part_of_step_navs = 2.times.map { random_step_nav_item("step_by_step_nav") }
part_of_step_navs[0]["title"] = "PRIMARY STEP BY STEP - NOT INTERACTING WITH"
part_of_step_navs[1]["content_id"] = "8ad999bd-8603-40eb-97c0-999cb22047cd"
part_of_step_navs[1]["title"] = "PRIMARY STEP BY STEP - INTERACTING WITH"
secondary_to_step_nav = random_step_nav_item("step_by_step_nav")
secondary_to_step_nav["title"] = "SECONDARY STEP BY STEP"
content_store_has_random_item(links: {
part_of_step_navs:,
secondary_to_step_navs: [secondary_to_step_nav],
})
end
def given_there_is_a_related_to_step_nav
content_store_has_random_item(links: {
related_to_step_navs: [random_step_nav_item("step_by_step_nav")],
})
end
def given_there_are_three_related_to_step_nav
content_store_has_random_item(links: {
related_to_step_navs: 3.times.map { random_step_nav_item("step_by_step_nav") },
})
end
def given_there_are_three_related_to_step_nav_and_one_secondary_to_step_nav
content_store_has_random_item(links: {
related_to_step_navs: 3.times.map { random_step_nav_item("step_by_step_nav") },
secondary_to_step_navs: [random_step_nav_item("step_by_step_nav")],
})
end
def given_theres_a_browse_page_with_a_browse_parent
content_store_has_random_item(
links: {
"parent" => [top_level_mainstream_browse_page],
"mainstream_browse_pages" => [example_item("mainstream_browse_page", "root_page")],
},
)
end
def given_theres_a_travel_advice_page
content_store_has_random_item(
schema: "travel_advice",
links: {
"parent" => [example_parent_page],
},
)
end
def given_theres_a_page_with_related_items
content_store_has_random_item(
links: {
"parent" => [top_level_mainstream_browse_page],
"ordered_related_items" => [example_item("guide", "guide")],
},
)
end
def given_theres_a_guide_with_a_live_taxon_tagged_to_it
alpha_taxon = example_item("taxon", "taxon_in_alpha_phase")
live_taxon = taxon_item
content_store_has_random_item(
schema: "guide",
links: {
"taxons" => [live_taxon, alpha_taxon],
},
)
end
def given_theres_a_page_tagged_to_browse_with_no_browse_parent
live_taxon = taxon_item
content_store_has_random_item(links: {
"mainstream_browse_pages" => [top_level_mainstream_browse_page],
"taxons" => [live_taxon],
})
end
def tag_page_to_a_taxon(*taxons)
content_store_has_random_item(
links: {
"taxons" => taxons,
},
)
end
def given_there_is_a_non_step_by_step_parent_page
@parent = not_step_by_step_content
end
def not_step_by_step_content
not_step_by_step_content = random_item("guide")
not_step_by_step_content["links"].delete("part_of_step_navs")
not_step_by_step_content["links"].delete("secondary_to_step_navs")
not_step_by_step_content
end
def given_there_is_a_parent_page_with_two_taxon
taxon = taxon_item
taxon_two = taxon_item
@parent = random_item("guide")
@parent["links"] = { "taxons" => [taxon, taxon_two] }
end
def given_there_is_a_parent_page_with_a_step_by_step
step_by_step = random_step_nav_item("step_by_step_nav").merge("title" => "A step by step page")
@parent = random_item("guide")
@parent["links"]["part_of_step_navs"] = [step_by_step]
@parent["links"].delete("finder")
end
def and_the_page_is_an_html_publication_with_that_parent
content_item = example_item("html_publication", "published")
content_item["base_path"] = "/page-with-contextual-navigation"
content_item["links"]["parent"] = [@parent]
stub_content_store_has_item(@parent["base_path"], @parent)
stub_content_store_has_item(content_item["base_path"], content_item)
end
def and_i_visit_that_page
visit "/contextual-navigation/page-with-contextual-navigation"
end
def and_i_visit_that_page_by_clicking_on_a_step_by_step_link
visit "/contextual-navigation/page-with-contextual-navigation?step-by-step-nav=8ad999bd-8603-40eb-97c0-999cb22047cd"
end
def then_i_see_the_step_by_step
expect(page).to have_selector(".gem-c-step-nav-related")
expect(page).to have_selector(".gem-c-step-nav__header")
end
def then_i_see_the_step_by_step_that_i_am_interacting_with
expect(page).to have_selector(".gem-c-step-nav-related")
expect(page).to have_selector(".gem-c-step-nav__header")
within ".gem-c-step-nav-header" do
expect(page).to have_content("PRIMARY STEP BY STEP - INTERACTING WITH")
expect(page).not_to have_content("PRIMARY STEP BY STEP - NOT INTERACTING WITH")
end
end
def and_the_step_by_step_header
expect(page).to have_selector(".gem-c-step-nav-header")
end
def then_i_just_see_the_step_by_step_related_links
expect(page).to have_selector(".gem-c-step-nav-related")
expect(page).not_to have_selector(".gem-c-step-nav__header")
end
def then_i_just_see_the_step_by_step_related_links_with_just_two_links
expect(page).to have_selector(".gem-c-step-nav-related")
expect(page).not_to have_selector(".gem-c-step-nav__header")
within(".gem-c-step-nav-related") do
expect(page).to have_xpath(".//li", count: 2)
end
end
def and_no_step_by_step_header
expect(page).not_to have_selector(".gem-c-step-nav-header")
end
def then_theres_no_step_by_step_at_all
expect(page).not_to have_selector(".gem-c-step-nav-related")
expect(page).not_to have_selector(".gem-c-step-nav__header")
end
def and_i_dont_see_the_secondary_step_by_step_related_links
within ".gem-c-step-nav-related" do
expect(page).not_to have_content("SECONDARY STEP BY STEP")
end
end
def and_i_see_the_other_step_by_step_as_an_also_part_of_list
within ".gem-c-step-nav-related:last-of-type" do
expect(page).to have_content("Also part of")
expect(page).to have_content("PRIMARY STEP BY STEP - NOT INTERACTING WITH")
expect(page).not_to have_content("PRIMARY STEP BY STEP - INTERACTING WITH")
end
end
def and_i_dont_see_the_secondary_step_by_step_in_the_also_part_of_list
within ".gem-c-step-nav-related:last-of-type" do
expect(page).not_to have_content("SECONDARY STEP BY STEP")
end
end
def then_i_see_both_browse_pages_in_the_footer
within ".gem-c-contextual-footer" do
expect(page).to have_selector(".gem-c-related-navigation")
expect(page).to have_content("Browse")
expect(page).to have_content("Benefits")
end
end
def then_i_see_the_browse_page_in_the_footer
within ".gem-c-contextual-footer" do
expect(page).to have_selector(".gem-c-related-navigation")
expect(page).to have_content("Benefits")
end
end
def then_i_see_the_related_links_sidebar
within ".gem-c-contextual-sidebar" do
expect(page).to have_selector(".gem-c-related-navigation")
expect(page).to have_content("The national curriculum")
end
end
def then_i_see_the_primary_step_by_step
within ".gem-c-step-nav-header" do
expect(page).to have_content("PRIMARY STEP BY STEP")
end
end
def and_the_default_breadcrumbs
within ".gem-c-breadcrumbs" do
expect(page).to have_link("Home")
expect(page).to have_link(top_level_mainstream_browse_page["title"])
end
end
def then_i_see_parent_breadcrumbs
within ".gem-c-breadcrumbs" do
expect(page).to have_link("Home")
expect(page).to have_link(example_parent_page["title"])
end
end
def and_the_taxonomy_breadcrumbs
within ".gem-c-breadcrumbs" do
expect(page).to have_link("Home")
expect(page).to have_link(taxon_item["title"])
end
end
def then_i_see_the_step_by_step_breadcrumbs
within ".gem-c-contextual-breadcrumbs" do
expect(page).to have_link("A step by step page")
end
end
def then_i_see_the_taxon_in_the_related_navigation_footer
within ".gem-c-contextual-footer" do
expect(page).to have_css(".gem-c-related-navigation__link", text: taxon_item["title"])
end
end
# Use links version if output could be either step by step or breadcrumbs
def then_i_see_home_and_parent_links
within ".gem-c-contextual-breadcrumbs" do
expect(page).to have_link("Home")
expect(page).to have_link(@parent["title"])
end
end
def then_i_see_home_and_parent_breadcrumbs
within ".gem-c-breadcrumbs" do
expect(page).to have_link("Home")
expect(page).to have_link(@parent["title"])
end
end
def then_i_see_four_breadcrumb_links
within(".gem-c-breadcrumbs") do
expect(page).to have_selector(".govuk-breadcrumbs__list-item", count: 4)
end
end
def then_i_do_not_see_home_and_parent_breadcrumbs
expect(page).not_to have_selector(".gem-c-breadcrumbs")
end
def content_store_has_random_item(schema: "guide", links: {})
content_item = random_item(
schema,
"base_path" => "/page-with-contextual-navigation",
"links" => links,
)
stub_content_store_has_item(content_item["base_path"], content_item)
end
def random_step_nav_item(schema_name)
GovukSchemas::Example.find(schema_name, example_name: "step_by_step_nav")
end
def example_item(schema_name, example_name)
GovukSchemas::Example.find(schema_name, example_name:)
end
def random_item(schema_name, merge_with = {})
GovukSchemas::RandomExample.for_schema(frontend_schema: schema_name) do |random_item|
random_item.merge(merge_with)
end
end
def example_parent_page
@example_parent_page ||= example_item("answer", "answer")
end
def top_level_mainstream_browse_page
@top_level_mainstream_browse_page ||= example_item("mainstream_browse_page", "top_level_page")
end
def taxon_item
@taxon_item ||= example_item("taxon", "taxon")
end
end