Merge pull request #9604 from demarches-simplifiees/etq-admin-je-peux-creer-une-regle-de-routage-de-plusieurs-lignes
ETQ admin je peux créer une règle de routage de plusieurs lignes
This commit is contained in:
commit
f7eeb21425
36 changed files with 486 additions and 302 deletions
|
@ -1,4 +1,4 @@
|
|||
describe TypesDeChampEditor::ConditionsComponent, type: :component do
|
||||
describe Conditions::ChampsConditionsComponent, type: :component do
|
||||
include Logic
|
||||
|
||||
describe 'render' do
|
52
spec/components/conditions/routing_rules_component_spec.rb
Normal file
52
spec/components/conditions/routing_rules_component_spec.rb
Normal file
|
@ -0,0 +1,52 @@
|
|||
describe Conditions::RoutingRulesComponent, type: :component do
|
||||
include Logic
|
||||
|
||||
describe 'render' do
|
||||
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :drop_down_list, libelle: 'Votre ville', options: ['Paris', 'Lyon', 'Marseille'] }, { type: :integer_number, libelle: 'Un champ nombre entier' }]) }
|
||||
let(:groupe_instructeur) { procedure.groupe_instructeurs.first }
|
||||
let(:drop_down_tdc) { procedure.draft_revision.types_de_champ.first }
|
||||
let(:integer_number_tdc) { procedure.draft_revision.types_de_champ.last }
|
||||
let(:routing_rule) { ds_eq(champ_value(drop_down_tdc.stable_id), constant('Lyon')) }
|
||||
|
||||
before do
|
||||
groupe_instructeur.update(routing_rule: routing_rule)
|
||||
render_inline(described_class.new(groupe_instructeur: groupe_instructeur))
|
||||
end
|
||||
|
||||
context 'with one row' do
|
||||
context 'when routing rule is valid' do
|
||||
it do
|
||||
expect(page).to have_text('Champ Cible')
|
||||
expect(page).not_to have_text('règle invalide')
|
||||
expect(page).to have_select('groupe_instructeur[condition_form][rows][][operator_name]', options: ["Est", "N’est pas"])
|
||||
end
|
||||
end
|
||||
|
||||
context 'when routing rule is invalid' do
|
||||
let(:routing_rule) { ds_eq(champ_value(drop_down_tdc.stable_id), empty) }
|
||||
it { expect(page).to have_text('règle invalide') }
|
||||
end
|
||||
end
|
||||
|
||||
context 'with two rows' do
|
||||
context 'when routing rule is valid' do
|
||||
let(:routing_rule) { ds_and([ds_eq(champ_value(drop_down_tdc.stable_id), constant('Lyon')), ds_not_eq(champ_value(integer_number_tdc.stable_id), constant(33))]) }
|
||||
|
||||
it do
|
||||
expect(page).not_to have_text('règle invalide')
|
||||
expect(page).to have_selector('tbody > tr', count: 2)
|
||||
expect(page).to have_select("groupe_instructeur_condition_form_top_operator_name", selected: "Et", options: ['Et', 'Ou'])
|
||||
end
|
||||
end
|
||||
|
||||
context 'when routing rule is invalid' do
|
||||
let(:routing_rule) { ds_or([ds_eq(champ_value(drop_down_tdc.stable_id), constant('Lyon')), ds_not_eq(champ_value(integer_number_tdc.stable_id), empty)]) }
|
||||
it do
|
||||
expect(page).to have_text('règle invalide')
|
||||
expect(page).to have_selector('tbody > tr', count: 2)
|
||||
expect(page).to have_select("groupe_instructeur_condition_form_top_operator_name", selected: "Ou", options: ['Et', 'Ou'])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,11 +1,11 @@
|
|||
describe TypesDeChampEditor::ConditionsErrorsComponent, type: :component do
|
||||
describe Conditions::ConditionsErrorsComponent, type: :component do
|
||||
include Logic
|
||||
|
||||
describe 'render' do
|
||||
let(:conditions) { [] }
|
||||
let(:upper_tdcs) { [] }
|
||||
let(:source_tdcs) { [] }
|
||||
|
||||
before { render_inline(described_class.new(conditions: conditions, upper_tdcs: upper_tdcs)) }
|
||||
before { render_inline(described_class.new(conditions: conditions, source_tdcs: source_tdcs)) }
|
||||
|
||||
context 'when there are no condition' do
|
||||
it { expect(page).to have_no_css('.errors-summary') }
|
||||
|
@ -23,7 +23,7 @@ describe TypesDeChampEditor::ConditionsErrorsComponent, type: :component do
|
|||
|
||||
context 'when the targeted_champ is unmanaged' do
|
||||
let(:tdc) { create(:type_de_champ_address) }
|
||||
let(:upper_tdcs) { [tdc] }
|
||||
let(:source_tdcs) { [tdc] }
|
||||
let(:conditions) { [ds_eq(champ_value(tdc.stable_id), constant(1))] }
|
||||
|
||||
it do
|
||||
|
@ -34,7 +34,7 @@ describe TypesDeChampEditor::ConditionsErrorsComponent, type: :component do
|
|||
|
||||
context 'when the types mismatch' do
|
||||
let(:tdc) { create(:type_de_champ_integer_number) }
|
||||
let(:upper_tdcs) { [tdc] }
|
||||
let(:source_tdcs) { [tdc] }
|
||||
let(:conditions) { [ds_eq(champ_value(tdc.stable_id), constant('a'))] }
|
||||
|
||||
it { expect(page).to have_content("Le champ « #{tdc.libelle} » est de type « nombre entier ». Il ne peut pas être égal à « a ».") }
|
||||
|
@ -42,7 +42,7 @@ describe TypesDeChampEditor::ConditionsErrorsComponent, type: :component do
|
|||
|
||||
context 'when a number operator is applied on not a number' do
|
||||
let(:tdc) { create(:type_de_champ_multiple_drop_down_list) }
|
||||
let(:upper_tdcs) { [tdc] }
|
||||
let(:source_tdcs) { [tdc] }
|
||||
let(:conditions) { [greater_than(champ_value(tdc.stable_id), constant('a text'))] }
|
||||
|
||||
it { expect(page).to have_content("« Supérieur à » ne s'applique qu'à des nombres.") }
|
||||
|
@ -50,7 +50,7 @@ describe TypesDeChampEditor::ConditionsErrorsComponent, type: :component do
|
|||
|
||||
context 'when the include operator is applied on a list' do
|
||||
let(:tdc) { create(:type_de_champ_integer_number) }
|
||||
let(:upper_tdcs) { [tdc] }
|
||||
let(:source_tdcs) { [tdc] }
|
||||
let(:conditions) { [ds_include(champ_value(tdc.stable_id), constant('a text'))] }
|
||||
|
||||
it { expect(page).to have_content("Lʼopérateur « inclus » ne s'applique qu'au choix simple ou multiple.") }
|
||||
|
@ -58,7 +58,7 @@ describe TypesDeChampEditor::ConditionsErrorsComponent, type: :component do
|
|||
|
||||
context 'when a choice is not in a drop_down' do
|
||||
let(:tdc) { create(:type_de_champ_drop_down_list) }
|
||||
let(:upper_tdcs) { [tdc] }
|
||||
let(:source_tdcs) { [tdc] }
|
||||
let(:conditions) { [ds_eq(champ_value(tdc.stable_id), constant('another choice'))] }
|
||||
|
||||
it { expect(page).to have_content("« another choice » ne fait pas partie de « #{tdc.libelle} ».") }
|
||||
|
@ -66,7 +66,7 @@ describe TypesDeChampEditor::ConditionsErrorsComponent, type: :component do
|
|||
|
||||
context 'when a choice is not in a multiple_drop_down' do
|
||||
let(:tdc) { create(:type_de_champ_multiple_drop_down_list) }
|
||||
let(:upper_tdcs) { [tdc] }
|
||||
let(:source_tdcs) { [tdc] }
|
||||
let(:conditions) { [ds_include(champ_value(tdc.stable_id), constant('another choice'))] }
|
||||
|
||||
it { expect(page).to have_content("« another choice » ne fait pas partie de « #{tdc.libelle} ».") }
|
||||
|
@ -74,7 +74,7 @@ describe TypesDeChampEditor::ConditionsErrorsComponent, type: :component do
|
|||
|
||||
context 'when an eq operator applies to a multiple_drop_down' do
|
||||
let(:tdc) { create(:type_de_champ_multiple_drop_down_list) }
|
||||
let(:upper_tdcs) { [tdc] }
|
||||
let(:source_tdcs) { [tdc] }
|
||||
let(:conditions) { [ds_eq(champ_value(tdc.stable_id), constant(tdc.drop_down_list_enabled_non_empty_options.first))] }
|
||||
|
||||
it { expect(page).to have_content("« est » ne s'applique pas au choix multiple.") }
|
||||
|
@ -82,7 +82,7 @@ describe TypesDeChampEditor::ConditionsErrorsComponent, type: :component do
|
|||
|
||||
context 'when an not_eq operator applies to a multiple_drop_down' do
|
||||
let(:tdc) { create(:type_de_champ_multiple_drop_down_list) }
|
||||
let(:upper_tdcs) { [tdc] }
|
||||
let(:source_tdcs) { [tdc] }
|
||||
let(:conditions) { [ds_not_eq(champ_value(tdc.stable_id), constant(tdc.drop_down_list_enabled_non_empty_options.first))] }
|
||||
|
||||
it { expect(page).to have_content("« n’est pas » ne s'applique pas au choix multiple.") }
|
||||
|
@ -92,7 +92,7 @@ describe TypesDeChampEditor::ConditionsErrorsComponent, type: :component do
|
|||
# Cf https://demarches-simplifiees.sentry.io/issues/3625488398/events/53164e105bc94d55a004d69f96d58fb2/?project=1429550
|
||||
# However maybe we should not have empty at left with still a constant at right
|
||||
let(:tdc) { create(:type_de_champ_integer_number) }
|
||||
let(:upper_tdcs) { [tdc] }
|
||||
let(:source_tdcs) { [tdc] }
|
||||
let(:conditions) { [ds_eq(empty, constant('a text'))] }
|
||||
|
||||
it { expect(page).to have_content("Un champ cible n'est plus disponible") }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue