-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathtravel_advice_spec.rb
More file actions
235 lines (172 loc) · 8.63 KB
/
Copy pathtravel_advice_spec.rb
File metadata and controls
235 lines (172 loc) · 8.63 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
RSpec.describe "TravelAdvice" do
let(:base_path) { content_store_response.fetch("base_path") }
before { stub_content_store_has_item(base_path, content_store_response) }
describe "GET /foreign-travel-advice" do
let(:content_store_response) { GovukSchemas::Example.find("travel_advice_index", example_name: "index") }
it "displays the list of countries" do
visit "/foreign-travel-advice"
expect(page.status_code).to eq(200)
within("head", visible: :all) do
expect(page).to have_selector("title", text: "Foreign travel advice", visible: :all)
expect(page).to have_selector("link[rel=alternate][type='application/atom+xml'][href='/foreign-travel-advice.atom']", visible: :all)
expect(page).to have_selector("meta[name=description][content='Latest travel advice by country including safety and security, entry requirements, travel warnings and health']", visible: :hidden)
end
within("#content") do
within(".gem-c-heading") do
expect(page).to have_content("Foreign travel advice")
end
expect(page).to have_selector("#country-filter")
names = page.all("ul.js-countries-list li a").map(&:text)
expect(names).to eq(["Afghanistan", "Austria", "Finland", "India", "Malaysia", "S\u00E3o Tom\u00E9 and Principe", "Spain"])
within(".list#A") do
expect(page).to have_link("Afghanistan", href: "/foreign-travel-advice/afghanistan")
end
within(".list#M") do
expect(page).to have_link("Malaysia", href: "/foreign-travel-advice/malaysia")
end
within(".list#S") do
expect(page).to have_link("Spain", href: "/foreign-travel-advice/spain")
end
end
group_headers = page.all(".list h2").map(&:text)
expect(group_headers).to eq(group_headers.sort)
end
it "has the correct titles" do
visit "/foreign-travel-advice"
expect(page).to have_title("Foreign travel advice")
expect(page.title).to eq("Foreign travel advice - GOV.UK")
end
it "displays breadcrumbs" do
visit "/foreign-travel-advice"
expect(page).to have_css(".gem-c-contextual-breadcrumbs")
end
context "with the javascript driver" do
before { Capybara.current_driver = Capybara.javascript_driver }
it "loads the page and performs filtering correctly" do
visit "/foreign-travel-advice"
expect(page).to have_content("Foreign travel advice")
page.execute_script("document.body.className = ((document.body.className) ? document.body.className + ' govuk-frontend-supported' : 'govuk-frontend-supported');")
expect(page).to have_selector("#country-filter")
within("#country-filter") { fill_in("country", with: "In") }
within(".countries-wrapper") do
expect(page).to have_selector("#I li")
expect(page).to have_selector("#F li")
expect(page).to have_selector("#S li")
expect(page).not_to have_selector("#A li")
expect(page).not_to have_selector("#M li")
end
within(".js-country-count") do
expect(page).to have_selector(".js-filter-count", text: "4")
end
end
end
end
describe "GET /foreign-travel-advice/<country>" do
let(:content_store_response) { GovukSchemas::Example.find("travel_advice", example_name: "full-country") }
it "displays the page" do
visit base_path
expect(page.status_code).to eq(200)
end
it "displays the title" do
visit base_path
expect(page).to have_title("#{content_store_response['details']['country']['name']} travel advice")
within(".travel-advice__header .gem-c-heading") do
expect(page).to have_content(content_store_response["details"]["country"]["name"])
end
end
it "displays the email sign-up link" do
visit base_path
expect(page).to have_css("a[href=\"#{content_store_response['details']['email_signup_link']}\"]", text: "Get email alerts")
end
it "displays the navigation" do
visit base_path
parts_size = content_store_response["details"]["parts"].size
expect(page).to have_css(".part-navigation-container nav li", count: parts_size)
expect(page).to have_css(".part-navigation-container nav li", text: content_store_response["details"]["parts"].first["title"])
expect(page).not_to have_css(".part-navigation li a", text: content_store_response["details"]["parts"].first["title"])
content_store_response["details"]["parts"][1..parts_size].each do |part|
expect(page).to have_css(".part-navigation-container nav li a[href*=\"#{part['slug']}\"]", text: part["title"])
end
expect(page).to have_css(".govuk-pagination")
expect(page).to have_css('.govuk-link.govuk-link--no-visited-state[href$="/print"]', text: I18n.t("multi_page.print_entire_guide"))
end
it "displays breadcrumbs" do
visit base_path
expect(page).to have_css(".gem-c-contextual-breadcrumbs")
end
describe "first part" do
it "displays latest updates" do
visit base_path
expect(page).to have_css("h1", text: content_store_response["details"]["parts"].first["title"])
expect(page).to have_text("The main opposition party has called for mass protests against the government in Tirana on 18 February 2017.")
expect(page).to have_content(I18n.t("formats.travel_advice.still_current_at"))
expect(page).to have_content(Time.zone.today.strftime("%-d %B %Y"))
expect(page).to have_content(I18n.t("formats.travel_advice.updated"))
expect(page).to have_content(Date.parse(content_store_response["details"]["reviewed_at"]).strftime("%-d %B %Y"))
within ".gem-c-metadata" do
expect(page).to have_content(content_store_response["details"]["change_description"].gsub("Latest update: ", "").strip)
end
end
context "when there is no reviewed_at date" do
let(:content_store_response) do
response = GovukSchemas::Example.find("travel_advice", example_name: "full-country")
response["details"].delete("reviewed_at")
response
end
it "displays the updated_at date" do
visit base_path
expect(page).to have_content(Date.parse(content_store_response["details"]["updated_at"]).strftime("%-d %B %Y"))
end
end
context "with map download" do
let(:content_store_response) do
response = GovukSchemas::Example.find("travel_advice", example_name: "full-country")
response["details"]["document"]["file_size"] = 201_672
response
end
it "displays the map" do
visit base_path
expect(page).to have_css(".map img[src=\"#{content_store_response['details']['image']['url']}\"]")
expect(page).to have_css(".map figcaption a[href=\"#{content_store_response['details']['document']['url']}\"]", text: "Download a more detailed map (PDF, 197 KB)")
end
end
end
describe "other parts" do
let(:part) { content_store_response.dig("details", "parts").last }
it "only renders one part" do
visit "#{base_path}/#{part['slug']}"
expect(page).to have_title("#{part['title']} - #{content_store_response['title']} - GOV.UK")
expect(page).to have_css("h1", text: part["title"])
expect(page).to have_text("If you’re abroad and you need emergency help from the UK government, contact the nearest British embassy, consulate or high commission")
end
it "does not display a map" do
visit "#{base_path}/#{part['slug']}"
expect(page).not_to have_css(".map")
expect(page).not_to have_css(".gem-c-metadata")
end
it "does not display navigation links for the part" do
visit "#{base_path}/#{part['slug']}"
expect(page).to have_css(".part-navigation-container nav li", text: part["title"])
expect(page).not_to have_css(".part-navigation-container nav li a", text: part["title"])
end
end
it "includes a discoverable atom feed link" do
visit base_path
expect(page).to have_css("link[type*='atom'][href='#{base_path}.atom']", visible: :hidden)
end
it "does not render with the single page notification button" do
visit base_path
expect(page).not_to have_css(".gem-c-single-page-notification-button")
end
it "has GA4 tracking on the print link" do
visit base_path
expected_ga4_json = {
event_name: "navigation",
type: "print page",
section: "Footer",
text: "View a printable version of the whole guide",
}.to_json
expect(page).to have_css("a[data-ga4-link='#{expected_ga4_json}']")
end
end
end