2023-02-21 11:42:30 +01:00
|
|
|
describe DossierSectionsConcern do
|
|
|
|
describe '#auto_numbering_section_headers_for?' do
|
|
|
|
let(:public_libelle) { "Infos" }
|
|
|
|
let(:private_libelle) { "Infos Private" }
|
|
|
|
let(:types_de_champ_public) { [{ type: :header_section, libelle: public_libelle }, { type: :header_section, libelle: "Details" }] }
|
|
|
|
let(:types_de_champ_private) { [{ type: :header_section, libelle: private_libelle }, { type: :header_section, libelle: "Details Private" }] }
|
|
|
|
|
|
|
|
let(:procedure) { create(:procedure, :for_individual, types_de_champ_public:, types_de_champ_private:) }
|
|
|
|
let(:dossier) { create(:dossier, procedure: procedure) }
|
|
|
|
|
2024-03-14 13:34:20 +01:00
|
|
|
let(:public_type_de_champ) { dossier.types_de_champ_public[1] }
|
|
|
|
let(:private_type_de_champ) { dossier.types_de_champ_private[1] }
|
|
|
|
|
2023-02-21 11:42:30 +01:00
|
|
|
context "with no section having number" do
|
2024-03-14 13:34:20 +01:00
|
|
|
it { expect(dossier.auto_numbering_section_headers_for?(public_type_de_champ)).to eq(true) }
|
|
|
|
it { expect(dossier.auto_numbering_section_headers_for?(private_type_de_champ)).to eq(true) }
|
2023-02-21 11:42:30 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context "with public section having number" do
|
|
|
|
let(:public_libelle) { "1 - infos" }
|
2024-03-14 13:34:20 +01:00
|
|
|
it { expect(dossier.auto_numbering_section_headers_for?(public_type_de_champ)).to eq(false) }
|
|
|
|
it { expect(dossier.auto_numbering_section_headers_for?(private_type_de_champ)).to eq(true) }
|
2023-02-21 11:42:30 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context "with private section having number" do
|
|
|
|
let(:private_libelle) { "1 - infos private" }
|
2024-03-14 13:34:20 +01:00
|
|
|
it { expect(dossier.auto_numbering_section_headers_for?(public_type_de_champ)).to eq(true) }
|
|
|
|
it { expect(dossier.auto_numbering_section_headers_for?(private_type_de_champ)).to eq(false) }
|
2023-02-21 11:42:30 +01:00
|
|
|
end
|
2023-03-09 16:15:56 +01:00
|
|
|
|
|
|
|
context "header_section in a repetition are not auto-numbered" do
|
|
|
|
let(:types_de_champ_public) { [{ type: :header_section, libelle: public_libelle }, { type: :repetition, mandatory: true, children: [{ type: :header_section, libelle: "Enfant" }, { type: :text }] }] }
|
|
|
|
|
2024-03-14 13:34:20 +01:00
|
|
|
let(:public_type_de_champ) { dossier.revision.children_of(dossier.types_de_champ_public[1]).first }
|
|
|
|
|
2023-03-09 16:15:56 +01:00
|
|
|
context "with parent section having headers with number" do
|
|
|
|
let(:public_libelle) { "1. Infos" }
|
2024-03-14 13:34:20 +01:00
|
|
|
it { expect(dossier.auto_numbering_section_headers_for?(public_type_de_champ)).to eq(false) }
|
2023-03-09 16:15:56 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context "with parent section having headers without number" do
|
|
|
|
let(:public_libelle) { "infos" }
|
2024-03-14 13:34:20 +01:00
|
|
|
it { expect(dossier.auto_numbering_section_headers_for?(public_type_de_champ)).to eq(false) }
|
2023-03-09 16:15:56 +01:00
|
|
|
end
|
|
|
|
end
|
2023-02-21 11:42:30 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#index_for_section_header' do
|
|
|
|
include Logic
|
|
|
|
let(:number_stable_id) { 99 }
|
|
|
|
let(:types_de_champ) {
|
|
|
|
[
|
|
|
|
{ type: :header_section, libelle: "Infos" }, { type: :integer_number, stable_id: number_stable_id },
|
|
|
|
{ type: :header_section, libelle: "Details", condition: ds_eq(champ_value(99), constant(5)) }, { type: :header_section, libelle: "Conclusion" }
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
let(:procedure) { create(:procedure, :for_individual, types_de_champ_public: types_de_champ) }
|
|
|
|
let(:dossier) { create(:dossier, procedure: procedure) }
|
|
|
|
|
2024-03-14 13:34:20 +01:00
|
|
|
let(:headers) { dossier.revision.types_de_champ_public.filter(&:header_section?) }
|
2023-02-21 11:42:30 +01:00
|
|
|
|
|
|
|
let(:number_value) { nil }
|
|
|
|
|
|
|
|
before do
|
2024-03-14 13:34:20 +01:00
|
|
|
dossier.champs.find { _1.stable_id == number_stable_id }.update(value: number_value)
|
2023-02-21 11:42:30 +01:00
|
|
|
dossier.reload
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when there are invisible sections" do
|
|
|
|
it "index accordingly header sections" do
|
|
|
|
expect(dossier.index_for_section_header(headers[0])).to eq(1)
|
2024-03-14 13:34:20 +01:00
|
|
|
expect(dossier.project_champ(headers[1], nil)).not_to be_visible
|
2023-02-21 11:42:30 +01:00
|
|
|
expect(dossier.index_for_section_header(headers[2])).to eq(2)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when all headers are visible" do
|
|
|
|
let(:number_value) { 5 }
|
|
|
|
it "index accordingly header sections" do
|
|
|
|
expect(dossier.index_for_section_header(headers[0])).to eq(1)
|
2024-03-14 13:34:20 +01:00
|
|
|
expect(dossier.project_champ(headers[1], nil)).to be_visible
|
2023-02-21 11:42:30 +01:00
|
|
|
expect(dossier.index_for_section_header(headers[1])).to eq(2)
|
|
|
|
expect(dossier.index_for_section_header(headers[2])).to eq(3)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|