From 23c6111ab5eda08d96904a5ca619b414d27d29ff Mon Sep 17 00:00:00 2001 From: edwin-jebaraj Date: Sun, 8 Dec 2024 23:12:16 +0000 Subject: [PATCH] updated spec scenario --- ...nt_can_upload_evaluation_documents_spec.rb | 75 ++++++++++++------- 1 file changed, 49 insertions(+), 26 deletions(-) diff --git a/spec/features/support/agent_can_upload_evaluation_documents_spec.rb b/spec/features/support/agent_can_upload_evaluation_documents_spec.rb index f873d55de..7145df2e9 100644 --- a/spec/features/support/agent_can_upload_evaluation_documents_spec.rb +++ b/spec/features/support/agent_can_upload_evaluation_documents_spec.rb @@ -1,13 +1,14 @@ require "rails_helper" -RSpec.describe "Agent can upload evaluation documents", type: :feature do +RSpec.feature "Agent can upload evaluation documents", :js, :with_csrf_protection do include_context "with an agent" let(:support_case) { create(:support_case) } let(:file_1) { fixture_file_upload(Rails.root.join("spec/fixtures/support/text-file.txt"), "text/plain") } let(:file_2) { fixture_file_upload(Rails.root.join("spec/fixtures/support/another-text-file.txt"), "text/plain") } + let(:document_uploader) { support_case.document_uploader(files: [file_1, file_2]) } - specify "Upload documents" do + specify "when no files are selected" do visit edit_support_case_document_uploads_path(case_id: support_case) expect(page).to have_text("Upload documents") @@ -21,37 +22,59 @@ expect(page).to have_text("Please confirm that you uploaded all documents") end - context "when files are uploaded" do - let(:document_uploader) { support_case.document_uploader(files: [file_1, file_2]) } - let(:is_upload_documents) { true } + specify "when files are uploaded and confirmation choosen as No (In progress)" do + support_case.update!(is_upload_documents: false) - it "attaches the files to the case" do - expect { document_uploader.save! }.to change { support_case.upload_documents.count }.from(0).to(2) - expect(support_case.upload_documents.pluck(:file_name)).to contain_exactly("text-file.txt", "another-text-file.txt") - expect(support_case.upload_documents.map { |a| a.file.attached? }.all?).to eq(true) - end + expect { document_uploader.save! }.to change { support_case.upload_documents.count }.from(0).to(2) + expect(support_case.upload_documents.pluck(:file_name)).to contain_exactly("text-file.txt", "another-text-file.txt") + expect(support_case.upload_documents.map { |a| a.file.attached? }.all?).to eq(true) + + visit support_case_path(support_case, anchor: "tasklist") + + expect(find("#complete-evaluation-3-status")).to have_text("In progress") + end + + specify "when files are uploaded and confirmation choosen as Yes (Complete)" do + support_case.update!(is_upload_documents: true) + + expect { document_uploader.save! }.to change { support_case.upload_documents.count }.from(0).to(2) + expect(support_case.upload_documents.pluck(:file_name)).to contain_exactly("text-file.txt", "another-text-file.txt") + expect(support_case.upload_documents.map { |a| a.file.attached? }.all?).to eq(true) + + visit support_case_path(support_case, anchor: "tasklist") + + expect(find("#complete-evaluation-3-status")).to have_text("Complete") end - context "when no files are uploaded" do - let(:document_uploader) { support_case.document_uploader } + specify "viewing uploaded files and deleting files" do + support_case.update!(is_upload_documents: true) + document_uploader.save! + + visit edit_support_case_document_uploads_path(case_id: support_case) + + expect(page).to have_content("text-file.txt") + expect(page).to have_content("another-text-file.txt") + + find_all(".case-files__file-remove a")[0].click + + expect(find(".govuk-button--warning")).to have_content("Delete") - it "fails validation" do - expect(document_uploader).not_to be_valid - expect(document_uploader.errors.messages[:files]).to eq ["Select files to upload"] - end + expect(page).to have_content("text-file.txt") end - context "when uploaded files contain viruses" do - before do - allow(Support::VirusScanner).to receive(:uploaded_file_safe?).with(file_1).and_return(true) - allow(Support::VirusScanner).to receive(:uploaded_file_safe?).with(file_2).and_return(false) - end + specify "when all files are deleted" do + support_case.reload + + support_case.upload_documents(&:destroy!) + + support_case.reload + + support_case.update!(is_upload_documents: nil) + + expect(support_case.upload_documents.count).to eq(0) - let(:document_uploader) { support_case.document_uploader(files: [file_1, file_2]) } + visit support_case_path(support_case, anchor: "tasklist") - it "fails validation" do - expect(document_uploader).not_to be_valid - expect(document_uploader.errors.messages[:files]).to eq ["One or more selected files contained a virus and have been rejected"] - end + expect(find("#complete-evaluation-3-status", wait: 10)).to have_text("To do") end end