Skip to content

Commit

Permalink
Add warning for deleting page at end of secondary skip route
Browse files Browse the repository at this point in the history
  • Loading branch information
lfdebrux committed Dec 11, 2024
1 parent 93ee772 commit c9116b4
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/controllers/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions app/views/pages/delete.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1141,6 +1141,13 @@ en:
<a class="govuk-notification-banner__link" href="%{routing_page_show_routes_href}">Question %{routing_page_position}’s route</a>
goes to this question. If you delete this question, question %{routing_page_position}’s routes will also be deleted.
</p>
end_of_secondary_skip_route:
heading_text: Question %{goto_page_position} is at the end of a route
html: |
<p class="govuk-body">
<a class="govuk-notification-banner__link" href="%{check_page_show_routes_href}">Question %{check_page_position}’s route</a>
goes to this question. If you delete this question, the route to it will also be deleted.
</p>
start_of_route:
heading_text: Question %{routing_page_position} is the start of a route
html: |
Expand Down
46 changes: 46 additions & 0 deletions spec/requests/pages_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
67 changes: 67 additions & 0 deletions spec/views/pages/delete.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit c9116b4

Please sign in to comment.