govuk_navigation_helpers 8.2.2 → 9.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Rakefile +1 -1
- data/config/step_navs/learn-to-drive-a-car.json +248 -0
- data/govuk_navigation_helpers.gemspec +8 -7
- data/lib/govuk_navigation_helpers.rb +1 -2
- data/lib/govuk_navigation_helpers/configuration.rb +1 -2
- data/lib/govuk_navigation_helpers/step_nav_content.rb +107 -0
- data/lib/govuk_navigation_helpers/taxon_breadcrumbs.rb +3 -2
- data/lib/govuk_navigation_helpers/version.rb +1 -1
- data/spec/related_navigation_sidebar_spec.rb +6 -12
- data/spec/{tasklist_content_spec.rb → step_nav_content_spec.rb} +25 -25
- data/spec/taxon_breadcrumbs_spec.rb +3 -3
- metadata +43 -46
- data/config/tasklists/learn-to-drive-a-car.json +0 -261
- data/lib/govuk_navigation_helpers/current_tasklist_ab_test.rb +0 -65
- data/lib/govuk_navigation_helpers/tasklist_content.rb +0 -118
- data/spec/current_tasklist_ab_test_spec.rb +0 -64
@@ -1,261 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"title": "Learn to drive a car: step by step",
|
3
|
-
"base_path": "/learn-to-drive-a-car",
|
4
|
-
"description": "<p>Check what you need to do to learn to drive.</p>",
|
5
|
-
"links": {
|
6
|
-
"breadcrumbs": [
|
7
|
-
{ "title": "Home", "url": "/" },
|
8
|
-
{ "title": "Driving and transport", "url": "/browse/driving"},
|
9
|
-
{ "title": "Learning to drive", "url": "/browse/driving/learning-to-drive"}
|
10
|
-
]
|
11
|
-
},
|
12
|
-
"ab_test_prefix": "",
|
13
|
-
"related_paths": [
|
14
|
-
"/apply-for-your-full-driving-licence",
|
15
|
-
"/automatic-driving-licence-to-manual",
|
16
|
-
"/complain-about-a-driving-instructor",
|
17
|
-
"/driving-licence-fees",
|
18
|
-
"/driving-test-cost",
|
19
|
-
"/dvlaforms",
|
20
|
-
"/find-theory-test-pass-number",
|
21
|
-
"/government/publications/application-for-refunding-out-of-pocket-expenses",
|
22
|
-
"/government/publications/drivers-record-for-learner-drivers",
|
23
|
-
"/government/publications/driving-instructor-grades-explained",
|
24
|
-
"/government/publications/know-your-traffic-signs",
|
25
|
-
"/government/publications/l-plate-size-rules",
|
26
|
-
"/guidance/rules-for-observing-driving-tests",
|
27
|
-
"/report-an-illegal-driving-instructor",
|
28
|
-
"/report-driving-test-impersonation",
|
29
|
-
"/track-your-driving-licence-application",
|
30
|
-
"/driving-lessons-learning-to-drive/practising-with-family-or-friends",
|
31
|
-
"/driving-lessons-learning-to-drive/taking-driving-lessons",
|
32
|
-
"/driving-lessons-learning-to-drive/using-l-and-p-plates",
|
33
|
-
"/driving-test",
|
34
|
-
"/driving-test/changes-december-2017",
|
35
|
-
"/driving-test/disability-health-condition-or-learning-difficulty",
|
36
|
-
"/driving-test/driving-test-faults-result",
|
37
|
-
"/driving-test/test-cancelled-bad-weather",
|
38
|
-
"/driving-test/using-your-own-car",
|
39
|
-
"/driving-test/what-happens-during-test",
|
40
|
-
"/pass-plus/apply-for-a-pass-plus-certificate",
|
41
|
-
"/pass-plus/booking-pass-plus",
|
42
|
-
"/pass-plus/car-insurance-discounts",
|
43
|
-
"/pass-plus/local-councils-offering-discounts",
|
44
|
-
"/pass-plus/how-pass-plus-training-works",
|
45
|
-
"/theory-test",
|
46
|
-
"/theory-test/hazard-perception-test",
|
47
|
-
"/theory-test/if-you-have-safe-road-user-award",
|
48
|
-
"/theory-test/multiple-choice-questions",
|
49
|
-
"/theory-test/pass-mark-and-result",
|
50
|
-
"/theory-test/reading-difficulty-disability-or-health-condition"
|
51
|
-
],
|
52
|
-
"tasklist": {
|
53
|
-
"groups": [
|
54
|
-
[
|
55
|
-
{
|
56
|
-
"title": "Check you're allowed to drive",
|
57
|
-
"contents": [
|
58
|
-
{
|
59
|
-
"type": "paragraph",
|
60
|
-
"text": "Most people can start learning to drive when they’re 17."
|
61
|
-
},
|
62
|
-
{
|
63
|
-
"type": "list",
|
64
|
-
"style": "required",
|
65
|
-
"contents": [
|
66
|
-
{
|
67
|
-
"href": "/vehicles-can-drive",
|
68
|
-
"text": "Check what age you can drive"
|
69
|
-
},
|
70
|
-
{
|
71
|
-
"href": "/legal-obligations-drivers-riders",
|
72
|
-
"text": "Requirements for driving legally"
|
73
|
-
},
|
74
|
-
{
|
75
|
-
"href": "/driving-eyesight-rules",
|
76
|
-
"text": "Driving eyesight rules"
|
77
|
-
}
|
78
|
-
]
|
79
|
-
}
|
80
|
-
]
|
81
|
-
}
|
82
|
-
],
|
83
|
-
[
|
84
|
-
{
|
85
|
-
"title": "Get a provisional driving licence",
|
86
|
-
"contents": [
|
87
|
-
{
|
88
|
-
"type": "list",
|
89
|
-
"style": "required",
|
90
|
-
"contents": [
|
91
|
-
{
|
92
|
-
"href": "/apply-first-provisional-driving-licence",
|
93
|
-
"text": "Apply for your first provisional driving licence",
|
94
|
-
"context": "£34"
|
95
|
-
}
|
96
|
-
]
|
97
|
-
}
|
98
|
-
]
|
99
|
-
}
|
100
|
-
],
|
101
|
-
[
|
102
|
-
{
|
103
|
-
"title": "Driving lessons and practice",
|
104
|
-
"contents": [
|
105
|
-
{
|
106
|
-
"type": "paragraph",
|
107
|
-
"text": "You need a provisional driving licence to take lessons or practice."
|
108
|
-
},
|
109
|
-
{
|
110
|
-
"type": "list",
|
111
|
-
"style": "required",
|
112
|
-
"contents": [
|
113
|
-
{
|
114
|
-
"href": "/guidance/the-highway-code",
|
115
|
-
"text": "The Highway Code"
|
116
|
-
},
|
117
|
-
{
|
118
|
-
"href": "/driving-lessons-learning-to-drive",
|
119
|
-
"text": "Taking driving lessons"
|
120
|
-
},
|
121
|
-
{
|
122
|
-
"href": "/find-driving-schools-and-lessons",
|
123
|
-
"text": "Find driving schools, lessons and instructors"
|
124
|
-
},
|
125
|
-
{
|
126
|
-
"href": "/government/publications/car-show-me-tell-me-vehicle-safety-questions",
|
127
|
-
"text": "Practise vehicle safety questions"
|
128
|
-
}
|
129
|
-
]
|
130
|
-
}
|
131
|
-
]
|
132
|
-
},
|
133
|
-
{
|
134
|
-
"title": "Prepare for your theory test",
|
135
|
-
"contents": [
|
136
|
-
{
|
137
|
-
"type": "list",
|
138
|
-
"style": "required",
|
139
|
-
"contents": [
|
140
|
-
{
|
141
|
-
"href": "/theory-test/revision-and-practice",
|
142
|
-
"text": "Theory test revision and practice"
|
143
|
-
},
|
144
|
-
{
|
145
|
-
"href": "/take-practice-theory-test",
|
146
|
-
"text": "Take a practice theory test"
|
147
|
-
},
|
148
|
-
{
|
149
|
-
"href": "https://www.safedrivingforlife.info/shop/product/official-dvsa-theory-test-kit-app-app",
|
150
|
-
"text": "Theory and hazard perception test app"
|
151
|
-
}
|
152
|
-
]
|
153
|
-
}
|
154
|
-
]
|
155
|
-
}
|
156
|
-
],
|
157
|
-
[
|
158
|
-
{
|
159
|
-
"title": "Book and manage your theory test",
|
160
|
-
"contents": [
|
161
|
-
{
|
162
|
-
"type": "paragraph",
|
163
|
-
"text": "You need a provisional driving licence to book your theory test."
|
164
|
-
},
|
165
|
-
{
|
166
|
-
"type": "list",
|
167
|
-
"style": "required",
|
168
|
-
"contents": [
|
169
|
-
{
|
170
|
-
"href": "/book-theory-test",
|
171
|
-
"text": "Book your theory test",
|
172
|
-
"context": "£23"
|
173
|
-
},
|
174
|
-
{
|
175
|
-
"href": "/theory-test/what-to-take",
|
176
|
-
"text": "What to take to your test"
|
177
|
-
},
|
178
|
-
{
|
179
|
-
"href": "/change-theory-test",
|
180
|
-
"text": "Change your theory test appointment"
|
181
|
-
},
|
182
|
-
{
|
183
|
-
"href": "/check-theory-test",
|
184
|
-
"text": "Check your theory test appointment details"
|
185
|
-
},
|
186
|
-
{
|
187
|
-
"href": "/cancel-theory-test",
|
188
|
-
"text": "Cancel your theory test"
|
189
|
-
}
|
190
|
-
]
|
191
|
-
}
|
192
|
-
]
|
193
|
-
}
|
194
|
-
],
|
195
|
-
[
|
196
|
-
{
|
197
|
-
"title": "Book and manage your driving test",
|
198
|
-
"contents": [
|
199
|
-
{
|
200
|
-
"type": "paragraph",
|
201
|
-
"text": "You must pass your theory test before you can book your driving test."
|
202
|
-
},
|
203
|
-
{
|
204
|
-
"type": "list",
|
205
|
-
"style": "required",
|
206
|
-
"contents": [
|
207
|
-
{
|
208
|
-
"href": "/book-driving-test",
|
209
|
-
"text": "Book your driving test",
|
210
|
-
"context": "£62"
|
211
|
-
},
|
212
|
-
{
|
213
|
-
"href": "/driving-test/what-to-take",
|
214
|
-
"text": "What to take to your test"
|
215
|
-
},
|
216
|
-
{
|
217
|
-
"href": "/change-driving-test",
|
218
|
-
"text": "Change your driving test appointment"
|
219
|
-
},
|
220
|
-
{
|
221
|
-
"href": "/check-driving-test",
|
222
|
-
"text": "Check your driving test appointment details"
|
223
|
-
},
|
224
|
-
{
|
225
|
-
"href": "/cancel-driving-test",
|
226
|
-
"text": "Cancel your driving test"
|
227
|
-
}
|
228
|
-
]
|
229
|
-
}
|
230
|
-
]
|
231
|
-
}
|
232
|
-
],
|
233
|
-
[
|
234
|
-
{
|
235
|
-
"title": "When you pass",
|
236
|
-
"contents": [
|
237
|
-
{
|
238
|
-
"type": "paragraph",
|
239
|
-
"text": "You can start driving as soon as you pass your driving test."
|
240
|
-
},
|
241
|
-
{
|
242
|
-
"type": "paragraph",
|
243
|
-
"text": "You must have an insurance policy that allows you to drive without supervision."
|
244
|
-
},
|
245
|
-
{
|
246
|
-
"type": "list",
|
247
|
-
"style": "required",
|
248
|
-
"style": "required",
|
249
|
-
"contents": [
|
250
|
-
{
|
251
|
-
"href": "/pass-plus",
|
252
|
-
"text": "Find out about Pass Plus training courses"
|
253
|
-
}
|
254
|
-
]
|
255
|
-
}
|
256
|
-
]
|
257
|
-
}
|
258
|
-
]
|
259
|
-
]
|
260
|
-
}
|
261
|
-
}
|
@@ -1,65 +0,0 @@
|
|
1
|
-
module GovukNavigationHelpers
|
2
|
-
class CurrentTasklistAbTest
|
3
|
-
TASKLIST_HEADER_DIMENSION = 44
|
4
|
-
TASKLIST_SIDEBAR_DIMENSION = 66
|
5
|
-
|
6
|
-
def initialize(current_tasklist:, request:)
|
7
|
-
@current_tasklist = current_tasklist
|
8
|
-
@ab_test_prefix = current_tasklist.ab_test_prefix if current_tasklist
|
9
|
-
@request = request
|
10
|
-
end
|
11
|
-
|
12
|
-
def eligible?
|
13
|
-
!! current_tasklist
|
14
|
-
end
|
15
|
-
|
16
|
-
def header
|
17
|
-
@header ||= set_ab_test(
|
18
|
-
name: "#{ab_test_prefix}TaskListHeader",
|
19
|
-
dimension: TASKLIST_HEADER_DIMENSION
|
20
|
-
)
|
21
|
-
end
|
22
|
-
|
23
|
-
def sidebar
|
24
|
-
@sidebar ||= set_ab_test(
|
25
|
-
name: "#{ab_test_prefix}TaskListSidebar",
|
26
|
-
dimension: TASKLIST_SIDEBAR_DIMENSION
|
27
|
-
)
|
28
|
-
end
|
29
|
-
|
30
|
-
def sidebar_variant
|
31
|
-
@sidebar_variant ||=
|
32
|
-
sidebar.requested_variant(request.headers)
|
33
|
-
end
|
34
|
-
|
35
|
-
def header_variant
|
36
|
-
@header_variant ||=
|
37
|
-
header.requested_variant(request.headers)
|
38
|
-
end
|
39
|
-
|
40
|
-
def show_tasklist_sidebar?
|
41
|
-
sidebar_variant.variant?('B') && is_tested_page?
|
42
|
-
end
|
43
|
-
|
44
|
-
def show_tasklist_header?
|
45
|
-
header_variant.variant?('B') && is_tested_page?
|
46
|
-
end
|
47
|
-
|
48
|
-
def is_tested_page?
|
49
|
-
return current_tasklist.is_page_included_in_ab_test? if current_tasklist
|
50
|
-
end
|
51
|
-
|
52
|
-
def set_response_header(response)
|
53
|
-
sidebar_variant.configure_response(response) if is_tested_page?
|
54
|
-
header_variant.configure_response(response) if is_tested_page?
|
55
|
-
end
|
56
|
-
|
57
|
-
private
|
58
|
-
|
59
|
-
attr_reader :current_tasklist, :ab_test_prefix, :request
|
60
|
-
|
61
|
-
def set_ab_test(name:, dimension:)
|
62
|
-
GovukAbTesting::AbTest.new(name, dimension: dimension)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
@@ -1,118 +0,0 @@
|
|
1
|
-
module GovukNavigationHelpers
|
2
|
-
class TasklistContent
|
3
|
-
TASKLIST_NAMES = %w(
|
4
|
-
learn-to-drive-a-car
|
5
|
-
).freeze
|
6
|
-
|
7
|
-
def self.current_tasklist(path)
|
8
|
-
TASKLIST_NAMES.each do |tasklist_name|
|
9
|
-
tasklist = new(file_name: tasklist_name, path: path)
|
10
|
-
return tasklist if tasklist.current?
|
11
|
-
end
|
12
|
-
nil
|
13
|
-
end
|
14
|
-
|
15
|
-
def initialize(file_name: nil, path: nil)
|
16
|
-
@file_name = file_name
|
17
|
-
@path = path
|
18
|
-
end
|
19
|
-
|
20
|
-
def title
|
21
|
-
parsed_file.dig(:title)
|
22
|
-
end
|
23
|
-
|
24
|
-
def base_path
|
25
|
-
parsed_file.dig(:base_path)
|
26
|
-
end
|
27
|
-
|
28
|
-
def tasklist
|
29
|
-
parsed_file.dig(:tasklist)
|
30
|
-
end
|
31
|
-
|
32
|
-
def ab_test_prefix
|
33
|
-
parsed_file.dig(:ab_test_prefix)
|
34
|
-
end
|
35
|
-
|
36
|
-
def skip_link
|
37
|
-
"##{groups.flatten.first[:title].downcase.tr(' ', '-')}"
|
38
|
-
end
|
39
|
-
|
40
|
-
def primary_paths
|
41
|
-
primary_content.map { |content|
|
42
|
-
content[:href] unless content[:href].start_with?('http')
|
43
|
-
}.select(&:present?)
|
44
|
-
end
|
45
|
-
|
46
|
-
def groups
|
47
|
-
tasklist.dig(:groups)
|
48
|
-
end
|
49
|
-
|
50
|
-
def related_paths
|
51
|
-
parsed_file.dig(:related_paths)
|
52
|
-
end
|
53
|
-
|
54
|
-
def set_current_task
|
55
|
-
set_task_as_active_if_current_page
|
56
|
-
end
|
57
|
-
|
58
|
-
def is_page_included_in_ab_test?
|
59
|
-
primary_paths.include?(path) ||
|
60
|
-
related_paths.include?(path)
|
61
|
-
end
|
62
|
-
|
63
|
-
def current?
|
64
|
-
primary_paths.include?(path) ||
|
65
|
-
related_paths.include?(path)
|
66
|
-
end
|
67
|
-
|
68
|
-
private
|
69
|
-
|
70
|
-
attr_reader :file_name, :file, :path
|
71
|
-
|
72
|
-
def set_task_as_active_if_current_page
|
73
|
-
counter = 0
|
74
|
-
|
75
|
-
groups.each_with_index.each do |grouped_steps, group_index|
|
76
|
-
grouped_steps.each do |step|
|
77
|
-
counter += 1
|
78
|
-
|
79
|
-
step[:contents].each do |content|
|
80
|
-
next unless content[:contents]
|
81
|
-
|
82
|
-
content[:contents].each do |link|
|
83
|
-
if link[:href] == path
|
84
|
-
link[:active] = true
|
85
|
-
tasklist[:show_step] = counter
|
86
|
-
tasklist[:highlight_group] = group_index + 1
|
87
|
-
return tasklist
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
tasklist
|
95
|
-
end
|
96
|
-
|
97
|
-
def primary_content
|
98
|
-
primary_content = groups.flat_map do |grouped_steps|
|
99
|
-
grouped_steps.flat_map do |group|
|
100
|
-
group[:contents].select { |content| content[:contents] }
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
primary_content.flat_map { |hash| hash[:contents] }
|
105
|
-
end
|
106
|
-
|
107
|
-
def parsed_file
|
108
|
-
@parsed_file ||=
|
109
|
-
JSON.parse(
|
110
|
-
File.read(
|
111
|
-
File.join(File.dirname(__FILE__), "../../", "config", "tasklists", "#{file_name}.json")
|
112
|
-
)
|
113
|
-
).deep_symbolize_keys.tap do |json_file|
|
114
|
-
json_file[:tasklist].merge!(small: true, heading_level: 3)
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
@@ -1,64 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module GovukNavigationHelpers
|
4
|
-
RSpec.describe CurrentTasklistAbTest do
|
5
|
-
let(:tasklist) { TasklistContent.current_tasklist('/vehicles-can-drive') }
|
6
|
-
|
7
|
-
it "indicates when to show the task list components" do
|
8
|
-
request = double('request', headers: {
|
9
|
-
'HTTP_GOVUK_ABTEST_TASKLISTSIDEBAR' => 'B',
|
10
|
-
'HTTP_GOVUK_ABTEST_TASKLISTHEADER' => 'B'
|
11
|
-
})
|
12
|
-
ab_test = described_class.new(current_tasklist: tasklist, request: request)
|
13
|
-
expect(ab_test.show_tasklist_sidebar?).to be true
|
14
|
-
expect(ab_test.show_tasklist_header?).to be true
|
15
|
-
end
|
16
|
-
|
17
|
-
it "indicates when to not show the task list components" do
|
18
|
-
request = double('request', headers: {
|
19
|
-
'HTTP_GOVUK_ABTEST_TASKLISTSIDEBAR' => 'A',
|
20
|
-
'HTTP_GOVUK_ABTEST_TASKLISTHEADER' => 'A'
|
21
|
-
})
|
22
|
-
ab_test = described_class.new(current_tasklist: tasklist, request: request)
|
23
|
-
expect(ab_test.show_tasklist_sidebar?).to be false
|
24
|
-
expect(ab_test.show_tasklist_header?).to be false
|
25
|
-
end
|
26
|
-
|
27
|
-
it "copes with a mixture when to not show the task list components" do
|
28
|
-
request = double('request', headers: {
|
29
|
-
'HTTP_GOVUK_ABTEST_TASKLISTSIDEBAR' => 'B',
|
30
|
-
'HTTP_GOVUK_ABTEST_TASKLISTHEADER' => 'A'
|
31
|
-
})
|
32
|
-
ab_test = described_class.new(current_tasklist: tasklist, request: request)
|
33
|
-
expect(ab_test.show_tasklist_sidebar?).to be true
|
34
|
-
expect(ab_test.show_tasklist_header?).to be false
|
35
|
-
end
|
36
|
-
|
37
|
-
it "configures the response vary header correctly " do
|
38
|
-
request = double('request', headers: {
|
39
|
-
'HTTP_GOVUK_ABTEST_TASKLISTSIDEBAR' => 'A',
|
40
|
-
'HTTP_GOVUK_ABTEST_TASKLISTHEADER' => 'B'
|
41
|
-
})
|
42
|
-
response = double('response', headers: {})
|
43
|
-
ab_test = described_class.new(current_tasklist: tasklist, request: request)
|
44
|
-
|
45
|
-
ab_test.set_response_header(response)
|
46
|
-
|
47
|
-
expect(response.headers["Vary"]).to eq("GOVUK-ABTest-TaskListSidebar, GOVUK-ABTest-TaskListHeader")
|
48
|
-
end
|
49
|
-
|
50
|
-
it "configures the response vary header correctly when the page is not under test" do
|
51
|
-
request = double('request', headers: {
|
52
|
-
'HTTP_GOVUK_ABTEST_TASKLISTSIDEBAR' => 'A',
|
53
|
-
'HTTP_GOVUK_ABTEST_TASKLISTHEADER' => 'B'
|
54
|
-
})
|
55
|
-
response = double('response', headers: {})
|
56
|
-
tasklist = TasklistContent.current_tasklist("/not_under_test")
|
57
|
-
ab_test = described_class.new(current_tasklist: tasklist, request: request)
|
58
|
-
|
59
|
-
ab_test.set_response_header(response)
|
60
|
-
|
61
|
-
expect(response.headers["Vary"]).to be nil
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|