feat(conditional): annotations can be conditioned by champs

This commit is contained in:
Paul Chavard 2023-11-03 10:15:50 +00:00
parent 532fe466df
commit 026885ebcf
3 changed files with 37 additions and 0 deletions

View file

@ -383,6 +383,11 @@ module Administrateurs
revision: [],
procedure: []
},
revision_types_de_champ_public: {
type_de_champ: { piece_justificative_template_attachment: :blob, revision: [], procedure: [] },
revision: [],
procedure: []
},
procedure: []
}).find(@procedure.id)
end

View file

@ -46,6 +46,10 @@ class ProcedureRevisionTypeDeChamp < ApplicationRecord
upper += parent.upper_coordinates
end
if type_de_champ.private?
upper += revision.revision_types_de_champ_public
end
upper
end

View file

@ -23,5 +23,33 @@ describe ProcedureRevisionTypeDeChamp do
it { expect(l2_2.upper_coordinates.map(&:libelle)).to match_array(["l1", "l2.1"]) }
end
context 'when the coordinate is an annotation' do
let(:procedure) do
create(:procedure,
types_de_champ_private: [
{ libelle: 'a1' },
{ libelle: 'a2' }
],
types_de_champ_public: [
{ libelle: 'l1' },
{
type: :repetition, libelle: 'l2', children: [
{ libelle: 'l2.1' },
{ libelle: 'l2.2' }
]
}
])
end
let(:a2) do
procedure
.draft_revision
.revision_types_de_champ.joins(:type_de_champ)
.find_by(type_de_champ: { libelle: 'a2' })
end
it { expect(a2.upper_coordinates.map(&:libelle)).to match_array(["l1", "l2", "a1"]) }
end
end
end