Skip to content

Commit 4d9366f

Browse files
committed
Add form to routes#show view
Add a view with a form to so multiple branch routes can be created.
1 parent 720bdf8 commit 4d9366f

4 files changed

Lines changed: 72 additions & 2 deletions

File tree

app/frontend/entrypoints/application.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ $govuk-global-styles: true;
77
@import "../styles/app_form_states";
88
@import "../styles/app_lists";
99
@import "../styles/app_preview_area";
10+
@import "../styles/app_routes_list";
1011
@import "../styles/app_select_options";
1112
@import "../styles/app_summary_card";
1213
@import "../styles/app_summary_list";
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.app-routes-list__key {
2+
@include govuk-media-query($from: desktop) {
3+
width: 5%;
4+
}
5+
}
6+

app/views/routes/show.html.erb

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,42 @@
88
<span class="govuk-visually-hidden"> - </span>
99
<%= t("page_titles.routes") %>
1010
</h1>
11+
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 %>
16+
17+
<%= govuk_summary_list(actions: false) do |summary_list|
18+
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}"}) { page.position.to_s }
22+
row.with_value do
23+
capture do %>
24+
<p> <%= page.question_text %> </p>
25+
<% if page.has_next_page? %>
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>
36+
<% end %>
37+
</ul>
38+
<% end %>
39+
<% end %>
40+
<% end %>
41+
<% end %>
42+
<% end %>
43+
<% end %>
44+
45+
<%= f.govuk_submit t("save_and_continue") %>
46+
47+
<% end %>
1148
</div>
1249
</div>

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

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
require "rails_helper"
22

33
describe "routes/show.html.erb" do
4-
let(:form) { build_stubbed :form }
4+
let(:form) { build_stubbed :form, pages: }
5+
let(:pages) { [] }
6+
let(:routes) { [] }
7+
let(:routes_input) { build :routes_input, form:, routes: }
58

69
def render_page
710
assign(:current_form, form)
8-
render template: "routes/show", locals: { current_form: form }
11+
assign(:routes_input, routes_input)
12+
render template: "routes/show", locals: { current_form: form, routes_input: }
913
end
1014

1115
it "has the correct title" do
@@ -23,4 +27,26 @@ def render_page
2327
expect(rendered).to have_selector("h1", text: form.name)
2428
expect(rendered).to have_selector("h1", text: "Edit question routes")
2529
end
30+
31+
context "when the form has pages and routes" do
32+
let(:pages) { build_stubbed_list(:page, 3) }
33+
let(:routes) do
34+
[
35+
build(:route_input, page: pages.first, goto: pages.third.id, goto_options: []),
36+
build(:route_input, :default, page: pages.second, goto_options: []),
37+
build(:route_input, :default, page: pages.third, goto_options: []),
38+
]
39+
end
40+
41+
it "displays the page's position and question text" do
42+
render_page
43+
expect(rendered).to have_selector(".govuk-summary-list__key", text: pages.first.position.to_s)
44+
expect(rendered).to have_selector(".govuk-summary-list__value", text: pages.first.question_text)
45+
end
46+
47+
it "includes the page's position in the id of the key" do
48+
render_page
49+
expect(rendered).to have_selector("#page-#{pages.first.position}")
50+
end
51+
end
2652
end

0 commit comments

Comments
 (0)