Skip to content

Commit

Permalink
can not add more than max evidence in journeys
Browse files Browse the repository at this point in the history
  • Loading branch information
asmega committed Nov 22, 2023
1 parent 66c8724 commit c73ee9a
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 9 deletions.
10 changes: 9 additions & 1 deletion app/forms/referrals/allegation_evidence/uploaded_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
Check and confirm your answers
</h1>

<%= 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 %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@
<% end %>
</dl>

<%= 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" %>
Expand Down
52 changes: 52 additions & 0 deletions spec/system/public_referrals/user_adds_allegation_evidence_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit c73ee9a

Please sign in to comment.