Skip to content

Commit ea1fbaf

Browse files
committed
fix up cucumber tests
1 parent e29e408 commit ea1fbaf

2 files changed

Lines changed: 31 additions & 49 deletions

File tree

app/views/admin/configurable_content_blocks/_default_array.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
heading_size: "l",
4444
id: path.form_control_id } do %>
4545
<%
46-
items = content[property_key].map.with_index do |element, index|
46+
items = (content[property_key] || []).map.with_index do |element, index|
4747
{
4848
fields: render_fields.call(element, index),
4949
destroy_checkbox: render_remove_checkbox.call(index),

features/step_definitions/standard_edition_steps.rb

Lines changed: 30 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ def create_configurable_document(title:, locale: "en", summary: nil, body: nil,
2323
end
2424
end
2525

26+
def default_block_content_for_locale(locale)
27+
default_content_for_locale(locale)
28+
.stringify_keys
29+
.except("title", "summary")
30+
end
31+
2632
def default_content_for_locale(locale)
2733
case locale
2834
when "cy"
@@ -33,7 +39,10 @@ def default_content_for_locale(locale)
3339
date_field: { "1" => "2025", "2" => "10", "3" => "2" },
3440
street: "Stryd Bakers",
3541
city: "Llundain",
36-
list_of_foods: %w[afal oren],
42+
list_of_foods: [
43+
{ food: "Afal" },
44+
{ food: "Oren" },
45+
],
3746
}
3847
else
3948
{
@@ -43,7 +52,10 @@ def default_content_for_locale(locale)
4352
date_field: { "1" => "2025", "2" => "10", "3" => "1" },
4453
street: "Bakers Street",
4554
city: "London",
46-
list_of_foods: %w[apple orange],
55+
list_of_foods: [
56+
{ food: "Apple" },
57+
{ food: "Orange" },
58+
],
4759
}
4860
end
4961
end
@@ -76,6 +88,7 @@ def default_content_for_locale(locale)
7688
fill_in "edition[block_content][date_field][1]", with: "2011"
7789
fill_in "edition[block_content][street]", with: "Bakers Street"
7890
fill_in "edition[block_content][city]", with: "London"
91+
fill_in "edition[block_content][list_of_foods][0][food]", with: "Apple"
7992
end
8093
click_button "Save and go to document summary"
8194
end
@@ -171,14 +184,7 @@ def default_content_for_locale(locale)
171184
configurable_document_type: "test",
172185
images: [image],
173186
title: title,
174-
block_content: {
175-
"image" => image.image_data.id.to_s,
176-
"body" => "Some text",
177-
"date_field" => { "1" => "2025", "2" => "10", "3" => "1" },
178-
"street" => "Bakers Street",
179-
"city" => "London",
180-
"list_of_foods" => %w[apple orange],
181-
},
187+
block_content: default_block_content_for_locale("en").merge("image" => image.image_data.id.to_s),
182188
},
183189
)
184190
stub_publishing_api_links_with_taxons(standard_edition.content_id, %w[a-taxon-content-id])
@@ -204,12 +210,13 @@ def default_content_for_locale(locale)
204210
visit admin_standard_edition_path(standard_edition)
205211
click_button "Create new edition"
206212

207-
expect(page).to have_field(name: "edition[block_content][body]", with: "Some text")
213+
expect(page).to have_field(name: "edition[block_content][body]", with: "## Some English govspeak. This is the English body content")
208214
expect(page).to have_field(name: "edition[block_content][date_field][3]", with: "1")
209215
expect(page).to have_field(name: "edition[block_content][date_field][2]", with: "10")
210216
expect(page).to have_field(name: "edition[block_content][date_field][1]", with: "2025")
211217
expect(page).to have_field(name: "edition[block_content][city]", with: "London")
212218
expect(page).to have_field(name: "edition[block_content][street]", with: "Bakers Street")
219+
expect(page).to have_field(name: "edition[block_content][list_of_foods][0][food]", with: "Apple")
213220

214221
click_link "Images"
215222
expect(page).to have_select("Image", selected: standard_edition.images.first.filename)
@@ -304,51 +311,33 @@ def default_content_for_locale(locale)
304311
end
305312

306313
Given(/^I have published an English document with a Welsh translation$/) do
307-
en_content = default_content_for_locale("en")
308314
@standard_edition = create(
309315
:published_standard_edition,
310316
{
311317
configurable_document_type: "test",
312-
title: en_content[:title],
313-
summary: en_content[:summary],
314-
block_content: {
315-
"body" => en_content[:body],
316-
"date_field" => en_content[:date_field],
317-
"street" => en_content[:street],
318-
"city" => en_content[:city],
319-
"list_of_foods" => en_content[:list_of_foods],
320-
},
318+
title: default_content_for_locale("en")[:title],
319+
summary: default_content_for_locale("en")[:summary],
320+
block_content: default_block_content_for_locale("en"),
321321
},
322322
)
323323
I18n.with_locale("cy") do
324-
cy_content = default_content_for_locale("cy")
325324
@standard_edition.translations.create!(
326325
locale: "cy",
327-
title: cy_content[:title],
328-
summary: cy_content[:summary],
329-
block_content: {
330-
"body" => cy_content[:body],
331-
"date_field" => cy_content[:date_field],
332-
"street" => cy_content[:street],
333-
"city" => cy_content[:city],
334-
"list_of_foods" => cy_content[:list_of_foods],
335-
},
326+
title: default_content_for_locale("cy")[:title],
327+
summary: default_content_for_locale("cy")[:summary],
328+
block_content: default_block_content_for_locale("cy"),
336329
)
337330
end
338331
end
339332

340333
Given(/^I have published a configurable document titled "([^"]*)"$/) do |title|
341-
en_content = default_content_for_locale("en")
342334
@standard_edition = create(
343335
:published_standard_edition,
344336
{
345337
configurable_document_type: "test",
346-
title: title || en_content[:title],
347-
summary: en_content[:summary],
348-
block_content: {
349-
"body" => en_content[:body],
350-
"date_field" => en_content[:date_field],
351-
},
338+
title: title || default_content_for_locale("en")[:title],
339+
summary: default_content_for_locale("en")[:summary],
340+
block_content: default_block_content_for_locale("en"),
352341
},
353342
)
354343
end
@@ -376,20 +365,13 @@ def default_content_for_locale(locale)
376365
end
377366

378367
And(/^I have created a new "(.+)" draft$/) do |document_type|
379-
content = default_content_for_locale("en")
380368
@standard_edition = create(
381369
:draft_standard_edition,
382370
{
383371
configurable_document_type: document_type,
384-
title: content[:title],
385-
summary: content[:summary],
386-
block_content: {
387-
"body" => content[:body],
388-
"date_field" => content[:date_field],
389-
"street" => content[:street],
390-
"city" => content[:city],
391-
"list_of_foods" => content[:list_of_foods],
392-
},
372+
title: default_content_for_locale("en")[:title],
373+
summary: default_content_for_locale("en")[:summary],
374+
block_content: default_block_content_for_locale("en"),
393375
},
394376
)
395377
end

0 commit comments

Comments
 (0)