From a6cf22edb8f22234590624e8ecadce387b760024 Mon Sep 17 00:00:00 2001 From: Martin Date: Fri, 20 Oct 2023 07:59:18 +0200 Subject: [PATCH] =?UTF-8?q?amelioration(types=5Fde=5Fchamp=5Feditor/champ?= =?UTF-8?q?=5Fcomponent):=20isole=20le=20type=20de=20champs=20Ej=20aux=20a?= =?UTF-8?q?nnotation=20priv=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../types_de_champ_editor/champ_component.rb | 9 ++++ app/models/type_de_champ.rb | 4 ++ .../champ_component_spec.rb | 47 ++++++++++++++----- 3 files changed, 48 insertions(+), 12 deletions(-) diff --git a/app/components/types_de_champ_editor/champ_component.rb b/app/components/types_de_champ_editor/champ_component.rb index f6abcf06d..178966a8d 100644 --- a/app/components/types_de_champ_editor/champ_component.rb +++ b/app/components/types_de_champ_editor/champ_component.rb @@ -63,6 +63,7 @@ class TypesDeChampEditor::ChampComponent < ApplicationComponent .filter(&method(:filter_type_champ)) .filter(&method(:filter_featured_type_champ)) .filter(&method(:filter_block_type_champ)) + .filter(&method(:filter_public_or_private_only_type_champ)) .group_by { TypeDeChamp::TYPE_DE_CHAMP_TO_CATEGORIE.fetch(_1.to_sym) } .sort_by { |k, _v| TypeDeChamp::CATEGORIES.find_index(k) } .to_h do |cat, tdc| @@ -91,6 +92,14 @@ class TypesDeChampEditor::ChampComponent < ApplicationComponent !coordinate.child? || !EXCLUDE_FROM_BLOCK.include?(type_champ) end + def filter_public_or_private_only_type_champ(type_champ) + if coordinate.private? + true + else + !TypeDeChamp::PRIVATE_TYPES.include?(type_champ) + end + end + def filter_featured_type_champ(type_champ) feature_name = TypeDeChamp::FEATURE_FLAGS[type_champ.to_sym] feature_name.blank? || procedure.feature_enabled?(feature_name) diff --git a/app/models/type_de_champ.rb b/app/models/type_de_champ.rb index 2dc807eb4..07d40a091 100644 --- a/app/models/type_de_champ.rb +++ b/app/models/type_de_champ.rb @@ -118,6 +118,10 @@ class TypeDeChamp < ApplicationRecord type_champs.fetch(:epci) ] + PRIVATE_TYPES = [ + type_champs.fetch(:engagement_juridique) + ] + store_accessor :options, :cadastres, :old_pj, diff --git a/spec/components/types_de_champ_editor/champ_component_spec.rb b/spec/components/types_de_champ_editor/champ_component_spec.rb index 09fe85b4d..1a634ddfb 100644 --- a/spec/components/types_de_champ_editor/champ_component_spec.rb +++ b/spec/components/types_de_champ_editor/champ_component_spec.rb @@ -1,8 +1,5 @@ describe TypesDeChampEditor::ChampComponent, type: :component do describe 'render' do - let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :drop_down_list, libelle: 'Votre ville', options: ['Paris', 'Lyon', 'Marseille'] }]) } - let(:drop_down_tdc) { procedure.draft_revision.types_de_champ.first } - let(:coordinate) { drop_down_tdc.revision_type_de_champ } let(:component) { described_class.new(coordinate:, upper_coordinates: []) } let(:routing_rules_stable_ids) { [] } @@ -11,19 +8,45 @@ describe TypesDeChampEditor::ChampComponent, type: :component do render_inline(component) end - context 'drop down tdc not used for routing' do - it do - expect(page).not_to have_text(/utilisé pour\nle routage/) - expect(page).not_to have_css("select[disabled=\"disabled\"]") + describe 'tdc dropdown' do + let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :drop_down_list, libelle: 'Votre ville', options: ['Paris', 'Lyon', 'Marseille'] }]) } + let(:tdc) { procedure.draft_revision.types_de_champ.first } + let(:coordinate) { tdc.revision_type_de_champ } + + context 'drop down tdc not used for routing' do + it do + expect(page).not_to have_text(/utilisé pour\nle routage/) + expect(page).not_to have_css("select[disabled=\"disabled\"]") + end + end + + context 'drop down tdc used for routing' do + let(:routing_rules_stable_ids) { [tdc.stable_id] } + + it do + expect(page).to have_css("select[disabled=\"disabled\"]") + expect(page).to have_text(/utilisé pour\nle routage/) + end end end - context 'drop down tdc used for routing' do - let(:routing_rules_stable_ids) { [drop_down_tdc.stable_id] } + describe 'tdc ej' do + let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :text }], types_de_champ_private: [{ type: :text }]) } - it do - expect(page).to have_css("select[disabled=\"disabled\"]") - expect(page).to have_text(/utilisé pour\nle routage/) + context 'when coordinate public' do + let(:coordinate) { procedure.draft_revision.revision_types_de_champ_public.first } + + it 'does not include Engagement Juridique' do + expect(page).not_to have_css(:option, text: "Engagement Juridique") + end + end + + context 'when coordinate private' do + let(:coordinate) { procedure.draft_revision.revision_types_de_champ_private.first } + + it 'includes Engagement Juridique' do + expect(page).to have_css(:option, text: "Engagement Juridique") + end end end end