diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index 4dc38eb0d..1a45b4ad1 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -21,6 +21,7 @@ def delete @check_page = PageRepository.find(page_id: @page.routing_conditions.first.check_page_id, form_id: current_form.id) if @page.routing_conditions.first&.secondary_skip? @routing_page = PageRepository.find(page_id: @page_goto_conditions.first.routing_page_id, form_id: current_form.id) if @page_goto_conditions.any? + @check_page = PageRepository.find(page_id: @page_goto_conditions.first.check_page_id, form_id: current_form.id) if @page_goto_conditions.any? @delete_confirmation_input = Forms::DeleteConfirmationInput.new diff --git a/app/views/pages/delete.html.erb b/app/views/pages/delete.html.erb index 745a8ae83..1a91b5819 100644 --- a/app/views/pages/delete.html.erb +++ b/app/views/pages/delete.html.erb @@ -17,6 +17,12 @@ t(".notification_banner.start_of_route.html", routing_page_position: @page.position, routing_page_show_routes_href: show_routes_path(current_form.id, @page.id)) end %> + <% elsif @page_goto_conditions.present? && @page_goto_conditions.first&.secondary_skip? %> + <%= govuk_notification_banner(title_text: "Important") do |banner| + banner.with_heading(text: t(".notification_banner.end_of_secondary_skip_route.heading_text", goto_page_position: @page.position), tag: :h3) + + t(".notification_banner.end_of_secondary_skip_route.html", check_page_position: @check_page.position, check_page_show_routes_href: show_routes_path(current_form.id, @check_page.id)) + end %> <% elsif @page_goto_conditions.present? %> <%= govuk_notification_banner(title_text: "Important") do |banner| banner.with_heading(text: t(".notification_banner.end_of_route.heading_text", goto_page_position: @page.position), tag: :h3) diff --git a/config/locales/en.yml b/config/locales/en.yml index 80decac5a..7ef8beec7 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1141,6 +1141,13 @@ en: Question %{routing_page_position}’s route goes to this question. If you delete this question, question %{routing_page_position}’s routes will also be deleted.
+ end_of_secondary_skip_route: + heading_text: Question %{goto_page_position} is at the end of a route + html: | ++ Question %{check_page_position}’s route + goes to this question. If you delete this question, the route to it will also be deleted. +
start_of_route: heading_text: Question %{routing_page_position} is the start of a route html: | diff --git a/spec/requests/pages_controller_spec.rb b/spec/requests/pages_controller_spec.rb index 2edaacab4..008fc52a8 100644 --- a/spec/requests/pages_controller_spec.rb +++ b/spec/requests/pages_controller_spec.rb @@ -247,6 +247,52 @@ end end end + + context "when page to delete is at the end of a secondary skip route" do + let(:pages) do + [ + build( + :page, + :with_selection_settings, + id: 1, + form_id: 2, + position: 1, + question_text: "What is your favourite colour?", + selection_options: [{ name: "Red" }, { name: "Green" }, { name: "Blue" }], + only_one_option: true, + routing_conditions: [ + build(:condition, routing_page_id: 1, check_page_id: 1, value: "green", goto_page_id: 3), + ], + ), + build( + :page, + id: 5, + form_id: 2, + position: 5, + routing_conditions: [ + build(:condition, routing_page_id: 5, check_page_id: 1, value: nil, goto_page_id: 8), + ], + ), + build( + :page, + id: 8, + form_id: 2, + position: 8, + ), + ] + end + + let(:page) { pages.last } + + it "renders a warning about deleting this page" do + assert_select(".govuk-notification-banner", count: 1) do + assert_select "*", "Important" + assert_select "h3", "Question 8 is at the end of a route" + assert_select "p.govuk-body a", "Question 1’s route" + assert_select "p.govuk-body", /Question 1’s route\s*goes to this question. If you delete this question, the route to it will also be deleted./ + end + end + end end end diff --git a/spec/views/pages/delete.html.erb_spec.rb b/spec/views/pages/delete.html.erb_spec.rb index f2d67f7d7..ae373a67c 100644 --- a/spec/views/pages/delete.html.erb_spec.rb +++ b/spec/views/pages/delete.html.erb_spec.rb @@ -200,4 +200,71 @@ end end end + + describe "when page to delete is at the end of a secondary skip route" do + let(:check_page) do + build( + :page, + id: 1, + form_id: 1, + position: 3, + routing_conditions: [ + build(:condition, routing_page_id: 1, check_page_id: 1, goto_page_id: 3), + ], + ) + end + + let(:routing_page) do + build( + :page, + id: 12, + form_id: 1, + position: 7, + routing_conditions: [ + build(:condition, routing_page_id: 12, check_page_id: 1, goto_page_id: 9), + ], + ) + end + + let(:page) do + build( + :page, + id: 9, + form_id: 1, + position: 12, + ) + end + + before do + assign(:check_page, check_page) + assign(:page_goto_conditions, routing_page.routing_conditions) + + render locals: { current_form: } + end + + it "renders a notification banner" do + expect(rendered).to have_css ".govuk-notification-banner" + end + + describe "notification banner" do + subject(:banner) { rendered.html.at_css(".govuk-notification-banner") } + + it { is_expected.to have_text "Important" } + it { is_expected.to have_css "h3.govuk-notification-banner__heading", text: "Question 12 is at the end of a route", count: 1 } + it { is_expected.to have_link "Question 3’s route", class: "govuk-notification-banner__link", href: show_routes_path(1, 1) } + it { is_expected.to have_css "p.govuk-body", text: "Question 3’s route goes to this question. If you delete this question, the route to it will also be deleted.", normalize_ws: true } + end + + context "but there was an error in the user's input" do + let(:delete_confirmation_input) do + delete_confirmation_input = Forms::DeleteConfirmationInput.new(confirm: "") + delete_confirmation_input.validate + delete_confirmation_input + end + + it "does not render the notification banner" do + expect(rendered).not_to have_css ".govuk-notification-banner" + end + end + end end