wip(dossiers/messages/_message): poc destroy button with expected ACL support

This commit is contained in:
Martin 2021-11-15 11:30:41 +01:00
parent f250a750fd
commit b03dc6ad5d
4 changed files with 39 additions and 1 deletions

View file

@ -75,7 +75,7 @@ class Commentaire < ApplicationRecord
end
def sent_by?(someone)
email == someone.email
email == someone&.email
end
def file_url

View file

@ -11,6 +11,8 @@
.rich-text= pretty_commentaire(commentaire)
.message-extras.flex.justify-start
- if commentaire.sent_by?(connected_user) && commentaire.sent_by_instructeur?
%div{"data-test-delete-id" => 1} Suppr
- if commentaire.piece_jointe.attached?
.attachment-link
= render partial: "shared/attachment/show", locals: { attachment: commentaire.piece_jointe.attachment }

View file

@ -382,6 +382,11 @@ describe Instructeurs::DossiersController, type: :controller do
end
end
describe '#messagerie' do
subject { get :messagerie, params: { procedure_id: procedure.id, dossier_id: dossier.id } }
it { expect(response).to have_http_status(:ok) }
end
describe "#create_commentaire" do
let(:saved_commentaire) { dossier.commentaires.first }
let(:body) { "avant\napres" }

View file

@ -46,5 +46,36 @@ describe 'shared/dossiers/messages/message.html.haml', type: :view do
it { is_expected.not_to have_text(instructeur.email) }
end
end
describe 'delete message button for instructeur' do
let(:instructeur) { create(:instructeur) }
let(:procedure) { create(:procedure) }
let(:dossier) { create(:dossier, :en_construction, commentaires: [commentaire], procedure: procedure) }
subject { render 'shared/dossiers/messages/message.html.haml', commentaire: commentaire, messagerie_seen_at: seen_at, connected_user: instructeur, show_reply_button: true }
context 'on a procedure where commentaire had been written by connected instructeur' do
let(:commentaire) { create(:commentaire, instructeur: instructeur, body: 'Second message') }
it { is_expected.to have_css("div[data-test-delete-id=1]")}
end
context 'on a procedure where commentaire had been written by connected an user' do
let(:commentaire) { create(:commentaire, email: create(:user).email, body: 'Second message') }
it { is_expected.not_to have_css("div[data-test-delete-id=1]")}
end
context 'on a procedure where commentaire had been written by connected an expert' do
let(:commentaire) { create(:commentaire, expert: create(:expert), body: 'Second message') }
it { is_expected.not_to have_css("div[data-test-delete-id=1]")}
end
context 'on a procedure where commentaire had been written another instructeur' do
let(:commentaire) { create(:commentaire, instructeur: create(:instructeur), body: 'Second message') }
it { is_expected.not_to have_css("div[data-test-delete-id=1]")}
end
end
end
end