From dc2d2fb0323947fbbb47f73ad87b1ef33bcf00c9 Mon Sep 17 00:00:00 2001 From: Eric Leroy-Terquem Date: Wed, 18 Oct 2023 18:44:52 +0200 Subject: [PATCH] fix(test): update routing tests --- .../routing_rules_component_spec.rb | 52 +++++++++++++++++++ .../groupe_instructeurs_controller_spec.rb | 14 ++--- .../routing/rules_full_scenario_spec.rb | 20 +++---- 3 files changed, 65 insertions(+), 21 deletions(-) create mode 100644 spec/components/conditions/routing_rules_component_spec.rb diff --git a/spec/components/conditions/routing_rules_component_spec.rb b/spec/components/conditions/routing_rules_component_spec.rb new file mode 100644 index 00000000000..f6fcb5d1ddd --- /dev/null +++ b/spec/components/conditions/routing_rules_component_spec.rb @@ -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 diff --git a/spec/controllers/administrateurs/groupe_instructeurs_controller_spec.rb b/spec/controllers/administrateurs/groupe_instructeurs_controller_spec.rb index c6737c284bc..a87df3f8c23 100644 --- a/spec/controllers/administrateurs/groupe_instructeurs_controller_spec.rb +++ b/spec/controllers/administrateurs/groupe_instructeurs_controller_spec.rb @@ -60,26 +60,18 @@ end end - context 'group without routing rule' do - before { get :show, params: { procedure_id: procedure.id, id: gi_1_1.id } } - - it do - expect(response).to have_http_status(:ok) - expect(response.body).to include('règle invalide') - end - end - context 'group with routing rule matching tdc' do let!(:drop_down_tdc) { create(:type_de_champ_drop_down_list, procedure: procedure, drop_down_options: options) } - let(:options) { procedure.groupe_instructeurs.pluck(:label) } + let(:options) { ['Premier choix', 'Deuxième choix', 'Troisième choix'] } before do - gi_1_1.update(routing_rule: ds_eq(champ_value(drop_down_tdc.stable_id), constant(gi_1_1.label))) + gi_1_1.update(routing_rule: ds_eq(champ_value(drop_down_tdc.stable_id), constant('Deuxième choix'))) get :show, params: { procedure_id: procedure.id, id: gi_1_1.id } end it do expect(response).to have_http_status(:ok) + expect(response.body).to include('Deuxième choix') expect(response.body).not_to include('règle invalide') end end diff --git a/spec/system/routing/rules_full_scenario_spec.rb b/spec/system/routing/rules_full_scenario_spec.rb index f8f5414ec5e..886e0db5d5b 100644 --- a/spec/system/routing/rules_full_scenario_spec.rb +++ b/spec/system/routing/rules_full_scenario_spec.rb @@ -39,14 +39,14 @@ expect(page).not_to have_text('à configurer') click_on 'littéraire' - expect(page).to have_select("targeted_champ", selected: "Spécialité") - expect(page).to have_select("value", selected: "littéraire") + expect(page).to have_select("groupe_instructeur[condition_form][rows][][targeted_champ]", selected: "Spécialité") + expect(page).to have_select("groupe_instructeur[condition_form][rows][][value]", selected: "littéraire") click_on '3 groupes' click_on 'scientifique' - expect(page).to have_select("targeted_champ", selected: "Spécialité") - expect(page).to have_select("value", selected: "scientifique") + expect(page).to have_select("groupe_instructeur[condition_form][rows][][targeted_champ]", selected: "Spécialité") + expect(page).to have_select("groupe_instructeur[condition_form][rows][][value]", selected: "scientifique") end scenario 'Routage avancé' do @@ -106,20 +106,20 @@ expect(page).to have_text("L’instructeur alain@gouv.fr a été affecté") # add routing rules - within('.target') { select('Spécialité') } - within('.value') { select('scientifique') } + within('.target select') { select('Spécialité') } + within('.value select') { select('scientifique') } click_on '3 groupes' click_on 'littéraire' - within('.target') { select('Spécialité') } - within('.value') { select('scientifique') } + within('.target select') { select('Spécialité') } + within('.value select') { select('scientifique') } expect(page).to have_text('règle déjà attribuée à scientifique') - within('.target') { select('Spécialité') } - within('.value') { select('littéraire') } + within('.target select') { select('Spécialité') } + within('.value select') { select('littéraire') } expect(page).not_to have_text('règle déjà attribuée à scientifique')