Merge pull request #9506 from demarches-simplifiees/add-departements-to-conditional
ETQ admin je peux conditionner sur un champ département
This commit is contained in:
commit
485d6c73b7
3 changed files with 30 additions and 6 deletions
|
@ -5,7 +5,8 @@ class Logic::ChampValue < Logic::Term
|
||||||
:integer_number,
|
:integer_number,
|
||||||
:decimal_number,
|
:decimal_number,
|
||||||
:drop_down_list,
|
:drop_down_list,
|
||||||
:multiple_drop_down_list
|
:multiple_drop_down_list,
|
||||||
|
:departements
|
||||||
)
|
)
|
||||||
|
|
||||||
CHAMP_VALUE_TYPE = {
|
CHAMP_VALUE_TYPE = {
|
||||||
|
@ -60,7 +61,7 @@ class Logic::ChampValue < Logic::Term
|
||||||
CHAMP_VALUE_TYPE.fetch(:boolean)
|
CHAMP_VALUE_TYPE.fetch(:boolean)
|
||||||
when MANAGED_TYPE_DE_CHAMP.fetch(:integer_number), MANAGED_TYPE_DE_CHAMP.fetch(:decimal_number)
|
when MANAGED_TYPE_DE_CHAMP.fetch(:integer_number), MANAGED_TYPE_DE_CHAMP.fetch(:decimal_number)
|
||||||
CHAMP_VALUE_TYPE.fetch(:number)
|
CHAMP_VALUE_TYPE.fetch(:number)
|
||||||
when MANAGED_TYPE_DE_CHAMP.fetch(:drop_down_list)
|
when MANAGED_TYPE_DE_CHAMP.fetch(:drop_down_list), MANAGED_TYPE_DE_CHAMP.fetch(:departements)
|
||||||
CHAMP_VALUE_TYPE.fetch(:enum)
|
CHAMP_VALUE_TYPE.fetch(:enum)
|
||||||
when MANAGED_TYPE_DE_CHAMP.fetch(:multiple_drop_down_list)
|
when MANAGED_TYPE_DE_CHAMP.fetch(:multiple_drop_down_list)
|
||||||
CHAMP_VALUE_TYPE.fetch(:enums)
|
CHAMP_VALUE_TYPE.fetch(:enums)
|
||||||
|
@ -94,11 +95,15 @@ class Logic::ChampValue < Logic::Term
|
||||||
|
|
||||||
def options(type_de_champs)
|
def options(type_de_champs)
|
||||||
tdc = type_de_champ(type_de_champs)
|
tdc = type_de_champ(type_de_champs)
|
||||||
opts = tdc.drop_down_list_enabled_non_empty_options.map { |option| [option, option] }
|
if tdc.departement?
|
||||||
if tdc.drop_down_other?
|
APIGeoService.departements.map { ["#{_1[:code]} – #{_1[:name]}", _1[:code]] }
|
||||||
opts + [["Autre", Champs::DropDownListChamp::OTHER]]
|
|
||||||
else
|
else
|
||||||
opts
|
opts = tdc.drop_down_list_enabled_non_empty_options.map { |option| [option, option] }
|
||||||
|
if tdc.drop_down_other?
|
||||||
|
opts + [["Autre", Champs::DropDownListChamp::OTHER]]
|
||||||
|
else
|
||||||
|
opts
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -80,6 +80,18 @@ describe TypesDeChampEditor::ConditionsComponent, type: :component do
|
||||||
expect(page).to have_select('type_de_champ[condition_form][rows][][value]', options: ['Sélectionner', 'val1', 'val2', 'val3'])
|
expect(page).to have_select('type_de_champ[condition_form][rows][][value]', options: ['Sélectionner', 'val1', 'val2', 'val3'])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'departements' do
|
||||||
|
let(:departements) { create(:type_de_champ_departements) }
|
||||||
|
let(:upper_tdcs) { [departements] }
|
||||||
|
let(:condition) { empty_operator(champ_value(departements.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
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'and 2 conditions' do
|
context 'and 2 conditions' do
|
||||||
|
|
|
@ -95,6 +95,13 @@ describe Logic::ChampValue do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'departement tdc' do
|
||||||
|
let(:champ) { create(:champ_departements, value: '02') }
|
||||||
|
|
||||||
|
it { expect(champ_value(champ.stable_id).type([champ.type_de_champ])).to eq(:enum) }
|
||||||
|
it { is_expected.to eq('02') }
|
||||||
|
end
|
||||||
|
|
||||||
context 'region tdc' do
|
context 'region tdc' do
|
||||||
let(:champ) { create(:champ_regions, value: 'La Réunion') }
|
let(:champ) { create(:champ_regions, value: 'La Réunion') }
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue