feat(gallery): add origin tag to gallery item
This commit is contained in:
parent
df08617387
commit
bc237152e7
3 changed files with 49 additions and 7 deletions
|
@ -16,7 +16,34 @@ class Attachment::GalleryItemComponent < ApplicationComponent
|
|||
def gallery_demande? = @gallery_demande
|
||||
|
||||
def libelle
|
||||
attachment.record.class.in?([Champs::PieceJustificativeChamp, Champs::TitreIdentiteChamp]) ? attachment.record.libelle : 'Pièce jointe au message'
|
||||
from_dossier? ? attachment.record.libelle : 'Pièce jointe au message'
|
||||
end
|
||||
|
||||
def from_dossier?
|
||||
attachment.record.class.in?([Champs::PieceJustificativeChamp, Champs::TitreIdentiteChamp])
|
||||
end
|
||||
|
||||
def from_messagerie?
|
||||
attachment.record.is_a?(Commentaire)
|
||||
end
|
||||
|
||||
def from_messagerie_instructeur?
|
||||
from_messagerie? && attachment.record.instructeur.present?
|
||||
end
|
||||
|
||||
def from_messagerie_usager?
|
||||
from_messagerie? && attachment.record.instructeur.nil?
|
||||
end
|
||||
|
||||
def origin
|
||||
case
|
||||
when from_dossier?
|
||||
'Dossier usager'
|
||||
when from_messagerie_instructeur?
|
||||
'Messagerie (instructeur)'
|
||||
when from_messagerie_usager?
|
||||
'Messagerie (usager)'
|
||||
end
|
||||
end
|
||||
|
||||
def title
|
||||
|
@ -40,7 +67,7 @@ class Attachment::GalleryItemComponent < ApplicationComponent
|
|||
end
|
||||
|
||||
def updated?
|
||||
attachment.record.class.in?([Champs::PieceJustificativeChamp, Champs::TitreIdentiteChamp]) && updated_at > attachment.record.dossier.depose_at
|
||||
from_dossier? && updated_at > attachment.record.dossier.depose_at
|
||||
end
|
||||
|
||||
def updated_at
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
.gallery-item
|
||||
- if !gallery_demande?
|
||||
.fr-mb-1v
|
||||
.fr-tag
|
||||
= origin
|
||||
.fr-mb-2v.champ-updated{ class: badge_updated_class }
|
||||
= t(updated? ? '.updated_at' : '.created_at', datetime: helpers.try_format_datetime(updated_at, format: :veryshort))
|
||||
- if displayable_pdf?(blob) || displayable_image?(blob)
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Attachment::GalleryItemComponent, type: :component do
|
||||
let(:instructeur) { create(:instructeur) }
|
||||
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:) }
|
||||
|
@ -18,10 +19,11 @@ RSpec.describe Attachment::GalleryItemComponent, type: :component do
|
|||
let(:libelle) { champ.libelle }
|
||||
let(:attachment) { champ.piece_justificative_file.attachments.first }
|
||||
|
||||
it "displays libelle, link and renders title" do
|
||||
it "displays libelle, link, tag 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(subject).to have_text('Dossier usager')
|
||||
expect(component.title).to eq("#{libelle} -- #{filename}")
|
||||
end
|
||||
|
||||
|
@ -42,10 +44,20 @@ RSpec.describe Attachment::GalleryItemComponent, type: :component 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
|
||||
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
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue