Skip to content

Commit b32f96e

Browse files
committed
Handle none of the above for show live pages
When a route uses the none_of_the_above option as its trigger, we need to display "None of the above" rather than just using the answer_value for the condition.
1 parent fa563cc commit b32f96e

3 files changed

Lines changed: 29 additions & 3 deletions

File tree

app/services/step_summary_card_service.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,14 +236,14 @@ def print_routes(conditions)
236236
caption = content_tag(:p, I18n.t("page_conditions.go_to_page", goto_page_question_number:, goto_page_question_text:), class: "govuk-body-s")
237237
end
238238

239-
answer_values = condition_group.map { |condition| "‘#{ActionController::Base.helpers.sanitize(condition.answer_value)}’" }
239+
answer_values = condition_group.map { |condition| "‘#{format_answer_value(condition.answer_value)}’" }
240240
formatted_list = html_unordered_list2(answer_values)
241241
safe_join([caption, formatted_list])
242242
}.join.html_safe
243243
end
244244

245245
def print_route(condition)
246-
answer_value = ActionController::Base.helpers.sanitize(condition.answer_value)
246+
answer_value = format_answer_value(condition.answer_value)
247247

248248
if condition.skip_to_end && condition.secondary_skip?
249249
I18n.t("page_conditions.condition_compact_html_secondary_skip_to_end_of_form")
@@ -266,6 +266,11 @@ def print_route(condition)
266266
end
267267
end
268268

269+
def format_answer_value(answer_value)
270+
answer_value = I18n.t("page_conditions.none_of_the_above") if answer_value == "none_of_the_above"
271+
ActionController::Base.helpers.sanitize(answer_value)
272+
end
273+
269274
def html_ordered_list(list_items)
270275
content_tag(:ol, html_list_item(list_items), class: ["govuk-list", "govuk-list--number"])
271276
end

spec/services/step_summary_card_service_spec.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,27 @@
304304
end
305305
end
306306

307+
context "with a single condition with none of the above as the trigger" do
308+
let(:goto_page) { form.pages.third }
309+
310+
before do
311+
page.update(is_optional: true)
312+
create :condition, routing_page_id: page.id, check_page_id: page.id, goto_page_id: goto_page.id, answer_value: "none_of_the_above"
313+
314+
page.reload
315+
form.reload.make_live!
316+
end
317+
318+
it "returns the correct options" do
319+
expect(step_summary_card_service.all_options_for_answer_type).to include(
320+
{
321+
key: { text: I18n.t("page_conditions.route") },
322+
value: { text: I18n.t("page_conditions.condition_compact_html", answer_value: "None of the above", goto_page_question_number: goto_page.position, goto_page_question_text: goto_page.question_text) },
323+
},
324+
)
325+
end
326+
end
327+
307328
context "with multiple conditions" do
308329
let(:first_goto_page) { form.pages.third }
309330
let(:second_goto_page) { form.pages.fourth }

spec/views/forms/_made_live_form_pages.html.erb_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
welsh_form_document:,
1414
status:,
1515
show_form_path:,
16-
current_form: form
16+
current_form: form,
1717
})
1818
end
1919

0 commit comments

Comments
 (0)