This commit is contained in:
simon lehericey 2022-05-13 17:06:59 +02:00
parent 419d853d1d
commit fd4d543b20
4 changed files with 47 additions and 25 deletions

View file

@ -74,7 +74,12 @@ describe Champ do
create(:procedure, :with_type_de_champ, :with_type_de_champ_private, :with_repetition, types_de_champ_count: 1, types_de_champ_private_count: 1).tap do |procedure|
create(:type_de_champ_header_section, procedure: procedure)
create(:type_de_champ_header_section, procedure: procedure, private: true)
create(:type_de_champ_header_section, parent: procedure.types_de_champ.find(&:repetition?))
procedure.active_revision.add_type_de_champ(
libelle: 'header',
type_champ: 'header_section',
parent_id: procedure.types_de_champ.find(&:repetition?).stable_id
)
end
end
let(:dossier) { create(:dossier, procedure: procedure) }
@ -508,11 +513,9 @@ describe Champ do
end
describe 'repetition' do
let(:procedure) { create(:procedure, :published, :with_type_de_champ, :with_type_de_champ_private, types_de_champ: [build(:type_de_champ_repetition, types_de_champ: [tdc_text, tdc_integer])]) }
let(:revision) { procedure.published_revision }
let(:rtdc_repetition) { revision.revision_types_de_champ.find { |rtdc| rtdc.type_de_champ.repetition? } }
let(:tdc_text) { build(:type_de_champ_text) }
let(:tdc_integer) { build(:type_de_champ_integer_number) }
let(:procedure) { create(:procedure, :published, :with_type_de_champ, :with_type_de_champ_private, :with_repetition) }
let(:tdc_repetition) { procedure.types_de_champ.find(&:repetition?) }
let(:tdc_text) { procedure.active_revision.children_of(tdc_repetition).first }
let(:dossier) { create(:dossier, procedure: procedure) }
let(:champ) { dossier.champs.find(&:repetition?) }
@ -521,8 +524,7 @@ describe Champ do
let(:champ_text_attrs) { attributes_for(:champ_text, type_de_champ: tdc_text, row: 1) }
before do
create(:procedure_revision_type_de_champ, revision: revision, type_de_champ: tdc_text, parent: rtdc_repetition, position: 1)
create(:procedure_revision_type_de_champ, revision: revision, type_de_champ: tdc_integer, parent: rtdc_repetition, position: 0)
procedure.active_revision.add_type_de_champ(libelle: 'sub integer', type_champ: 'integer_number', parent_id: tdc_repetition.stable_id)
end
context 'when creating the model directly' do
@ -557,12 +559,12 @@ describe Champ do
champ.champs << champ_integer
first_row = champ.reload.rows.first
expect(first_row.size).to eq(2)
expect(first_row.first).to eq(champ_integer)
expect(first_row.second).to eq(champ_integer)
champ.champs << champ_text
first_row = champ.reload.rows.first
expect(first_row.size).to eq(2)
expect(first_row.second).to eq(champ_text)
expect(first_row.first).to eq(champ_text)
expect(champ.rows.size).to eq(2)
end

View file

@ -23,12 +23,26 @@ describe Champs::HeaderSectionChamp do
end
context 'for repetition champs' do
let(:procedure) { create(:procedure, types_de_champ: [build(:type_de_champ_repetition, types_de_champ: types_de_champ)]) }
let(:procedure) { create(:procedure, :with_repetition) }
let(:dossier) { create(:dossier, procedure: procedure) }
let(:first_header) { dossier.champs.first.champs[0] }
let(:second_header) { dossier.champs.first.champs[3] }
before do
revision = procedure.active_revision
tdc_repetition = revision.types_de_champ_public.first
revision.remove_type_de_champ(revision.children_of(tdc_repetition))
types_de_champ.each do |tdc|
revision.add_type_de_champ(
libelle: tdc.libelle,
type_champ: tdc.type_champ,
parent_id: tdc_repetition.stable_id
)
end
end
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

View file

@ -161,19 +161,23 @@ describe TagsSubstitutionConcern, type: :model do
context 'when the procedure has a type de champ repetition' do
let(:template) { '--Répétition--' }
let(:types_de_champ) do
[
build(:type_de_champ_repetition, libelle: 'Répétition', types_de_champ: [
build(:type_de_champ_text, libelle: 'Nom', order_place: 1),
build(:type_de_champ_text, libelle: 'Prénom', order_place: 2)
])
]
let(:repetition) do
repetition_tdc = procedure.active_revision.add_type_de_champ(type_champ: 'repetition', libelle: 'Répétition')
procedure.active_revision.add_type_de_champ(type_champ: 'text', libelle: 'Nom', parent_id: repetition_tdc.stable_id)
procedure.active_revision.add_type_de_champ(type_champ: 'text', libelle: 'Prénom', parent_id: repetition_tdc.stable_id)
repetition_tdc
end
let(:dossier) do
repetition
create(:dossier, procedure: procedure)
end
before do
repetition = dossier.champs
.find { |champ| champ.libelle == 'Répétition' }
repetition.add_row
repetition.add_row(dossier.revision)
paul_champs, pierre_champs = repetition.rows
paul_champs.first.update(value: 'Paul')

View file

@ -1190,11 +1190,13 @@ describe Dossier do
end
context "with champ repetition" do
let(:procedure) { create(:procedure, types_de_champ: [type_de_champ_repetition]) }
let(:type_de_champ_repetition) { build(:type_de_champ_repetition, mandatory: true) }
let(:procedure) { create(:procedure, :with_repetition) }
let(:revision) { procedure.active_revision }
let(:type_de_champ_repetition) { revision.types_de_champ.first }
before do
create(:type_de_champ_text, mandatory: true, parent: type_de_champ_repetition)
type_de_champ_repetition.update(mandatory: true)
revision.children_of(type_de_champ_repetition).first.update(mandatory: true)
end
context "when no champs" do
@ -1215,7 +1217,7 @@ describe Dossier do
let(:champ_with_error) { dossier.champs.first.champs.first }
before do
dossier.champs.first.add_row
dossier.champs.first.add_row(dossier.revision)
end
it 'should have errors' do
@ -1763,8 +1765,8 @@ describe Dossier do
datetime_champ.update(value: Date.today.to_s)
text_champ.update(value: 'bonjour')
# Add two rows then remove previous to last row in order to create a "hole" in the sequence
repetition_champ.add_row
repetition_champ.add_row
repetition_champ.add_row(repetition_champ.dossier.revision)
repetition_champ.add_row(repetition_champ.dossier.revision)
repetition_champ.champs.where(row: repetition_champ.champs.last.row - 1).destroy_all
repetition_champ.reload
end