2017-12-05 17:20:10 +01:00
|
|
|
RSpec.describe DossierHelper, type: :helper do
|
|
|
|
describe ".highlight_if_unseen_class" do
|
2018-10-25 15:07:15 +02:00
|
|
|
let(:seen_at) { Time.zone.now }
|
2017-12-05 17:20:10 +01:00
|
|
|
|
|
|
|
subject { highlight_if_unseen_class(seen_at, updated_at) }
|
|
|
|
|
|
|
|
context "when commentaire date is created before last seen datetime" do
|
|
|
|
let(:updated_at) { seen_at - 2.days }
|
|
|
|
|
|
|
|
it { is_expected.to eq nil }
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when commentaire date is created after last seen datetime" do
|
|
|
|
let(:updated_at) { seen_at + 2.hours }
|
|
|
|
|
|
|
|
it { is_expected.to eq "highlighted" }
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when there is no last seen datetime" do
|
2018-10-25 15:07:15 +02:00
|
|
|
let(:updated_at) { Time.zone.now }
|
2017-12-05 17:20:10 +01:00
|
|
|
let(:seen_at) { nil }
|
|
|
|
|
|
|
|
it { is_expected.to eq nil }
|
|
|
|
end
|
|
|
|
end
|
2018-06-25 18:07:16 +02:00
|
|
|
|
2018-06-28 17:19:22 +02:00
|
|
|
describe ".url_for_dossier" do
|
|
|
|
subject { url_for_dossier(dossier) }
|
|
|
|
|
|
|
|
context "when the dossier is in the brouillon state" do
|
2018-08-28 14:10:55 +02:00
|
|
|
let(:dossier) { create(:dossier, state: Dossier.states.fetch(:brouillon)) }
|
2018-09-06 09:09:23 +02:00
|
|
|
it { is_expected.to eq "/dossiers/#{dossier.id}/brouillon" }
|
2018-06-28 17:19:22 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
context "when the dossier is any other state" do
|
2018-08-28 14:10:55 +02:00
|
|
|
let(:dossier) { create(:dossier, state: Dossier.states.fetch(:en_construction)) }
|
2018-09-27 16:52:17 +02:00
|
|
|
it { is_expected.to eq "/dossiers/#{dossier.id}" }
|
2018-06-28 17:19:22 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-04-09 14:09:39 +02:00
|
|
|
describe ".demandeur_dossier" do
|
|
|
|
subject { demandeur_dossier(dossier) }
|
|
|
|
|
|
|
|
let(:individual) { create(:individual) }
|
|
|
|
let(:etablissement) { create(:etablissement) }
|
|
|
|
let(:dossier) { create(:dossier, procedure: procedure, individual: individual, etablissement: etablissement) }
|
|
|
|
|
|
|
|
context "when the dossier is for an individual" do
|
|
|
|
let(:procedure) { create(:simple_procedure, :for_individual) }
|
|
|
|
|
|
|
|
context "when the individual is not provided" do
|
|
|
|
let(:individual) { nil }
|
|
|
|
it { is_expected.to be_blank }
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when the individual has name information" do
|
|
|
|
it { is_expected.to eq "#{individual.nom} #{individual.prenom}" }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when the dossier is for a company" do
|
|
|
|
let(:procedure) { create(:procedure, for_individual: false) }
|
|
|
|
|
|
|
|
context "when the company is not provided" do
|
|
|
|
let(:etablissement) { nil }
|
|
|
|
it { is_expected.to be_blank }
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when the company has name information" do
|
|
|
|
it { is_expected.to eq raison_sociale_or_name(etablissement) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-06-25 18:07:16 +02:00
|
|
|
describe ".dossier_submission_is_closed?" do
|
|
|
|
let(:dossier) { create(:dossier, state: state) }
|
2018-08-28 14:10:55 +02:00
|
|
|
let(:state) { Dossier.states.fetch(:brouillon) }
|
2018-06-25 18:07:16 +02:00
|
|
|
|
|
|
|
subject { dossier_submission_is_closed?(dossier) }
|
|
|
|
|
|
|
|
context "when dossier state is brouillon" do
|
|
|
|
it { is_expected.to be false }
|
|
|
|
|
2019-11-14 09:43:45 +01:00
|
|
|
context "when dossier state is brouillon and procedure is close" do
|
|
|
|
before { dossier.procedure.close }
|
2018-06-25 18:07:16 +02:00
|
|
|
|
|
|
|
it { is_expected.to be true }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for "returns false" do
|
|
|
|
it { is_expected.to be false }
|
|
|
|
|
2019-11-14 09:43:45 +01:00
|
|
|
context "and procedure is close" do
|
|
|
|
before { dossier.procedure.close }
|
2018-06-25 18:07:16 +02:00
|
|
|
|
|
|
|
it { is_expected.to be false }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when dossier state is en_construction" do
|
2018-08-28 14:10:55 +02:00
|
|
|
let(:state) { Dossier.states.fetch(:en_construction) }
|
2018-06-25 18:07:16 +02:00
|
|
|
|
|
|
|
it_behaves_like "returns false"
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when dossier state is en_construction" do
|
2018-08-28 14:10:55 +02:00
|
|
|
let(:state) { Dossier.states.fetch(:en_instruction) }
|
2018-06-25 18:07:16 +02:00
|
|
|
|
|
|
|
it_behaves_like "returns false"
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when dossier state is en_construction" do
|
2018-08-28 14:10:55 +02:00
|
|
|
let(:state) { Dossier.states.fetch(:accepte) }
|
2018-06-25 18:07:16 +02:00
|
|
|
|
|
|
|
it_behaves_like "returns false"
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when dossier state is en_construction" do
|
2018-08-28 14:10:55 +02:00
|
|
|
let(:state) { Dossier.states.fetch(:refuse) }
|
2018-06-25 18:07:16 +02:00
|
|
|
|
|
|
|
it_behaves_like "returns false"
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when dossier state is en_construction" do
|
2018-08-28 14:10:55 +02:00
|
|
|
let(:state) { Dossier.states.fetch(:sans_suite) }
|
2018-06-25 18:07:16 +02:00
|
|
|
|
|
|
|
it_behaves_like "returns false"
|
|
|
|
end
|
|
|
|
end
|
2018-11-06 18:44:32 +01:00
|
|
|
|
|
|
|
describe '.dossier_display_state' do
|
|
|
|
let(:dossier) { create(:dossier) }
|
|
|
|
|
|
|
|
subject { dossier_display_state(dossier) }
|
|
|
|
|
|
|
|
it 'brouillon is brouillon' do
|
|
|
|
dossier.brouillon!
|
|
|
|
expect(subject).to eq('Brouillon')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'en_construction is En construction' do
|
|
|
|
dossier.en_construction!
|
|
|
|
expect(subject).to eq('En construction')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'accepte is traité' do
|
|
|
|
dossier.accepte!
|
|
|
|
expect(subject).to eq('Accepté')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'en_instruction is reçu' do
|
|
|
|
dossier.en_instruction!
|
|
|
|
expect(subject).to eq('En instruction')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'sans_suite is traité' do
|
|
|
|
dossier.sans_suite!
|
2020-07-06 09:30:07 +02:00
|
|
|
expect(subject).to eq('Classé sans suite')
|
2018-11-06 18:44:32 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'refuse is traité' do
|
|
|
|
dossier.refuse!
|
|
|
|
expect(subject).to eq('Refusé')
|
|
|
|
end
|
|
|
|
|
2019-12-19 13:22:40 +01:00
|
|
|
context 'when requesting lowercase' do
|
2018-11-06 18:44:32 +01:00
|
|
|
subject { dossier_display_state(dossier, lower: true) }
|
|
|
|
|
2019-12-19 13:22:40 +01:00
|
|
|
it 'lowercases the display name' do
|
2018-11-06 18:44:32 +01:00
|
|
|
dossier.brouillon!
|
|
|
|
expect(subject).to eq('brouillon')
|
|
|
|
end
|
2019-12-19 13:22:40 +01:00
|
|
|
end
|
2018-11-06 18:44:32 +01:00
|
|
|
|
2019-12-19 13:22:40 +01:00
|
|
|
context 'when providing directly a state name' do
|
|
|
|
subject { dossier_display_state(:brouillon) }
|
2018-11-06 18:44:32 +01:00
|
|
|
|
2019-12-19 13:22:40 +01:00
|
|
|
it 'generates a display name for the given state' do
|
|
|
|
expect(subject).to eq('Brouillon')
|
2018-11-06 18:44:32 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-11-07 14:46:22 +01:00
|
|
|
|
|
|
|
describe '.dossier_legacy_state' do
|
|
|
|
subject { dossier_legacy_state(dossier) }
|
|
|
|
|
|
|
|
context 'when the dossier is en instruction' do
|
|
|
|
let(:dossier) { create(:dossier) }
|
|
|
|
|
|
|
|
it { is_expected.to eq('brouillon') }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the dossier is en instruction' do
|
|
|
|
let(:dossier) { create(:dossier, :en_instruction) }
|
|
|
|
|
|
|
|
it { is_expected.to eq('received') }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the dossier is accepte' do
|
|
|
|
let(:dossier) { create(:dossier, state: Dossier.states.fetch(:accepte)) }
|
|
|
|
|
|
|
|
it { is_expected.to eq('closed') }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the dossier is refuse' do
|
|
|
|
let(:dossier) { create(:dossier, state: Dossier.states.fetch(:refuse)) }
|
|
|
|
|
|
|
|
it { is_expected.to eq('refused') }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the dossier is sans_suite' do
|
|
|
|
let(:dossier) { create(:dossier, state: Dossier.states.fetch(:sans_suite)) }
|
|
|
|
|
|
|
|
it { is_expected.to eq('without_continuation') }
|
|
|
|
end
|
|
|
|
end
|
2017-12-05 17:20:10 +01:00
|
|
|
end
|