2024-04-29 00:17:15 +02:00
|
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2020-05-27 11:25:43 +02:00
|
|
|
|
RSpec.describe ProcedureHelper, type: :helper do
|
2022-05-24 11:39:03 +02:00
|
|
|
|
describe '#procedure_auto_archive_datetime' do
|
|
|
|
|
let(:auto_archive_date) { Time.zone.local(2020, 8, 2, 12, 00) }
|
|
|
|
|
let(:procedure) { build(:procedure, auto_archive_on: auto_archive_date) }
|
2020-05-27 11:25:43 +02:00
|
|
|
|
|
2022-05-24 11:39:03 +02:00
|
|
|
|
subject { procedure_auto_archive_datetime(procedure) }
|
2020-05-27 11:25:43 +02:00
|
|
|
|
|
2022-05-24 11:39:03 +02:00
|
|
|
|
it "displays the day before the auto archive date (to account for the '23h59' ending time)" do
|
|
|
|
|
expect(subject).to have_text("1 août 2020 à 23 h 59 (heure de Paris)")
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2023-07-18 14:49:30 +02:00
|
|
|
|
describe 'can_send_groupe_message?' do
|
|
|
|
|
let(:procedure) { create(:procedure, groupe_instructeurs: [gi1, gi2]) }
|
|
|
|
|
let(:current_instructeur) { create(:instructeur) }
|
|
|
|
|
subject { can_send_groupe_message?(procedure) }
|
|
|
|
|
|
|
|
|
|
context 'when current_instructeur is in all procedure.groupes_instructeur' do
|
|
|
|
|
let(:gi1) { create(:groupe_instructeur, instructeurs: [current_instructeur]) }
|
|
|
|
|
let(:gi2) { create(:groupe_instructeur, instructeurs: [current_instructeur]) }
|
|
|
|
|
it { is_expected.to be_truthy }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when current_instructeur is in all procedure.groupes_instructeur' do
|
|
|
|
|
let(:instructeur2) { create(:instructeur) }
|
|
|
|
|
let(:gi1) { create(:groupe_instructeur, instructeurs: [current_instructeur]) }
|
|
|
|
|
let(:gi2) { create(:groupe_instructeur, instructeurs: [instructeur2]) }
|
|
|
|
|
|
|
|
|
|
it { is_expected.to be_falsy }
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2022-05-24 11:39:03 +02:00
|
|
|
|
describe '#estimated_fill_duration_minutes' do
|
2022-10-29 12:43:37 +02:00
|
|
|
|
subject { estimated_fill_duration_minutes(procedure.reload) }
|
2022-05-24 11:39:03 +02:00
|
|
|
|
|
|
|
|
|
context 'with champs' do
|
2024-01-23 09:52:20 +01:00
|
|
|
|
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :yes_no }, { type: :piece_justificative }]) }
|
2022-05-24 11:39:03 +02:00
|
|
|
|
|
|
|
|
|
it 'rounds up the duration to the minute' do
|
2024-06-25 17:17:51 +02:00
|
|
|
|
expect(subject).to eq(3)
|
2022-05-24 11:39:03 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'without champs' do
|
2022-10-29 12:43:37 +02:00
|
|
|
|
let(:procedure) { create(:procedure) }
|
2022-05-24 11:39:03 +02:00
|
|
|
|
|
|
|
|
|
it 'never displays ‘zero minutes’' do
|
|
|
|
|
expect(subject).to eq(1)
|
|
|
|
|
end
|
|
|
|
|
end
|
2020-05-27 11:25:43 +02:00
|
|
|
|
end
|
|
|
|
|
end
|