Skip to content

Commit 2d75ade

Browse files
authored
Merge pull request #2774 from govuk-forms/update-add-edit-routes-content
Update add edit routes content
2 parents aa302f8 + 1f12886 commit 2d75ade

6 files changed

Lines changed: 202 additions & 89 deletions

File tree

app/components/page_list_component/view.html.erb

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,23 @@
3535
<% if FeatureService.new(group: @form.group).enabled?(:multiple_branches) && page.routing_conditions.present? %>
3636
<div class="govuk-summary-list__row">
3737
<dt class="govuk-summary-list__key app-page-list__key">
38-
<%= t("page_conditions.condition_name", question_number: page.position) %>
38+
<%= t("page_conditions.condition_list_key", count: page.routing_conditions.count, question_number: page.position) %>
3939
</dt>
4040
<dd class="govuk-summary-list__value">
4141
<% if page.routing_conditions.first.answer_value.present? %>
42-
<p><%= I18n.t("page_conditions.if_answer_is") %></p>
43-
<ul class="govuk-list govuk-list--bullet">
44-
<% page.routing_conditions.each do |condition| %>
45-
<li>
46-
<%= condition_description2(condition) %>
47-
</li>
48-
<% end %>
49-
</ul>
42+
<% answer_value_groups(page).each do |_, group| %>
43+
<p><%= condition_group_description(group) %></p>
44+
<ul class="govuk-list govuk-list--bullet">
45+
<% group.each do |condition| %>
46+
<li>
47+
<%= answer_value_text_for_condition2(condition) %>
48+
</li>
49+
<% end %>
50+
</ul>
51+
<% end %>
5052
<% else %>
5153
<p>
52-
<%= condition_description2(page.routing_conditions.first) %>
54+
<%= unconditional_description(page.routing_conditions.first) %>
5355
</p>
5456
<% end %>
5557
<dd class="govuk-summary-list__actions govuk-!-padding-bottom-6">

app/components/page_list_component/view.rb

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,21 @@ def condition_description(condition)
2828
end
2929
end
3030

31-
def condition_description2(condition)
32-
if condition.answer_value.present?
33-
I18n.t("page_conditions.condition_description2", goto_page_question_text: goto_page_text_for_condition(condition), answer_value: answer_value_text_for_condition(condition))
31+
def unconditional_description(condition)
32+
if condition.goto_page_id.present?
33+
goto_page = @pages.find { |page| page.id == condition.goto_page_id }
34+
I18n.t("page_conditions.unconditional_goto_page_text", goto_page_question_number: goto_page.position, goto_page_question_text: goto_page.question_text)
35+
elsif condition.skip_to_end
36+
I18n.t("page_conditions.unconditional_skip_to_end_text")
37+
end
38+
end
39+
40+
def condition_group_description(group)
41+
if group.first.skip_to_end
42+
I18n.t("page_conditions.condition_group_description_end_of_form")
3443
else
35-
I18n.t("page_conditions.unconditional_description", goto_page_question_text: goto_page_text_for_condition(condition))
44+
goto_page = @pages.find { |page| page.id == group.first.goto_page_id }
45+
I18n.t("page_conditions.condition_group_description", goto_page_question_text: goto_page.question_text, goto_page_question_number: goto_page.position)
3646
end
3747
end
3848

@@ -50,6 +60,15 @@ def answer_value_text_for_condition(condition)
5060
end
5161
end
5262

63+
def answer_value_text_for_condition2(condition)
64+
if condition.answer_value.present?
65+
answer_value = condition.answer_value == :none_of_the_above.to_s ? I18n.t("page_conditions.none_of_the_above") : condition.answer_value
66+
I18n.t("page_conditions.condition_answer_value_text2", answer_value:)
67+
else
68+
I18n.t("page_conditions.condition_answer_value_text_with_errors")
69+
end
70+
end
71+
5372
def goto_page_text_for_condition(condition)
5473
if condition.goto_page_id.present?
5574
goto_page = @pages.find { |page| page.id == condition.goto_page_id }
@@ -80,5 +99,9 @@ def skip_condition_route_page_text(condition)
8099
routing_page = @pages.find { |page| page.id == condition.routing_page_id }
81100
I18n.t("page_conditions.skip_condition_route_page_text", route_page_question_text: routing_page.question_text, route_page_question_number: routing_page.position)
82101
end
102+
103+
def answer_value_groups(page)
104+
page.routing_conditions.group_by(&:goto_page_id).sort_by { |goto_page_id, _| goto_page_id || Float::INFINITY }
105+
end
83106
end
84107
end

config/locales/en.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,6 +1360,7 @@ en:
13601360
title: Page not found
13611361
page_conditions:
13621362
condition_answer_value_text: "“%{answer_value}”"
1363+
condition_answer_value_text2: "‘%{answer_value}’"
13631364
condition_answer_value_text_with_errors: "[Answer not selected]"
13641365
condition_check_page_text: "“%{check_page_question_text}”"
13651366
condition_compact_html: If the answer is “%{answer_value}” go to %{goto_page_question_number}, “%{goto_page_question_text}”
@@ -1368,22 +1369,26 @@ en:
13681369
condition_compact_html_secondary_skip: Go to %{goto_page_question_number}, “%{goto_page_question_text}”
13691370
condition_compact_html_secondary_skip_to_end_of_form: Go to end of form
13701371
condition_description: If %{check_page_question_text} is answered as %{answer_value} go to %{goto_page_question_text}
1371-
condition_description2: "%{answer_value} go to %{goto_page_question_text}"
13721372
condition_goto_exit_page: exit page, “%{exit_page_heading}”
13731373
condition_goto_page_end_of_form: end of form.
13741374
condition_goto_page_text: "%{goto_page_question_number}, “%{goto_page_question_text}”"
13751375
condition_goto_page_text_with_errors: "[Question not selected]"
1376+
condition_group_description: 'Go to %{goto_page_question_number}, ‘%{goto_page_question_text}’ if the answer is:'
1377+
condition_group_description_end_of_form: 'Go to the end of the form if the answer is:'
1378+
condition_list_key:
1379+
one: Question %{question_number}’s route
1380+
other: Question %{question_number}’s routes
13761381
condition_name: Question %{question_number}’s routes
13771382
edit_exit_page: Edit “%{exit_page_heading}”
13781383
end_of_form: End of form
13791384
exit_page: Add an exit page
13801385
exit_page_label: An ‘exit page’ to leave the form
1381-
if_answer_is: 'If the answer is:'
13821386
none_of_the_above: None of the above
13831387
route: Route
13841388
secondary_skip_description: After %{check_page_question_text} go to %{goto_page_question_text}
13851389
skip_condition_route_page_text: "%{route_page_question_number}, “%{route_page_question_text}”"
1386-
unconditional_description: Go to %{goto_page_question_text}
1390+
unconditional_goto_page_text: Go to %{goto_page_question_number}, ‘%{goto_page_question_text}’
1391+
unconditional_skip_to_end_text: Go to the end of the form
13871392
page_route_card:
13881393
any_other_answer: Route for any other answer
13891394
conditional_answer_value: "%{answer_value}"

db/seeds.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@
128128
# create some test groups
129129
end_to_end_group = Group.create! name: "End to end tests", organisation: gds, status: :active
130130
test_group = Group.create! name: "Test Group", organisation: gds, creator: default_user, status: :active
131+
multiple_branches_test_group = Group.create! name: "Test Group with multiple branches", organisation: gds, creator: default_user, status: :active, multiple_branches_enabled: true
131132
Group.create! name: "Ministry of Tests forms", organisation: mot_org
132133
Group.create! name: "Ministry of Tests forms - secret!", organisation: mot_org, creator: mot_user
133134

@@ -583,5 +584,5 @@
583584
GroupForm.create! group: test_group, form_id: branch_route_form.id # Branch routing form
584585
GroupForm.create! group: test_group, form_id: none_of_the_above_form.id # None of the above form
585586
GroupForm.create! group: test_group, form_id: welsh_form.id # Welsh form
586-
GroupForm.create! group: test_group, form_id: multiple_branch_form.id
587+
GroupForm.create! group: multiple_branches_test_group, form_id: multiple_branch_form.id
587588
end

spec/components/page_list_component/page_list_component_preview.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ def with_multiple_branches
9696
(build :page, id: 2, position: 2, question_text: "What is your pet's phone number?", routing_conditions: routing_conditions_2),
9797
(build :page, id: 3, position: 3, question_text: "How many pets do you own?", routing_conditions: []),
9898
(build :page, id: 4, position: 4, question_text: "What kind of pet do you want?", routing_conditions: []),
99+
(build :page, id: 5, position: 5, question_text: "What is your favourite colour?", routing_conditions: []),
99100
]
100101

101102
form = build(:form, :with_group, id: 1, pages:)

0 commit comments

Comments
 (0)