2017-12-14 17:10:13 +01:00
|
|
|
|
RSpec.describe CommentaireHelper, type: :helper do
|
2018-09-06 18:13:14 +02:00
|
|
|
|
let(:commentaire) { create(:commentaire, email: "michel@pref.fr") }
|
2017-12-14 17:10:13 +01:00
|
|
|
|
|
2018-09-06 18:13:14 +02:00
|
|
|
|
describe ".commentaire_is_from_me_class" do
|
2017-12-14 17:10:13 +01:00
|
|
|
|
subject { commentaire_is_from_me_class(commentaire, me) }
|
|
|
|
|
|
|
|
|
|
context "when commentaire is from me" do
|
2018-09-11 18:40:10 +02:00
|
|
|
|
let(:me) { User.new(email: "michel@pref.fr") }
|
2017-12-14 17:10:13 +01:00
|
|
|
|
it { is_expected.to eq("from-me") }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context "when commentaire is not from me" do
|
2018-09-11 18:40:10 +02:00
|
|
|
|
let(:me) { User.new(email: "roger@usager.fr") }
|
2017-12-14 17:10:13 +01:00
|
|
|
|
it { is_expected.to eq nil }
|
|
|
|
|
end
|
|
|
|
|
end
|
2018-09-06 15:04:43 +02:00
|
|
|
|
|
2018-09-11 18:40:10 +02:00
|
|
|
|
describe '.commentaire_answer_action' do
|
|
|
|
|
subject { commentaire_answer_action(commentaire, me) }
|
|
|
|
|
|
|
|
|
|
context "when commentaire is from me" do
|
|
|
|
|
let(:me) { User.new(email: "michel@pref.fr") }
|
|
|
|
|
it { is_expected.to include('Envoyer') }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context "when commentaire is not from me" do
|
|
|
|
|
let(:me) { User.new(email: "roger@usager.fr") }
|
|
|
|
|
it { is_expected.to include('Répondre') }
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2018-09-06 16:08:24 +02:00
|
|
|
|
describe '.commentaire_is_from_guest' do
|
2019-07-02 15:21:49 +02:00
|
|
|
|
let(:dossier) { create(:dossier, :en_instruction) }
|
2018-10-10 09:23:08 +02:00
|
|
|
|
let!(:guest) { create(:invite, dossier: dossier) }
|
2018-09-06 16:08:24 +02:00
|
|
|
|
|
|
|
|
|
subject { commentaire_is_from_guest(commentaire) }
|
|
|
|
|
|
|
|
|
|
context 'when the commentaire sender is not a guest' do
|
|
|
|
|
let(:commentaire) { create(:commentaire, dossier: dossier, email: "michel@pref.fr") }
|
|
|
|
|
it { is_expected.to be false }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when the commentaire sender is a guest on this dossier' do
|
|
|
|
|
let(:commentaire) { create(:commentaire, dossier: dossier, email: guest.email) }
|
|
|
|
|
it { is_expected.to be true }
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2018-09-06 15:04:43 +02:00
|
|
|
|
describe '.commentaire_date' do
|
2018-10-25 15:24:31 +02:00
|
|
|
|
let(:present_date) { Time.zone.local(2018, 9, 2, 10, 5, 0) }
|
2018-09-06 15:04:43 +02:00
|
|
|
|
let(:creation_date) { present_date }
|
|
|
|
|
let(:commentaire) do
|
|
|
|
|
Timecop.freeze(creation_date) { create(:commentaire, email: "michel@pref.fr") }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
subject do
|
|
|
|
|
Timecop.freeze(present_date) { commentaire_date(commentaire) }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'doesn’t include the creation year' do
|
|
|
|
|
expect(subject).to eq 'le 2 septembre à 10 h 05'
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when displaying a commentaire created on a previous year' do
|
|
|
|
|
let(:creation_date) { present_date.prev_year }
|
|
|
|
|
it 'includes the creation year' do
|
|
|
|
|
expect(subject).to eq 'le 2 septembre 2017 à 10 h 05'
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when formatting the first day of the month' do
|
2018-10-25 15:24:31 +02:00
|
|
|
|
let(:present_date) { Time.zone.local(2018, 9, 1, 10, 5, 0) }
|
2018-09-06 15:04:43 +02:00
|
|
|
|
it 'includes the ordinal' do
|
|
|
|
|
expect(subject).to eq 'le 1er septembre à 10 h 05'
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2017-12-14 17:10:13 +01:00
|
|
|
|
end
|