feat(gallery): display right tag for annotation privée
This commit is contained in:
parent
2e2d2afecb
commit
17aaa7b32c
2 changed files with 53 additions and 8 deletions
|
@ -17,7 +17,7 @@ class Attachment::GalleryItemComponent < ApplicationComponent
|
||||||
def gallery_demande? = @gallery_demande
|
def gallery_demande? = @gallery_demande
|
||||||
|
|
||||||
def libelle
|
def libelle
|
||||||
if from_dossier?
|
if from_champ?
|
||||||
attachment.record.libelle
|
attachment.record.libelle
|
||||||
elsif from_messagerie?
|
elsif from_messagerie?
|
||||||
'Pièce jointe au message'
|
'Pièce jointe au message'
|
||||||
|
@ -28,8 +28,10 @@ class Attachment::GalleryItemComponent < ApplicationComponent
|
||||||
|
|
||||||
def origin
|
def origin
|
||||||
case
|
case
|
||||||
when from_dossier?
|
when from_public_champ?
|
||||||
'Dossier usager'
|
'Dossier usager'
|
||||||
|
when from_private_champ?
|
||||||
|
'Annotation privée'
|
||||||
when from_messagerie_expert?
|
when from_messagerie_expert?
|
||||||
'Messagerie (expert)'
|
'Messagerie (expert)'
|
||||||
when from_messagerie_instructeur?
|
when from_messagerie_instructeur?
|
||||||
|
@ -64,7 +66,7 @@ class Attachment::GalleryItemComponent < ApplicationComponent
|
||||||
end
|
end
|
||||||
|
|
||||||
def updated?
|
def updated?
|
||||||
from_dossier? && updated_at > attachment.record.dossier.depose_at
|
from_public_champ? && updated_at > attachment.record.dossier.depose_at
|
||||||
end
|
end
|
||||||
|
|
||||||
def updated_at
|
def updated_at
|
||||||
|
@ -80,10 +82,18 @@ class Attachment::GalleryItemComponent < ApplicationComponent
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def from_dossier?
|
def from_champ?
|
||||||
attachment.record.class.in?([Champs::PieceJustificativeChamp, Champs::TitreIdentiteChamp])
|
attachment.record.class.in?([Champs::PieceJustificativeChamp, Champs::TitreIdentiteChamp])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def from_public_champ?
|
||||||
|
from_champ? && !attachment.record.private?
|
||||||
|
end
|
||||||
|
|
||||||
|
def from_private_champ?
|
||||||
|
from_champ? && attachment.record.private?
|
||||||
|
end
|
||||||
|
|
||||||
def from_messagerie?
|
def from_messagerie?
|
||||||
attachment.record.is_a?(Commentaire)
|
attachment.record.is_a?(Commentaire)
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,9 +4,10 @@ require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe Attachment::GalleryItemComponent, type: :component do
|
RSpec.describe Attachment::GalleryItemComponent, type: :component do
|
||||||
let(:instructeur) { create(:instructeur) }
|
let(:instructeur) { create(:instructeur) }
|
||||||
let(:procedure) { create(:procedure, :published, types_de_champ_public:) }
|
let(:procedure) { create(:procedure, :published, types_de_champ_public:, types_de_champ_private:) }
|
||||||
let(:types_de_champ_public) { [{ type: :piece_justificative }] }
|
let(:types_de_champ_public) { [{ type: :piece_justificative }] }
|
||||||
let(:dossier) { create(:dossier, :with_populated_champs, :en_construction, procedure:) }
|
let(:types_de_champ_private) { [{ type: :piece_justificative }] }
|
||||||
|
let(:dossier) { create(:dossier, :with_populated_champs, :with_populated_annotations, :en_construction, procedure:) }
|
||||||
let(:filename) { attachment.blob.filename.to_s }
|
let(:filename) { attachment.blob.filename.to_s }
|
||||||
let(:gallery_demande) { false }
|
let(:gallery_demande) { false }
|
||||||
let(:seen_at) { nil }
|
let(:seen_at) { nil }
|
||||||
|
@ -16,8 +17,10 @@ RSpec.describe Attachment::GalleryItemComponent, type: :component do
|
||||||
|
|
||||||
subject { render_inline(component).to_html }
|
subject { render_inline(component).to_html }
|
||||||
|
|
||||||
context "when attachment is from a piece justificative champ" do
|
context "when attachment is from a public piece justificative champ" do
|
||||||
let(:champ) { dossier.champs.first }
|
let(:champ) do
|
||||||
|
dossier.champs.where(private: false).first
|
||||||
|
end
|
||||||
let(:libelle) { champ.libelle }
|
let(:libelle) { champ.libelle }
|
||||||
let(:attachment) { champ.piece_justificative_file.attachments.first }
|
let(:attachment) { champ.piece_justificative_file.attachments.first }
|
||||||
|
|
||||||
|
@ -56,6 +59,38 @@ RSpec.describe Attachment::GalleryItemComponent, type: :component do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "when attachment is from a private piece justificative champ" do
|
||||||
|
let(:annotation) do
|
||||||
|
dossier.champs.where(private: true).first
|
||||||
|
end
|
||||||
|
let(:libelle) { annotation.libelle }
|
||||||
|
let(:attachment) { annotation.piece_justificative_file.attachments.first }
|
||||||
|
|
||||||
|
# Correspond au cas standard où le blob est créé avant le dépôt du dossier
|
||||||
|
before { dossier.touch(:depose_at) }
|
||||||
|
|
||||||
|
it "displays libelle, link, tag and renders title" do
|
||||||
|
expect(subject).to have_text(libelle)
|
||||||
|
expect(subject).to have_link(filename)
|
||||||
|
expect(subject).to have_text('Annotation privée')
|
||||||
|
expect(component.title).to eq("#{libelle} -- #{filename}")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "displays when gallery item has been added" do
|
||||||
|
expect(subject).to have_text('Ajoutée le')
|
||||||
|
expect(subject).not_to have_css('.highlighted')
|
||||||
|
expect(subject).to have_text(component.helpers.try_format_datetime(attachment.record.created_at, format: :veryshort))
|
||||||
|
end
|
||||||
|
|
||||||
|
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
|
||||||
|
end
|
||||||
|
|
||||||
context "when attachment is from a commentaire" do
|
context "when attachment is from a commentaire" do
|
||||||
let(:commentaire) { create(:commentaire, :with_file, dossier: dossier) }
|
let(:commentaire) { create(:commentaire, :with_file, dossier: dossier) }
|
||||||
let(:attachment) { commentaire.piece_jointe.first }
|
let(:attachment) { commentaire.piece_jointe.first }
|
||||||
|
|
Loading…
Reference in a new issue