refactor(gallery): add attachment_gallery_item component
This commit is contained in:
parent
6b1c6a796a
commit
bae752f1aa
6 changed files with 96 additions and 39 deletions
38
spec/components/attachment/gallery_item_component_spec.rb
Normal file
38
spec/components/attachment/gallery_item_component_spec.rb
Normal file
|
@ -0,0 +1,38 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Attachment::GalleryItemComponent, type: :component do
|
||||
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 }
|
||||
|
||||
let(:component) { described_class.new(attachment: attachment) }
|
||||
|
||||
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 }
|
||||
|
||||
it "displays libelle, link and renders title" do
|
||||
expect(subject).to have_text(libelle)
|
||||
expect(subject).not_to have_text('Pièce jointe au message')
|
||||
expect(subject).to have_link(filename)
|
||||
expect(component.title).to eq("#{libelle} -- #{filename}")
|
||||
end
|
||||
end
|
||||
|
||||
context "when attachment is from a commentaire" do
|
||||
let(:commentaire) { create(:commentaire, :with_file, dossier: dossier) }
|
||||
let(:attachment) { commentaire.piece_jointe.first }
|
||||
|
||||
it "displays a generic libelle, link and renders title" do
|
||||
expect(subject).to have_text('Pièce jointe au message')
|
||||
expect(subject).to have_link(filename)
|
||||
expect(component.title).to eq("Pièce jointe au message -- #{filename}")
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue