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/fixtures/forms/2022_2023.json b/spec/fixtures/forms/2022_2023.json index e9fcb6990..62208736e 100644 --- a/spec/fixtures/forms/2022_2023.json +++ b/spec/fixtures/forms/2022_2023.json @@ -118,7 +118,12 @@ "derived": true, "depends_on": [false] } - } + }, + "depends_on": [ + { + "setup": "completed" + } + ] } } } diff --git a/spec/requests/form_controller_spec.rb b/spec/requests/form_controller_spec.rb index 5a30b1ae5..33c95a9e9 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(:case_log_2022) do + FactoryBot.create( + :case_log, + startdate: Time.zone.local(2022, 12, 1), + 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 + get "/logs/#{case_log_2022.id}/setup/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