2018-08-16 17:22:35 +02:00
|
|
|
describe 'shared/dossiers/messages/message.html.haml', type: :view do
|
2017-12-05 17:20:10 +01:00
|
|
|
before { view.extend DossierHelper }
|
|
|
|
|
2019-07-16 12:11:24 +02:00
|
|
|
subject { render 'shared/dossiers/messages/message.html.haml', commentaire: commentaire, messagerie_seen_at: seen_at, connected_user: dossier.user, show_reply_button: true }
|
2017-12-05 17:20:10 +01:00
|
|
|
|
2019-07-02 15:21:49 +02:00
|
|
|
let(:dossier) { create(:dossier, :en_construction) }
|
2017-12-05 17:20:10 +01:00
|
|
|
let(:commentaire) { create(:commentaire, dossier: dossier) }
|
|
|
|
let(:seen_at) { commentaire.created_at + 1.hour }
|
|
|
|
|
2019-07-16 12:11:24 +02:00
|
|
|
it { is_expected.to have_button("Répondre") }
|
|
|
|
|
2017-12-05 17:20:10 +01:00
|
|
|
context "with a seen_at after commentaire created_at" do
|
|
|
|
let(:seen_at) { commentaire.created_at + 1.hour }
|
|
|
|
|
|
|
|
it { is_expected.not_to have_css(".highlighted") }
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with a seen_at after commentaire created_at" do
|
|
|
|
let(:seen_at) { commentaire.created_at - 1.hour }
|
|
|
|
|
|
|
|
it { is_expected.to have_css(".highlighted") }
|
|
|
|
end
|
2020-05-12 17:58:00 +02:00
|
|
|
|
|
|
|
context 'with an instructeur message' do
|
|
|
|
let(:instructeur) { create(:instructeur) }
|
|
|
|
let(:procedure) { create(:procedure) }
|
|
|
|
let(:commentaire) { create(:commentaire, instructeur: instructeur, body: 'Second message') }
|
|
|
|
let(:dossier) { create(:dossier, :en_construction, commentaires: [commentaire], procedure: procedure) }
|
|
|
|
|
|
|
|
context 'on a procedure with anonymous instructeurs' do
|
|
|
|
before { Flipper.enable_actor(:hide_instructeur_email, procedure) }
|
|
|
|
|
|
|
|
context 'redacts the instructeur email' do
|
|
|
|
it { is_expected.to have_text(commentaire.body) }
|
|
|
|
it { is_expected.to have_text("Instructeur n° #{instructeur.id}") }
|
|
|
|
it { is_expected.not_to have_text(instructeur.email) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'on a procedure where instructeurs names are not redacted' do
|
|
|
|
before { Flipper.disable_actor(:hide_instructeur_email, procedure) }
|
|
|
|
|
|
|
|
context 'redacts the instructeur email but keeps the name' do
|
|
|
|
it { is_expected.to have_text(commentaire.body) }
|
|
|
|
it { is_expected.to have_text(instructeur.email.split('@').first) }
|
|
|
|
it { is_expected.not_to have_text(instructeur.email) }
|
|
|
|
end
|
|
|
|
end
|
2021-11-15 11:30:41 +01:00
|
|
|
|
|
|
|
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 }
|
2021-11-15 13:53:32 +01:00
|
|
|
let(:form_url) { instructeur_commentaire_path(commentaire.dossier.procedure, commentaire.dossier, commentaire) }
|
2021-11-15 11:30:41 +01:00
|
|
|
|
|
|
|
context 'on a procedure where commentaire had been written by connected instructeur' do
|
|
|
|
let(:commentaire) { create(:commentaire, instructeur: instructeur, body: 'Second message') }
|
|
|
|
|
2021-11-15 14:17:57 +01:00
|
|
|
it { is_expected.to have_selector("form[action=\"#{form_url}\"]") }
|
2021-11-15 13:53:32 +01:00
|
|
|
end
|
|
|
|
|
2021-11-16 14:28:38 +01:00
|
|
|
context 'on a procedure where commentaire had been written by connected instructeur and discarded' do
|
|
|
|
let(:commentaire) { create(:commentaire, instructeur: instructeur, body: 'Second message', discarded_at: 2.days.ago) }
|
2021-11-15 13:53:32 +01:00
|
|
|
|
2021-11-15 14:17:57 +01:00
|
|
|
it { is_expected.not_to have_selector("form[action=\"#{form_url}\"]") }
|
2021-11-16 14:28:38 +01:00
|
|
|
it { is_expected.not_to have_selector(".rich-text", text: I18n.t(t('views.shared.commentaires.destroy.deleted_body'))) }
|
2021-11-15 11:30:41 +01:00
|
|
|
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') }
|
|
|
|
|
2021-11-15 14:17:57 +01:00
|
|
|
it { is_expected.not_to have_selector("form[action=\"#{form_url}\"]") }
|
2021-11-15 11:30:41 +01:00
|
|
|
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') }
|
|
|
|
|
2021-11-15 14:17:57 +01:00
|
|
|
it { is_expected.not_to have_selector("form[action=\"#{form_url}\"]") }
|
2021-11-15 11:30:41 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'on a procedure where commentaire had been written another instructeur' do
|
|
|
|
let(:commentaire) { create(:commentaire, instructeur: create(:instructeur), body: 'Second message') }
|
|
|
|
|
2021-11-15 14:17:57 +01:00
|
|
|
it { is_expected.not_to have_selector("form[action=\"#{form_url}\"]") }
|
2021-11-15 11:30:41 +01:00
|
|
|
end
|
|
|
|
end
|
2020-05-12 17:58:00 +02:00
|
|
|
end
|
2022-03-31 15:33:59 +02:00
|
|
|
|
|
|
|
context 'with an expert message' do
|
|
|
|
describe 'delete message button for expert' do
|
|
|
|
let(:expert) { create(:expert) }
|
|
|
|
let(:procedure) { create(:procedure) }
|
|
|
|
let(:dossier) { create(:dossier, :en_construction, commentaires: [commentaire], procedure: procedure) }
|
|
|
|
let(:experts_procedure) { create(:experts_procedure, procedure: procedure, expert: expert) }
|
|
|
|
let!(:avis) { create(:avis, email: nil, experts_procedure: experts_procedure) }
|
|
|
|
subject { render 'shared/dossiers/messages/message.html.haml', commentaire: commentaire, messagerie_seen_at: seen_at, connected_user: expert, show_reply_button: true }
|
|
|
|
let(:form_url) { delete_commentaire_expert_avis_path(avis.procedure, avis, commentaire: commentaire) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
assign(:avis, avis)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'on a procedure where commentaire had been written by connected expert' do
|
|
|
|
let(:commentaire) { create(:commentaire, expert: expert, body: 'Second message') }
|
|
|
|
|
|
|
|
it { is_expected.to have_selector("form[action=\"#{form_url}\"]") }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'on a procedure where commentaire had been written by connected expert and discarded' do
|
|
|
|
let(:commentaire) { create(:commentaire, expert: expert, body: 'Second message', discarded_at: 2.days.ago) }
|
|
|
|
|
|
|
|
it { is_expected.not_to have_selector("form[action=\"#{form_url}\"]") }
|
|
|
|
it { is_expected.not_to have_selector(".rich-text", text: I18n.t(t('views.shared.commentaires.destroy.deleted_body'))) }
|
|
|
|
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_selector("form[action=\"#{form_url}\"]") }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'on a procedure where commentaire had been written by connected an instructeur' do
|
|
|
|
let(:commentaire) { create(:commentaire, instructeur: create(:instructeur), body: 'Second message') }
|
|
|
|
|
|
|
|
it { is_expected.not_to have_selector("form[action=\"#{form_url}\"]") }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'on a procedure where commentaire had been written another expert' do
|
|
|
|
let(:commentaire) { create(:commentaire, expert: create(:expert), body: 'Second message') }
|
|
|
|
|
|
|
|
it { is_expected.not_to have_selector("form[action=\"#{form_url}\"]") }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-12-05 17:20:10 +01:00
|
|
|
end
|