From ea8112b8b3906cf5e985f19f570a73c512cbb933 Mon Sep 17 00:00:00 2001
From: Eric Leroy-Terquem Pour le configurer, votre formulaire doit comporter
- au moins un champ de type « choix simple », « communes », « epci », « départements » ou « régions ».
Ajoutez ce champ dans la page « Configuration des champs ».
delete_title: Aucun dossier ne sera supprimé. Les groupes d'instructeurs vont être supprimés. Seuls les instructeurs du groupe « %{defaut_label} » resteront affectés à la démarche. delete_confirmation: | diff --git a/app/components/procedure/instructeurs_options_component/instructeurs_options_component.html.haml b/app/components/procedure/instructeurs_options_component/instructeurs_options_component.html.haml index aa46fb167..903cf6e64 100644 --- a/app/components/procedure/instructeurs_options_component/instructeurs_options_component.html.haml +++ b/app/components/procedure/instructeurs_options_component/instructeurs_options_component.html.haml @@ -24,8 +24,8 @@ ROUTAGE_URL, title: t('.routage_doc.title'), **helpers.external_link_attributes) - - if @procedure.active_revision.routable_types_de_champ.none? - %p.fr-mt-2w= t('.routing_configuration_notice_2_html', path: champs_admin_procedure_path(@procedure)) + - if @procedure.active_revision.conditionable_types_de_champ.none? + %p.fr-mt-2w= t('.routing_configuration_notice_2_html', path: champs_admin_procedure_path(@procedure), conditionable_types: TypeDeChamp.humanized_conditionable_types) - elsif @procedure.groupe_instructeurs.active.one? = link_to 'Configurer le routage', options_admin_procedure_groupe_instructeurs_path(@procedure, state: :choix), class: 'fr-btn' diff --git a/app/models/type_de_champ.rb b/app/models/type_de_champ.rb index 52fc141b0..31ce288da 100644 --- a/app/models/type_de_champ.rb +++ b/app/models/type_de_champ.rb @@ -660,6 +660,12 @@ class TypeDeChamp < ApplicationRecord Logic::ChampValue::MANAGED_TYPE_DE_CHAMP.values.include?(type_champ) end + def self.humanized_conditionable_types + Logic::ChampValue::MANAGED_TYPE_DE_CHAMP.values.map do + "« #{I18n.t(_1, scope: [:activerecord, :attributes, :type_de_champ, :type_champs])} »" + end.to_sentence(last_word_connector: ' ou ') + end + def invalid_regexp? self.errors.delete(:expression_reguliere) self.errors.delete(:expression_reguliere_exemple_text) diff --git a/spec/controllers/administrateurs/groupe_instructeurs_controller_spec.rb b/spec/controllers/administrateurs/groupe_instructeurs_controller_spec.rb index e916435de..8600a0325 100644 --- a/spec/controllers/administrateurs/groupe_instructeurs_controller_spec.rb +++ b/spec/controllers/administrateurs/groupe_instructeurs_controller_spec.rb @@ -793,6 +793,41 @@ describe Administrateurs::GroupeInstructeursController, type: :controller do end end + describe '#options' do + context 'with a simple routable type de champ' do + let!(:procedure) do + create(:procedure, + types_de_champ_public: [ + { type: :drop_down_list, libelle: 'Votre ville', options: ['Paris', 'Lyon', 'Marseille'] } + ], + administrateurs: [admin]) + end + before { get :options, params: { procedure_id: procedure.id, state: 'choix' } } + + it do + expect(response).to have_http_status(:ok) + expect(response.body).to include('Choix du type de routage') + expect(procedure.reload.routing_enabled).to be_falsey + end + end + + context 'with a conditionable but not simple routable type de champ' do + let!(:procedure) do + create(:procedure, + types_de_champ_public: [ + { type: :integer_number } + ], + administrateurs: [admin]) + end + before { get :options, params: { procedure_id: procedure.id, state: 'choix' } } + + it do + expect(response).to redirect_to(admin_procedure_groupe_instructeurs_path(procedure)) + expect(procedure.reload.routing_enabled).to be_truthy + end + end + end + describe '#create_simple_routing' do context 'with a drop_down_list type de champ' do let!(:procedure3) do