From ebb49002c080aead92f224ee2cbb0421a51a9b11 Mon Sep 17 00:00:00 2001 From: Samuel Culley Date: Wed, 1 Jul 2026 09:34:11 +0100 Subject: [PATCH 1/2] Update answer type change with routes warning --- app/views/pages/type_of_answer.html.erb | 5 ++--- config/locales/en.yml | 11 +++------- .../pages/type_of_answer.html.erb_spec.rb | 21 ++++++++++++------- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/app/views/pages/type_of_answer.html.erb b/app/views/pages/type_of_answer.html.erb index 67779624b..2984ab900 100644 --- a/app/views/pages/type_of_answer.html.erb +++ b/app/views/pages/type_of_answer.html.erb @@ -3,10 +3,9 @@
- <% if !FeatureService.new(group: current_form&.group).enabled?(:multiple_branches) && @page.present? && @page.routing_conditions.any? %> + <% if @page.present? && @page.routing_conditions.any? && @page.answer_settings.only_one_option == "true" %> <%= govuk_notification_banner(title_text: t("banner.default.title")) do |banner| %> - <% banner.with_heading(text: t("type_of_answer.routing_warning_about_change_answer_type_heading"), tag: "h3") %> - <%= t("type_of_answer.routing_warning_about_change_answer_type_html", pages_link_url: form_pages_path(current_form.id)) %> + <% banner.with_heading(text: t("type_of_answer.routing_warning_changing_from_one_option_heading", count: @page.routing_conditions.count), tag: "h3") %> <% end %> <% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 680812b28..4d278ca92 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -2168,14 +2168,9 @@ en: not_started: Not started optional: Optional type_of_answer: - routing_warning_about_change_answer_type_heading: Your existing route may be deleted - routing_warning_about_change_answer_type_html: | -

- Changing the answer type from “Selection from a list of options” to a different answer type means your route will no longer work and will be deleted. -

-

- If you do not want to lose your route you can cancel this change by using the back button or go to your questions. -

+ routing_warning_changing_from_one_option_heading: + one: If you change the answer type of this question, its route will be deleted + other: If you change the answer type of this question, its routes will be deleted unarchive: new: body_html: | diff --git a/spec/views/pages/type_of_answer.html.erb_spec.rb b/spec/views/pages/type_of_answer.html.erb_spec.rb index 3aec31ece..45399f345 100644 --- a/spec/views/pages/type_of_answer.html.erb_spec.rb +++ b/spec/views/pages/type_of_answer.html.erb_spec.rb @@ -66,20 +66,25 @@ expect(rendered).not_to have_selector(".govuk-notification-banner__content") end - context "when editing an existing" do - let(:page) { OpenStruct.new(routing_conditions:, answer_type:) } + context "when editing an existing select one option question with a route set" do + let(:page) { OpenStruct.new(routing_conditions:, answer_type:, answer_settings:) } + let(:answer_settings) { OpenStruct.new(only_one_option: "true") } let(:answer_type) { "selection" } let(:routing_conditions) { [build(:condition)] } it "displays a warning about routes being deleted if answer type changes" do - expect(Capybara.string(rendered.html).find(".govuk-notification-banner__content").text(normalize_ws: true)) - .to include(Capybara.string(I18n.t("type_of_answer.routing_warning_about_change_answer_type_html", pages_link_url: form_pages_path(form))) - .text(normalize_ws: true)) + expect(Capybara.string(rendered.html).find(".govuk-notification-banner__heading").text(normalize_ws: true)) + .to include(Capybara.string(I18n.t("type_of_answer.routing_warning_changing_from_one_option_heading", count: 1)) + .text(normalize_ws: true)) end - context "when multiple branches are enabled", :feature_multiple_branches do - it "does not display a warning about routes being deleted if answer type changes" do - expect(rendered).not_to have_selector(".govuk-notification-banner__content") + context "with multiple routes set" do + let(:routing_conditions) { [build(:condition), build(:condition)] } + + it "displays a warning about routes being deleted if answer type changes" do + expect(Capybara.string(rendered.html).find(".govuk-notification-banner__heading").text(normalize_ws: true)) + .to include(Capybara.string(I18n.t("type_of_answer.routing_warning_changing_from_one_option_heading", count: 2)) + .text(normalize_ws: true)) end end From e17614be13fae400c56f0efdb9dadff4fec6a56a Mon Sep 17 00:00:00 2001 From: Samuel Culley Date: Wed, 1 Jul 2026 09:56:55 +0100 Subject: [PATCH 2/2] Delete conditions when changing from single select When changing the answer type of a selection question, we only need to delete conditions associated with that question if it was a single selection question. If it could have multiple options, then we don't need to remove existing conditions. --- app/models/page.rb | 6 +++--- spec/models/page_spec.rb | 10 ++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/app/models/page.rb b/app/models/page.rb index 908b16e11..2cacc0d74 100644 --- a/app/models/page.rb +++ b/app/models/page.rb @@ -54,7 +54,7 @@ def save_and_update_form save! form.save_question_changes! - check_conditions.destroy_all if answer_type_changed_from_selection + check_conditions.destroy_all if answer_type_changed_from_selection_only_one_option check_conditions.destroy_all if answer_settings_changed_from_only_one_option true @@ -79,8 +79,8 @@ def has_next_page? next_page.present? end - def answer_type_changed_from_selection - answer_type_previously_was&.to_sym == :selection && answer_type&.to_sym != :selection + def answer_type_changed_from_selection_only_one_option + answer_type_previously_was&.to_sym == :selection && answer_type&.to_sym != :selection && answer_settings_previously_was.only_one_option == "true" end def answer_settings_changed_from_only_one_option diff --git a/spec/models/page_spec.rb b/spec/models/page_spec.rb index ab678060e..a609670d8 100644 --- a/spec/models/page_spec.rb +++ b/spec/models/page_spec.rb @@ -521,6 +521,16 @@ expect(page.reload.check_conditions).not_to be_empty end end + + context "when the answer type changes from selection with more than one option" do + subject(:page) { create :page, :selection_with_checkboxes, form:, routing_conditions:, check_conditions: } + + it "does not delete any conditions" do + page.answer_type = "number" + page.save_and_update_form + expect(page.reload.check_conditions).not_to be_empty + end + end end end