Skip to content

Commit 8f36326

Browse files
committed
Add message to routes#show when not enough pages
Instead of showing the routes form when there are not enough pages, show a warning and a link to the question pages. We show the message when there is 0 or 1 page.
1 parent 23f44c7 commit 8f36326

3 files changed

Lines changed: 54 additions & 29 deletions

File tree

app/views/routes/show.html.erb

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,46 +9,50 @@
99
<%= t("page_titles.routes") %>
1010
</h1>
1111

12-
<%= form_with(model: @routes_input, url: routes_path(@routes_input.form)) do |f| %>
13-
<% if @routes_input&.errors&.present? %>
14-
<%= f.govuk_error_summary(presenter: ErrorSummaryPresenter.new(@routes_input.errors)) %>
15-
<% end %>
12+
<%if @routes_input.form.pages.length < 2 %>
13+
<%= t(".not_enough_pages_html", pages_link: form_pages_path(@current_form)) %>
14+
<% else %>
15+
<%= form_with(model: @routes_input, url: routes_path(@routes_input.form)) do |f| %>
16+
<% if @routes_input&.errors&.present? %>
17+
<%= f.govuk_error_summary(presenter: ErrorSummaryPresenter.new(@routes_input.errors)) %>
18+
<% end %>
1619

17-
<%= govuk_summary_list(actions: false) do |summary_list|
20+
<%= govuk_summary_list(actions: false) do |summary_list|
1821

19-
@routes_input.routes.group_by(&:page).each do |page, routes|
20-
summary_list.with_row do |row|
21-
row.with_key(classes: "app-routes-list__key", html_attributes: { id: page.page_position_id}) { page.position.to_s }
22-
row.with_value do
23-
capture do %>
24-
<p> <%= page.question_text %> </p>
25-
<% if @routes_input.form.next_page_after(page).present? %>
26-
<ul class="govuk-list">
27-
<% routes.each do |route| %>
28-
<li>
29-
<%= f.fields_for :routes, route do |route_form|
30-
route_form.hidden_field(:id) +
31-
route_form.hidden_field(:page_id) +
32-
route_form.hidden_field(:answer_value) +
33-
route_form.govuk_select(:goto, options_for_select(route_form.object.goto_options, route_form.object.goto), label: route_form.object.label)
34-
end %>
35-
</li>
22+
@routes_input.routes.group_by(&:page).each do |page, routes|
23+
summary_list.with_row do |row|
24+
row.with_key(classes: "app-routes-list__key", html_attributes: { id: page.page_position_id}) { page.position.to_s }
25+
row.with_value do
26+
capture do %>
27+
<p> <%= page.question_text %> </p>
28+
<% if @routes_input.form.next_page_after(page).present? %>
29+
<ul class="govuk-list">
30+
<% routes.each do |route| %>
31+
<li>
32+
<%= f.fields_for :routes, route do |route_form|
33+
route_form.hidden_field(:id) +
34+
route_form.hidden_field(:page_id) +
35+
route_form.hidden_field(:answer_value) +
36+
route_form.govuk_select(:goto, options_for_select(route_form.object.goto_options, route_form.object.goto), label: route_form.object.label)
37+
end %>
38+
</li>
39+
<% end %>
40+
</ul>
41+
<% if page.answer_type == "selection" &&
42+
page.answer_settings.only_one_option == "true" &&
43+
@routes_input.class.too_many_selection_options?(page) %>
44+
<%= t(".too_many_options_html") %>
3645
<% end %>
37-
</ul>
38-
<% if page.answer_type == "selection" &&
39-
page.answer_settings.only_one_option == "true" &&
40-
@routes_input.class.too_many_selection_options?(page) %>
41-
<%= t(".too_many_options_html") %>
4246
<% end %>
4347
<% end %>
4448
<% end %>
4549
<% end %>
4650
<% end %>
4751
<% end %>
48-
<% end %>
4952

50-
<%= f.govuk_submit t("save_and_continue") %>
53+
<%= f.govuk_submit t("save_and_continue") %>
5154

55+
<% end %>
5256
<% end %>
5357
</div>
5458
</div>

config/locales/en.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1957,6 +1957,9 @@ en:
19571957
title: Number of users per organisation
19581958
routes:
19591959
show:
1960+
not_enough_pages_html: |
1961+
<p>You need more than one question in your form before you can add any routes.</p>
1962+
<p><a href="%{pages_link}">Back to your questions</a></p>
19601963
too_many_options_html: |
19611964
<p>This question has a list with more than 10 options.</p>
19621965

spec/views/routes/show.html.erb_spec.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,4 +215,22 @@ def select_options(select_field)
215215
end
216216
end
217217
end
218+
219+
context "when there are not enoough pages" do
220+
let(:pages) do
221+
[
222+
build_stubbed(:page, id: 101),
223+
]
224+
end
225+
226+
it "shows a warning" do
227+
render_page
228+
expect(rendered).to have_content("You need more than one question in your form before you can add any routes.")
229+
end
230+
231+
it "shows a link to the question pages" do
232+
render_page
233+
expect(rendered).to have_link("Back to your questions", href: form_pages_path(form.id))
234+
end
235+
end
218236
end

0 commit comments

Comments
 (0)