2024-09-06 17:17:57 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe Attachment::GalleryItemComponent, type: :component do
|
2024-09-10 11:43:25 +02:00
|
|
|
let(:instructeur) { create(:instructeur) }
|
2024-09-06 17:17:57 +02:00
|
|
|
let(:procedure) { create(:procedure, :published, types_de_champ_public:) }
|
|
|
|
let(:types_de_champ_public) { [{ type: :piece_justificative }] }
|
|
|
|
let(:dossier) { create(:dossier, :with_populated_champs, :en_construction, procedure:) }
|
|
|
|
let(:filename) { attachment.blob.filename.to_s }
|
2024-09-09 10:33:31 +02:00
|
|
|
let(:gallery_demande) { false }
|
2024-09-06 17:17:57 +02:00
|
|
|
|
2024-09-09 10:33:31 +02:00
|
|
|
let(:component) { described_class.new(attachment: attachment, gallery_demande:) }
|
2024-09-06 17:17:57 +02:00
|
|
|
|
|
|
|
subject { render_inline(component).to_html }
|
|
|
|
|
|
|
|
context "when attachment is from a piece justificative champ" do
|
|
|
|
let(:champ) { dossier.champs.first }
|
|
|
|
let(:libelle) { champ.libelle }
|
|
|
|
let(:attachment) { champ.piece_justificative_file.attachments.first }
|
|
|
|
|
2024-09-10 11:43:25 +02:00
|
|
|
it "displays libelle, link, tag and renders title" do
|
2024-09-06 17:17:57 +02:00
|
|
|
expect(subject).to have_text(libelle)
|
|
|
|
expect(subject).not_to have_text('Pièce jointe au message')
|
|
|
|
expect(subject).to have_link(filename)
|
2024-09-10 11:43:25 +02:00
|
|
|
expect(subject).to have_text('Dossier usager')
|
2024-09-06 17:17:57 +02:00
|
|
|
expect(component.title).to eq("#{libelle} -- #{filename}")
|
|
|
|
end
|
2024-09-09 10:33:31 +02:00
|
|
|
|
2024-09-09 18:01:24 +02:00
|
|
|
it "displays when gallery item has been added" do
|
|
|
|
expect(subject).to have_text(component.helpers.try_format_datetime(attachment.record.created_at, format: :veryshort))
|
|
|
|
end
|
|
|
|
|
2024-09-09 10:33:31 +02:00
|
|
|
context "when gallery item is in page Demande" do
|
|
|
|
let(:gallery_demande) { true }
|
|
|
|
|
|
|
|
it "does not display libelle" do
|
|
|
|
expect(subject).not_to have_text(libelle)
|
|
|
|
end
|
|
|
|
end
|
2024-09-06 17:17:57 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
context "when attachment is from a commentaire" do
|
|
|
|
let(:commentaire) { create(:commentaire, :with_file, dossier: dossier) }
|
|
|
|
let(:attachment) { commentaire.piece_jointe.first }
|
|
|
|
|
2024-09-10 11:43:25 +02:00
|
|
|
context 'from an usager' do
|
|
|
|
it "displays a generic libelle, link, tag and renders title" do
|
|
|
|
expect(subject).to have_text('Pièce jointe au message')
|
|
|
|
expect(subject).to have_link(filename)
|
|
|
|
expect(subject).to have_text('Messagerie (usager)')
|
|
|
|
expect(component.title).to eq("Pièce jointe au message -- #{filename}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'from an instructeur' do
|
|
|
|
before { commentaire.update!(instructeur:) }
|
|
|
|
it "displays the right tag" do
|
|
|
|
expect(subject).to have_text('Messagerie (instructeur)')
|
|
|
|
end
|
2024-09-06 17:17:57 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|