bug(TypesDeChamp::ConditionValidator): should allow to use types_de_champ_public on condition for types_de_champ_private
This commit is contained in:
parent
5ef29a2f31
commit
d2ccea700b
1 changed files with 39 additions and 20 deletions
|
@ -352,24 +352,12 @@ describe Procedure do
|
|||
end
|
||||
|
||||
describe 'draft_types_de_champ validations' do
|
||||
let(:repetition) { repetition = procedure.draft_revision.types_de_champ_public.find(&:repetition?) }
|
||||
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
|
||||
let(:procedure) { create(:procedure, types_de_champ_public:, types_de_champ_private:) }
|
||||
|
||||
context 'on a draft procedure' do
|
||||
let(:types_de_champ_private) { [] }
|
||||
let(:types_de_champ_public) { [{ type: :repetition, libelle: 'Enfants', children: [] }] }
|
||||
|
||||
it 'doesn’t validate the types de champs' do
|
||||
procedure.validate
|
||||
expect(procedure.errors[:draft_types_de_champ_public]).not_to be_present
|
||||
|
@ -377,12 +365,22 @@ describe Procedure do
|
|||
end
|
||||
|
||||
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
|
||||
procedure.validate(:publication)
|
||||
expect(procedure.errors.full_messages_for(:draft_types_de_champ_public)).to include(invalid_repetition_error_message)
|
||||
|
||||
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)
|
||||
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)
|
||||
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")
|
||||
procedure.reload.validate(:publication)
|
||||
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
|
||||
|
||||
context 'when the champ is private' do
|
||||
before do
|
||||
repetition.update(private: true)
|
||||
drop_down.update(private: true)
|
||||
let(:types_de_champ_private) do
|
||||
[
|
||||
{ type: :repetition, libelle: 'Enfants', children: [] },
|
||||
{ type: :drop_down_list, libelle: 'Civilité', options: [] }
|
||||
]
|
||||
end
|
||||
let(:types_de_champ_public) { [] }
|
||||
|
||||
let(:invalid_repetition_error_message) { 'L’annotation privée « Enfants » doit comporter au moins un champ répétable' }
|
||||
let(:invalid_drop_down_error_message) { 'L’annotation privée « Civilité » doit comporter au moins un choix sélectionnable' }
|
||||
|
@ -418,6 +420,23 @@ describe Procedure do
|
|||
procedure.validate(:publication)
|
||||
expect(procedure.errors.full_messages_for(:draft_types_de_champ_private)).to include(invalid_drop_down_error_message)
|
||||
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
|
||||
|
||||
|
|
Loading…
Reference in a new issue