Skip to content

Commit 859f86f

Browse files
authored
Merge pull request #2758 from govuk-forms/add-edit-routes-link-for-each-route-in-question-list
Add edit link to multiple branches question page
2 parents bceb5bc + 2c45a3b commit 859f86f

5 files changed

Lines changed: 78 additions & 1 deletion

File tree

app/components/page_list_component/view.html.erb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@
5252
<%= condition_description2(page.routing_conditions.first) %>
5353
</p>
5454
<% end %>
55+
<dd class="govuk-summary-list__actions govuk-!-padding-bottom-6">
56+
<%= govuk_link_to routes_path(form_id: @form.id, anchor: page.page_position_id) do %>
57+
<%= t("forms.form_overview.edit_with_visually_hidden_text_html", visually_hidden_text: t("page_conditions.condition_name", question_number: page.position)) %>
58+
<% end %>
59+
</dd>
5560
</dd>
5661
</div>
5762
<% else %>

app/models/page.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ def normalise_welsh!
133133
routing_conditions.each(&:normalise_welsh!)
134134
end
135135

136+
def page_position_id
137+
"page-#{position}"
138+
end
139+
136140
private
137141

138142
def guidance_fields_presence

app/views/routes/show.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
@routes_input.routes.group_by(&:page).each do |page, routes|
2020
summary_list.with_row do |row|
21-
row.with_key(classes: "app-routes-list__key", html_attributes: { id: "page-#{page.position}"}) { page.position.to_s }
21+
row.with_key(classes: "app-routes-list__key", html_attributes: { id: page.page_position_id}) { page.position.to_s }
2222
row.with_value do
2323
capture do %>
2424
<p> <%= page.question_text %> </p>

spec/components/page_list_component/view_spec.rb

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,68 @@
182182
end
183183
end
184184

185+
describe "rendering component with multiple branches feature", :feature_multiple_branches do
186+
context "when the form has multiple pages" do
187+
let(:form) { create :form, :ready_for_routing }
188+
let(:first_page) { form.pages.first }
189+
let(:third_page) { form.pages.third }
190+
let(:fourth_page) { form.pages.fourth }
191+
192+
context "when the page has a single condition" do
193+
let!(:condition) { create :condition, routing_page_id: first_page.id, answer_value: "Option 1", goto_page_id: third_page.id }
194+
195+
before do
196+
render_inline(page_list_component)
197+
end
198+
199+
it "renders the condition description" do
200+
condition_description = "If the answer is:"
201+
condition_detail = "“#{condition.answer_value}” go to #{third_page.position}, “#{third_page.question_text}”"
202+
203+
expect(page).to have_css("dd.govuk-summary-list__value", text: condition_description)
204+
expect(page).to have_css("dd.govuk-summary-list__value", text: condition_detail)
205+
end
206+
207+
it "renders link" do
208+
expect(page).to have_link("Edit", href: routes_path(form_id: form.id, anchor: "page-#{first_page.position}"))
209+
end
210+
end
211+
212+
context "when the page has branching conditions" do
213+
let!(:first_condition) { create :condition, routing_page_id: first_page.id, answer_value: "Option 1", goto_page_id: third_page.id }
214+
let!(:second_condition) { create :condition, routing_page_id: first_page.id, answer_value: "Option 2", goto_page_id: fourth_page.id }
215+
216+
before do
217+
render_inline(page_list_component)
218+
end
219+
220+
it "renders the condition description" do
221+
condition_description = "If the answer is:"
222+
first_condition_detail = "“#{first_condition.answer_value}” go to #{third_page.position}, “#{third_page.question_text}”"
223+
second_condition_detail = "“#{second_condition.answer_value}” go to #{fourth_page.position}, “#{fourth_page.question_text}”"
224+
225+
expect(page).to have_css("dd.govuk-summary-list__value", text: condition_description)
226+
expect(page).to have_css("dd.govuk-summary-list__value", text: first_condition_detail)
227+
expect(page).to have_css("dd.govuk-summary-list__value", text: second_condition_detail)
228+
end
229+
end
230+
231+
context "when the page has an unconditional route" do
232+
before do
233+
create :condition, routing_page_id: first_page.id, goto_page_id: third_page.id
234+
235+
render_inline(page_list_component)
236+
end
237+
238+
it "renders the condition description" do
239+
unconditional_route_description = "Go to #{third_page.position}, “#{third_page.question_text}”"
240+
241+
expect(page).to have_css("dd.govuk-summary-list__value", text: unconditional_route_description)
242+
end
243+
end
244+
end
245+
end
246+
185247
describe "class methods", feature_multiple_branches: false do
186248
let(:form) { create :form, :with_pages }
187249

spec/models/page_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -872,4 +872,10 @@
872872
end
873873
end
874874
end
875+
876+
describe "#page_position_id" do
877+
it "returns a string for the page position id" do
878+
expect(page.page_position_id).to eq "page-#{page.position}"
879+
end
880+
end
875881
end

0 commit comments

Comments
 (0)