diff --git a/app/forms/referrals/allegation_evidence/uploaded_form.rb b/app/forms/referrals/allegation_evidence/uploaded_form.rb index 746a543e0..631a6610c 100644 --- a/app/forms/referrals/allegation_evidence/uploaded_form.rb +++ b/app/forms/referrals/allegation_evidence/uploaded_form.rb @@ -3,11 +3,19 @@ module AllegationEvidence class UploadedForm < FormItem attr_accessor :more_evidence - validates :more_evidence, inclusion: { in: %w[yes no] }, on: :update + validates :more_evidence, + inclusion: { in: %w[yes no] }, + on: :update, + if: Proc.new { |form| form.can_upload_more_evidence? } + def more_evidence? @more_evidence == "yes" end + + def can_upload_more_evidence? + referral.can_upload_more_evidence? + end end end end diff --git a/app/views/public_referrals/allegation_evidence/check_answers/edit.html.erb b/app/views/public_referrals/allegation_evidence/check_answers/edit.html.erb index ebe1ff304..29f940fb8 100644 --- a/app/views/public_referrals/allegation_evidence/check_answers/edit.html.erb +++ b/app/views/public_referrals/allegation_evidence/check_answers/edit.html.erb @@ -11,11 +11,13 @@ Check and confirm your answers - <%= govuk_button_link_to( - "Add more evidence", - edit_public_referral_allegation_evidence_upload_path(current_referral), - class: "govuk-button--secondary govuk-!-margin-bottom-8" - ) if current_referral.has_evidence %> + <% if current_referral.can_upload_more_evidence? %> + <%= govuk_button_link_to( + "Add more evidence", + edit_public_referral_allegation_evidence_upload_path(current_referral), + class: "govuk-button--secondary govuk-!-margin-bottom-8" + ) if current_referral.has_evidence %> + <% end %> <%= render partial: 'referrals/shared/check_answers', locals: { f:, complete_field_name: :evidence_details_complete } %> <% end %> diff --git a/app/views/public_referrals/allegation_evidence/uploaded/edit.html.erb b/app/views/public_referrals/allegation_evidence/uploaded/edit.html.erb index 5e41bea19..c82db71bc 100644 --- a/app/views/public_referrals/allegation_evidence/uploaded/edit.html.erb +++ b/app/views/public_referrals/allegation_evidence/uploaded/edit.html.erb @@ -30,9 +30,11 @@ <% end %> - <%= f.govuk_radio_buttons_fieldset(:more_evidence, legend: { size: "m", text: "Do you want to upload another file?" }) do %> - <%= f.govuk_radio_button :more_evidence, "yes", label: { text: "Yes" }, link_errors: true %> - <%= f.govuk_radio_button :more_evidence, "no", label: { text: "No" } %> + <% if f.object.referral.can_upload_more_evidence? %> + <%= f.govuk_radio_buttons_fieldset(:more_evidence, legend: { size: "m", text: "Do you want to upload another file?" }) do %> + <%= f.govuk_radio_button :more_evidence, "yes", label: { text: "Yes" }, link_errors: true %> + <%= f.govuk_radio_button :more_evidence, "no", label: { text: "No" } %> + <% end %> <% end %> <%= f.govuk_submit "Save and continue" %> diff --git a/spec/system/public_referrals/user_adds_allegation_evidence_spec.rb b/spec/system/public_referrals/user_adds_allegation_evidence_spec.rb index 7c75ff9a6..211e7df4c 100644 --- a/spec/system/public_referrals/user_adds_allegation_evidence_spec.rb +++ b/spec/system/public_referrals/user_adds_allegation_evidence_spec.rb @@ -5,6 +5,34 @@ include CommonSteps include SummaryListHelpers + scenario "A member of public uploads maximum number of evidence uploads" do + given_the_service_is_open + and_i_am_signed_in + and_the_referral_form_feature_is_active + and_i_am_a_member_of_the_public_with_an_existing_referral + and_i_visit_the_public_referral + then_i_see_the_public_referral_summary + + when_i_edit_the_evidence + then_i_am_asked_if_i_have_evidence_to_upload + + when_i_choose_yes_to_uploading_evidence + and_i_click_save_and_continue + then_i_am_asked_to_upload_evidence_files + + when_i_upload_the_maximum_number_of_files + and_i_click_save_and_continue + then_i_see_a_list_of_max_uploaded_files + then_i_cannot_upload_another_file + + when_i_click_save_and_continue + then_i_see_the_check_your_answers_page( + "Evidence and supporting information", + "allegation_evidence" + ) + then_cannot_add_more_evidence + end + scenario "A member of public adds evidence to referral" do given_the_service_is_open and_i_am_signed_in @@ -311,4 +339,28 @@ def then_the_list_of_the_uploaded_files_should_be_empty def when_i_click_on_change_evidence click_on "Change if you have anything to upload" end + + def when_i_upload_the_maximum_number_of_files + attach_file( + "Upload files", + FileUploadValidator::MAX_FILES.times.map { + Rails.root.join("spec/fixtures/files/upload1.pdf") + } + ) + end + + def then_i_cannot_upload_another_file + expect(page).not_to have_content("Do you want to upload another file?") + end + + def then_cannot_add_more_evidence + expect(page).not_to have_content("Add more evidence") + end + + def then_i_see_a_list_of_max_uploaded_files + expect(page).to have_content("Uploaded evidence") + within(".govuk-summary-list") do + expect(page).to have_link("upload1.pdf", count: 20, href: /active_storage/) + end + end end