From 4493d4c6aff7a0855d3ee62194bccfffd432bde5 Mon Sep 17 00:00:00 2001 From: Eric Leroy-Terquem Date: Tue, 17 Oct 2023 11:27:36 +0200 Subject: [PATCH] feat(conditional): can condition on commune champ value --- app/models/logic/champ_value.rb | 10 ++++++---- .../conditions_component_spec.rb | 12 ++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/app/models/logic/champ_value.rb b/app/models/logic/champ_value.rb index 37ed167ca27..bd4d31f0020 100644 --- a/app/models/logic/champ_value.rb +++ b/app/models/logic/champ_value.rb @@ -6,6 +6,7 @@ class Logic::ChampValue < Logic::Term :decimal_number, :drop_down_list, :multiple_drop_down_list, + :communes, :epci, :departements, :regions @@ -64,10 +65,11 @@ def type(type_de_champs) when MANAGED_TYPE_DE_CHAMP.fetch(:integer_number), MANAGED_TYPE_DE_CHAMP.fetch(:decimal_number) CHAMP_VALUE_TYPE.fetch(:number) when MANAGED_TYPE_DE_CHAMP.fetch(:drop_down_list), + MANAGED_TYPE_DE_CHAMP.fetch(:communes), + MANAGED_TYPE_DE_CHAMP.fetch(:epci), MANAGED_TYPE_DE_CHAMP.fetch(:departements), - MANAGED_TYPE_DE_CHAMP.fetch(:regions), - MANAGED_TYPE_DE_CHAMP.fetch(:epci) - CHAMP_VALUE_TYPE.fetch(:enum) + MANAGED_TYPE_DE_CHAMP.fetch(:regions) + CHAMP_VALUE_TYPE.fetch(:enum) when MANAGED_TYPE_DE_CHAMP.fetch(:multiple_drop_down_list) CHAMP_VALUE_TYPE.fetch(:enums) else @@ -102,7 +104,7 @@ def options(type_de_champs) tdc = type_de_champ(type_de_champs) case tdc.type_champ - when MANAGED_TYPE_DE_CHAMP.fetch(:departements), MANAGED_TYPE_DE_CHAMP.fetch(:epci) + when MANAGED_TYPE_DE_CHAMP.fetch(:communes), MANAGED_TYPE_DE_CHAMP.fetch(:epci), MANAGED_TYPE_DE_CHAMP.fetch(:departements) APIGeoService.departements.map { ["#{_1[:code]} – #{_1[:name]}", _1[:code]] } when MANAGED_TYPE_DE_CHAMP.fetch(:regions) APIGeoService.regions.map { ["#{_1[:code]} – #{_1[:name]}", _1[:code]] } diff --git a/spec/components/types_de_champ_editor/conditions_component_spec.rb b/spec/components/types_de_champ_editor/conditions_component_spec.rb index be2e1d2e20d..ffce44546ed 100644 --- a/spec/components/types_de_champ_editor/conditions_component_spec.rb +++ b/spec/components/types_de_champ_editor/conditions_component_spec.rb @@ -81,6 +81,18 @@ end end + context 'communes' do + let(:communes) { create(:type_de_champ_communes) } + let(:upper_tdcs) { [communes] } + let(:condition) { empty_operator(champ_value(communes.stable_id), constant(true)) } + let(:departement_options) { APIGeoService.departements.map { "#{_1[:code]} – #{_1[:name]}" } } + + it do + expect(page).to have_select('type_de_champ[condition_form][rows][][operator_name]', with_options: ['Est']) + expect(page).to have_select('type_de_champ[condition_form][rows][][value]', options: (['Sélectionner'] + departement_options)) + end + end + context 'epcis' do let(:epcis) { create(:type_de_champ_epci) } let(:upper_tdcs) { [epcis] }