feat(gallery): add attachments from avis
This commit is contained in:
parent
e95e86faae
commit
d10df6e17c
5 changed files with 99 additions and 8 deletions
|
@ -101,4 +101,52 @@ RSpec.describe Attachment::GalleryItemComponent, type: :component do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when attachment is from an avis" do
|
||||
context 'from an instructeur' do
|
||||
let(:avis) { create(:avis, :with_introduction, dossier: dossier) }
|
||||
let(:attachment) { avis.introduction_file.attachment }
|
||||
|
||||
it "displays a generic libelle, link, tag and renders title" do
|
||||
expect(subject).to have_text('Pièce jointe à l’avis')
|
||||
expect(subject).to have_link(filename)
|
||||
expect(subject).to have_text('Avis externe (instructeur)')
|
||||
expect(component.title).to eq("Pièce jointe à l’avis -- #{filename}")
|
||||
end
|
||||
|
||||
context "when instructeur has not seen it yet" do
|
||||
let(:seen_at) { now - 1.day }
|
||||
|
||||
before do
|
||||
attachment.blob.update(created_at: now)
|
||||
end
|
||||
|
||||
it 'displays datetime in the right style' do
|
||||
expect(subject).to have_css('.highlighted')
|
||||
end
|
||||
end
|
||||
|
||||
context "when instructeur has already seen it" do
|
||||
let!(:seen_at) { now }
|
||||
|
||||
before do
|
||||
freeze_time
|
||||
attachment.blob.touch(:created_at)
|
||||
end
|
||||
|
||||
it 'displays datetime in the right style' do
|
||||
expect(subject).not_to have_css('.highlighted')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'from an expert' do
|
||||
let(:avis) { create(:avis, :with_piece_justificative, dossier: dossier) }
|
||||
let(:attachment) { avis.piece_justificative_file.attachment }
|
||||
|
||||
it "displays the right tag" do
|
||||
expect(subject).to have_text('Avis externe (expert)')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1486,6 +1486,9 @@ describe Instructeurs::DossiersController, type: :controller do
|
|||
let(:logo_path) { 'spec/fixtures/files/logo_test_procedure.png' }
|
||||
let(:rib_path) { 'spec/fixtures/files/RIB.pdf' }
|
||||
let(:commentaire) { create(:commentaire, dossier: dossier) }
|
||||
let(:expert) { create(:expert) }
|
||||
let(:experts_procedure) { create(:experts_procedure, expert: expert, procedure: procedure) }
|
||||
let(:avis) { create(:avis, :with_answer, :with_piece_justificative, dossier: dossier, claimant: expert, experts_procedure: experts_procedure) }
|
||||
|
||||
before do
|
||||
dossier.champs.first.piece_justificative_file.attach(
|
||||
|
@ -1502,20 +1505,29 @@ describe Instructeurs::DossiersController, type: :controller do
|
|||
metadata: { virus_scan_result: ActiveStorage::VirusScanner::SAFE }
|
||||
)
|
||||
|
||||
avis.piece_justificative_file.attach(
|
||||
io: File.open(rib_path),
|
||||
filename: "RIB.pdf",
|
||||
content_type: "application/pdf",
|
||||
metadata: { virus_scan_result: ActiveStorage::VirusScanner::SAFE }
|
||||
)
|
||||
|
||||
get :pieces_jointes, params: {
|
||||
procedure_id: procedure.id,
|
||||
dossier_id: dossier.id
|
||||
}
|
||||
end
|
||||
|
||||
it 'returns pieces jointes from champs and from messagerie' do
|
||||
it 'returns pieces jointes from champs, messagerie and avis' do
|
||||
expect(response.body).to include('Télécharger le fichier toto.txt')
|
||||
expect(response.body).to include('Télécharger le fichier logo_test_procedure.png')
|
||||
expect(response.body).to include('Télécharger le fichier RIB.pdf')
|
||||
expect(response.body).to include('Visualiser')
|
||||
expect(assigns(:gallery_attachments).count).to eq 3
|
||||
expect(response.body).to include('Pièce jointe au message')
|
||||
expect(response.body).to include('Pièce jointe à l’avis')
|
||||
expect(assigns(:gallery_attachments).count).to eq 4
|
||||
expect(assigns(:gallery_attachments)).to all(be_a(ActiveStorage::Attachment))
|
||||
expect([Champs::PieceJustificativeChamp, Champs::TitreIdentiteChamp, Commentaire]).to include(*assigns(:gallery_attachments).map { _1.record.class })
|
||||
expect([Champs::PieceJustificativeChamp, Champs::TitreIdentiteChamp, Commentaire, Avis]).to include(*assigns(:gallery_attachments).map { _1.record.class })
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue