From 4ca4ec913762d5592ba792cdf7e2e471d0cb065a Mon Sep 17 00:00:00 2001 From: Kat Date: Thu, 26 May 2022 14:50:01 +0100 Subject: [PATCH] =?UTF-8?q?don't=20display=20the=20save=20and=20go=20to=20?= =?UTF-8?q?the=20next=20incomplete=20section=20button=20if=20it=20errors?= =?UTF-8?q?=20=F0=9F=A4=B7=E2=80=8D=E2=99=80=EF=B8=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/form/check_answers.html.erb | 5 +++-- spec/requests/form_controller_spec.rb | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/app/views/form/check_answers.html.erb b/app/views/form/check_answers.html.erb index 45ecaf9a2..216bc747b 100644 --- a/app/views/form/check_answers.html.erb +++ b/app/views/form/check_answers.html.erb @@ -24,8 +24,9 @@ <%= form_with model: @case_log, method: "get" do |f| %> <%= f.govuk_submit "Save and return to log" do %> - <% if @case_log.status == "in_progress" %> - <%= govuk_button_link_to "Save and go to next incomplete section", "/logs/#{@case_log.id}/#{@case_log.form.next_incomplete_section_redirect_path(subsection, @case_log)}", secondary: true %> + <% next_incomplete_section_redirect_path = @case_log.form.next_incomplete_section_redirect_path(subsection, @case_log) %> + <% if @case_log.status == "in_progress" && next_incomplete_section_redirect_path != "error" %> + <%= govuk_button_link_to "Save and go to next incomplete section", "/logs/#{@case_log.id}/#{next_incomplete_section_redirect_path}", secondary: true %> <% end %> <% end %> <% end %> diff --git a/spec/requests/form_controller_spec.rb b/spec/requests/form_controller_spec.rb index 5a30b1ae5..d99e03ba6 100644 --- a/spec/requests/form_controller_spec.rb +++ b/spec/requests/form_controller_spec.rb @@ -1,6 +1,7 @@ require "rails_helper" RSpec.describe FormController, type: :request do + let(:page) { Capybara::Node::Simple.new(response.body) } let(:user) { FactoryBot.create(:user) } let(:organisation) { user.organisation } let(:other_organisation) { FactoryBot.create(:organisation) } @@ -36,6 +37,14 @@ RSpec.describe FormController, type: :request do managing_organisation: organisation, ) end + let(:in_progress_case_log) do + FactoryBot.create( + :case_log, + :in_progress, + owning_organisation: organisation, + managing_organisation: organisation, + ) + end let(:headers) { { "Accept" => "text/html" } } context "when a user is not signed in" do @@ -100,6 +109,16 @@ RSpec.describe FormController, type: :request do expect(response).to have_http_status(:not_found) end end + + context "when no other sections are enabled" do + before do + allow(in_progress_case_log.form).to receive(:next_incomplete_section_redirect_path).and_return("error") + get "/logs/#{in_progress_case_log.id}/household-characteristics/check-answers", headers: headers, params: {} + end + it "does not show Save and go to next incomplete section button" do + expect(page).not_to have_content("Save and go to next incomplete section") + end + end end context "with a question in a section that isn't enabled yet" do