bug(TypesDeChamp::ConditionValidator): should allow to use types_de_champ_public on condition for types_de_champ_private

This commit is contained in:
mfo 2024-06-10 09:35:29 +02:00
parent 5ef29a2f31
commit d2ccea700b
No known key found for this signature in database
GPG key ID: 7CE3E1F5B794A8EC

View file

@ -352,24 +352,12 @@ describe Procedure do
end end
describe 'draft_types_de_champ validations' do describe 'draft_types_de_champ validations' do
let(:repetition) { repetition = procedure.draft_revision.types_de_champ_public.find(&:repetition?) } let(:procedure) { create(:procedure, types_de_champ_public:, types_de_champ_private:) }
let(:text_field) { build(:type_de_champ_text) }
let(:invalid_repetition_error_message) { 'Le champ « Enfants » doit comporter au moins un champ répétable' }
let(:drop_down) { build(:type_de_champ_drop_down_list, :without_selectable_values, libelle: 'Civilité') }
let(:invalid_drop_down_error_message) { 'Le champ « Civilité » doit comporter au moins un choix sélectionnable' }
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :repetition, children: [{ type: :text }, { type: :integer_number }] }]) }
let(:draft) { procedure.draft_revision }
before do
draft.revision_types_de_champ.create(type_de_champ: drop_down, position: 100)
repetition.update(libelle: 'Enfants')
draft.children_of(repetition).destroy_all
end
context 'on a draft procedure' do context 'on a draft procedure' do
let(:types_de_champ_private) { [] }
let(:types_de_champ_public) { [{ type: :repetition, libelle: 'Enfants', children: [] }] }
it 'doesnt validate the types de champs' do it 'doesnt validate the types de champs' do
procedure.validate procedure.validate
expect(procedure.errors[:draft_types_de_champ_public]).not_to be_present expect(procedure.errors[:draft_types_de_champ_public]).not_to be_present
@ -377,12 +365,22 @@ describe Procedure do
end end
context 'when validating for publication' do context 'when validating for publication' do
let(:types_de_champ_public) do
[
{ type: :repetition, libelle: 'Enfants', children: [] },
{ type: :drop_down_list, libelle: 'Civilité', options: [] }
]
end
let(:types_de_champ_private) { [] }
let(:invalid_repetition_error_message) { 'Le champ « Enfants » doit comporter au moins un champ répétable' }
let(:invalid_drop_down_error_message) { 'Le champ « Civilité » doit comporter au moins un choix sélectionnable' }
it 'validates that no repetition type de champ is empty' do it 'validates that no repetition type de champ is empty' do
procedure.validate(:publication) procedure.validate(:publication)
expect(procedure.errors.full_messages_for(:draft_types_de_champ_public)).to include(invalid_repetition_error_message) expect(procedure.errors.full_messages_for(:draft_types_de_champ_public)).to include(invalid_repetition_error_message)
new_draft = procedure.draft_revision new_draft = procedure.draft_revision
repetition = procedure.draft_revision.types_de_champ_public.find(&:repetition?)
parent_coordinate = new_draft.revision_types_de_champ.find_by(type_de_champ: repetition) parent_coordinate = new_draft.revision_types_de_champ.find_by(type_de_champ: repetition)
new_draft.revision_types_de_champ.create(type_de_champ: create(:type_de_champ), position: 0, parent: parent_coordinate) new_draft.revision_types_de_champ.create(type_de_champ: create(:type_de_champ), position: 0, parent: parent_coordinate)
@ -394,6 +392,7 @@ describe Procedure do
procedure.validate(:publication) procedure.validate(:publication)
expect(procedure.errors.full_messages_for(:draft_types_de_champ_public)).to include(invalid_drop_down_error_message) expect(procedure.errors.full_messages_for(:draft_types_de_champ_public)).to include(invalid_drop_down_error_message)
drop_down = procedure.draft_revision.types_de_champ_public.find(&:drop_down_list?)
drop_down.update!(drop_down_list_value: "--title--\r\nsome value") drop_down.update!(drop_down_list_value: "--title--\r\nsome value")
procedure.reload.validate(:publication) procedure.reload.validate(:publication)
expect(procedure.errors.full_messages_for(:draft_types_de_champ_public)).not_to include(invalid_drop_down_error_message) expect(procedure.errors.full_messages_for(:draft_types_de_champ_public)).not_to include(invalid_drop_down_error_message)
@ -401,10 +400,13 @@ describe Procedure do
end end
context 'when the champ is private' do context 'when the champ is private' do
before do let(:types_de_champ_private) do
repetition.update(private: true) [
drop_down.update(private: true) { type: :repetition, libelle: 'Enfants', children: [] },
{ type: :drop_down_list, libelle: 'Civilité', options: [] }
]
end end
let(:types_de_champ_public) { [] }
let(:invalid_repetition_error_message) { 'Lannotation privée « Enfants » doit comporter au moins un champ répétable' } let(:invalid_repetition_error_message) { 'Lannotation privée « Enfants » doit comporter au moins un champ répétable' }
let(:invalid_drop_down_error_message) { 'Lannotation privée « Civilité » doit comporter au moins un choix sélectionnable' } let(:invalid_drop_down_error_message) { 'Lannotation privée « Civilité » doit comporter au moins un choix sélectionnable' }
@ -418,6 +420,23 @@ describe Procedure do
procedure.validate(:publication) procedure.validate(:publication)
expect(procedure.errors.full_messages_for(:draft_types_de_champ_private)).to include(invalid_drop_down_error_message) expect(procedure.errors.full_messages_for(:draft_types_de_champ_private)).to include(invalid_drop_down_error_message)
end end
it 'validates that types de champ private condition works types de champ public and private' do
end
end
context 'when condition on champ private use public champ' do
include Logic
let(:types_de_champ_private) { [{ type: :text, condition: ds_eq(champ_value(1), constant(2)) }] }
let(:types_de_champ_public) { [{ type: :number, stable_id: 1 }] }
it 'validate without context' do
expect(procedure.validate).to be_truthy
end
it 'validate with types_de_champ_private_editor' do
expect(procedure.validate(:types_de_champ_private_editor)).to be_falsey
end
end end
end end