2020-02-13 11:07:10 +01:00
|
|
|
describe Champs::HeaderSectionChamp do
|
|
|
|
describe '#section_index' do
|
|
|
|
let(:types_de_champ) do
|
|
|
|
[
|
2022-08-04 11:39:07 +02:00
|
|
|
{ type: :header_section },
|
|
|
|
{ type: :civilite },
|
|
|
|
{ type: :text },
|
|
|
|
{ type: :header_section },
|
|
|
|
{ type: :email }
|
2020-02-13 11:07:10 +01:00
|
|
|
]
|
|
|
|
end
|
2022-08-04 11:39:07 +02:00
|
|
|
let(:types_de_champ_public) { types_de_champ }
|
|
|
|
let(:procedure) { create(:procedure, types_de_champ_public: types_de_champ_public) }
|
|
|
|
let(:dossier) { create(:dossier, procedure: procedure) }
|
2020-02-13 11:07:10 +01:00
|
|
|
|
2020-02-17 17:11:17 +01:00
|
|
|
context 'for root-level champs' do
|
2022-08-04 11:39:07 +02:00
|
|
|
let(:first_header) { dossier.champs.first }
|
|
|
|
let(:second_header) { dossier.champs.fourth }
|
2020-02-17 17:11:17 +01:00
|
|
|
|
|
|
|
it 'returns the index of the section (starting from 1)' do
|
|
|
|
expect(first_header.section_index).to eq 1
|
|
|
|
expect(second_header.section_index).to eq 2
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for repetition champs' do
|
2022-08-04 11:39:07 +02:00
|
|
|
let(:types_de_champ_public) { [{ type: :repetition, children: types_de_champ }] }
|
2020-02-17 17:11:17 +01:00
|
|
|
|
2022-08-04 11:39:07 +02:00
|
|
|
let(:first_header) { dossier.champs.first.champs.first }
|
|
|
|
let(:second_header) { dossier.champs.first.champs.fourth }
|
2022-05-13 17:06:59 +02:00
|
|
|
|
2020-02-17 17:11:17 +01:00
|
|
|
it 'returns the index of the section in the repetition (starting from 1)' do
|
|
|
|
expect(first_header.section_index).to eq 1
|
|
|
|
expect(second_header.section_index).to eq 2
|
|
|
|
end
|
2020-02-13 11:07:10 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|