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