Skip to content

Commit

Permalink
feat(conditional): can condition on epci champ value
Browse files Browse the repository at this point in the history
  • Loading branch information
E-L-T committed Oct 17, 2023
1 parent d724b27 commit b3e5ba8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
10 changes: 7 additions & 3 deletions app/models/logic/champ_value.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class Logic::ChampValue < Logic::Term
:decimal_number,
:drop_down_list,
:multiple_drop_down_list,
:epci,
:departements,
:regions
)
Expand Down Expand Up @@ -62,8 +63,11 @@ def type(type_de_champs)
CHAMP_VALUE_TYPE.fetch(:boolean)
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(:departements), MANAGED_TYPE_DE_CHAMP.fetch(:regions)
CHAMP_VALUE_TYPE.fetch(:enum)
when MANAGED_TYPE_DE_CHAMP.fetch(:drop_down_list),
MANAGED_TYPE_DE_CHAMP.fetch(:departements),
MANAGED_TYPE_DE_CHAMP.fetch(:regions),
MANAGED_TYPE_DE_CHAMP.fetch(:epci)
CHAMP_VALUE_TYPE.fetch(:enum)
when MANAGED_TYPE_DE_CHAMP.fetch(:multiple_drop_down_list)
CHAMP_VALUE_TYPE.fetch(:enums)
else
Expand Down Expand Up @@ -98,7 +102,7 @@ def options(type_de_champs)
tdc = type_de_champ(type_de_champs)

case tdc.type_champ
when MANAGED_TYPE_DE_CHAMP.fetch(:departements)
when MANAGED_TYPE_DE_CHAMP.fetch(:departements), MANAGED_TYPE_DE_CHAMP.fetch(:epci)
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]] }
Expand Down
12 changes: 12 additions & 0 deletions spec/components/types_de_champ_editor/conditions_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@
end
end

context 'epcis' do
let(:epcis) { create(:type_de_champ_epci) }
let(:upper_tdcs) { [epcis] }
let(:condition) { empty_operator(champ_value(epcis.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 'departements' do
let(:departements) { create(:type_de_champ_departements) }
let(:upper_tdcs) { [departements] }
Expand Down

0 comments on commit b3e5ba8

Please sign in to comment.