Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions app/views/pages/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,22 @@
<h2 class="govuk-heading-m"><%= t("pages.answer_settings") %></h2>
<%= render PageSettingsSummaryComponent::View.new(draft_question:, errors: question_input.errors) %>

<% unless is_new_page %>
Comment thread
SamJamCul marked this conversation as resolved.
<% routes_body_key =
if page_object.routing_conditions.any?
"has_routes_html"
elsif draft_question.answer_type == "selection" && draft_question.answer_settings[:only_one_option] == "true" && draft_question.answer_settings[:selection_options].length <= 10
"body_html"
elsif page_object.has_next_page?
"skip_body_html"
end %>
<% if routes_body_key %>
Comment on lines +56 to +64

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's quite a lot of logic happening in the view here - it might be worth moving some of it into a controller method or a view component

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(this isn't a blocker, and might make sense as a separate refactor PR after this one is merged)

<h2 class="govuk-heading-m"><%= t("pages.routes_section.heading") %></h2>
<p class="govuk-body"><%= t("pages.routes_section.#{routes_body_key}", routes_path: routes_path(form_id: form_object.id, anchor: page_object.page_position_id)) %></p>
<hr class="govuk-section-break govuk-section-break--m govuk-section-break--visible" />
<% end %>
<% end %>

<ul class="govuk-list govuk-list--spaced">
<li>
<%= f.govuk_submit t('pages.submit_save'), class: "govuk-!-margin-bottom-3", name: "submit_type", value: "save" %>
Expand Down
5 changes: 5 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2038,6 +2038,11 @@ en:
skip_later: If you need to, you can make them skip one or more questions that only people on route 1 need to answer.
will_continue_to: People who select any other answer will continue to question %{next_question_number} and through the rest of the form.
will_continue_to_end_of_form: People who select any other answer will continue to the end of the form.
routes_section:
body_html: If you need people to skip some questions or exit the form based on their answer to this question, <a class="govuk-link" href="%{routes_path}">edit question routes</a>.
has_routes_html: 'This question has routes: <a class="govuk-link" href="%{routes_path}">Edit question routes</a>'
heading: Routes
skip_body_html: If you need people to skip some questions after this one, <a class="govuk-link" href="%{routes_path}">edit question routes</a>.
submit_save: Save question
payment_link_input:
body_html: |
Expand Down
118 changes: 118 additions & 0 deletions spec/views/pages/edit.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,122 @@
expect(rendered).not_to have_text(I18n.t("helpers.hint.pages_question_input.is_optional_options.true"))
end
end

describe "routes section" do
let(:form) { create :form, pages: [page, create(:page)] }
let(:question_input) do
build :question_input,
answer_type: draft_question.answer_type,
answer_settings: draft_question.answer_settings,
question_text: draft_question.question_text,
draft_question:
end

context "when the question has no routes" do
context "when the question is a selection question with one option only" do
let(:draft_question) { build :selection_draft_question, only_one_option: "true" }

it "contains the routes heading" do
expect(rendered).to have_css("h2", text: I18n.t("pages.routes_section.heading"))
end

it "contains a link to the question's routes" do
expect(rendered).to have_link("edit question routes", href: routes_path(form_id: form.id, anchor: page.page_position_id))
end
end

context "when the question is a selection question with one option only and more than 10 options" do
let(:draft_question) { build :selection_draft_question, only_one_option: "true", selection_options: (1..11).map { |i| { name: "Option #{i}", value: "option #{i}" } } }

it "contains the text about skipping questions" do
expect(rendered).to have_text("If you need people to skip some questions after this one, edit question routes.")
end

context "when the question is the last question in the form" do
let(:form) { create :form, pages: [page] }

it "does not contain the routes section" do
expect(rendered).not_to have_css("h2", text: I18n.t("pages.routes_section.heading"))
end
end
end

context "when the question is a selection question with multiple options" do
let(:draft_question) { build :selection_draft_question, only_one_option: "false" }

it "contains the routes heading" do
expect(rendered).to have_css("h2", text: I18n.t("pages.routes_section.heading"))
end

it "contains the text about skipping questions" do
expect(rendered).to have_text("If you need people to skip some questions after this one, edit question routes.")
end

it "contains a link to the question's routes" do
expect(rendered).to have_link("edit question routes", href: routes_path(form_id: form.id, anchor: page.page_position_id))
end
end

context "when the question is not a selection question" do
let(:draft_question) { build :draft_question, answer_type: "email" }

it "contains the routes heading" do
expect(rendered).to have_css("h2", text: I18n.t("pages.routes_section.heading"))
end

it "contains the text about skipping questions" do
expect(rendered).to have_text("If you need people to skip some questions after this one, edit question routes.")
end

it "contains a link to the question's routes" do
expect(rendered).to have_link("edit question routes", href: routes_path(form_id: form.id, anchor: page.page_position_id))
end
end

context "when the question is not a selection question and is the last question in the form" do
let(:form) { create :form, pages: [page] }
let(:draft_question) { build :draft_question, answer_type: "email" }

it "does not contain the routes section" do
expect(rendered).not_to have_css("h2", text: I18n.t("pages.routes_section.heading"))
end
end
end

context "when the question has routes" do
let(:other_page) { create :page }
let(:form) do
create(:form, pages: [page, other_page]).tap do
create :condition, routing_page: page, check_page: page, answer_value: "Option 1", goto_page: other_page
page.reload
end
end
let(:draft_question) { build :selection_draft_question, only_one_option: "true" }

it "contains the routes heading" do
expect(rendered).to have_css("h2", text: I18n.t("pages.routes_section.heading"))
end

it "contains the text saying the question has routes" do
expect(rendered).to have_text("This question has routes: Edit question routes")
end

it "contains a link to the question's routes" do
expect(rendered).to have_link("Edit question routes", href: routes_path(form_id: form.id, anchor: page.page_position_id))
end

context "when the question is the last question in the form" do
let(:form) do
create(:form, pages: [page]).tap do
create :condition, routing_page: page, check_page: page, answer_value: "Option 1", skip_to_end: true
page.reload
end
end

it "contains the text saying the question has routes" do
expect(rendered).to have_text("This question has routes: Edit question routes")
end
end
end
end
end
Loading