amelioration(types_de_champ_editor/champ_component): isole le type de champs Ej aux annotation privée

This commit is contained in:
Martin 2023-10-20 07:59:18 +02:00
parent 13624f0f7e
commit a6cf22edb8
3 changed files with 48 additions and 12 deletions

View file

@ -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)

View file

@ -118,6 +118,10 @@ class TypeDeChamp < ApplicationRecord
type_champs.fetch(:epci)
]
PRIVATE_TYPES = [
type_champs.fetch(:engagement_juridique)
]
store_accessor :options,
:cadastres,
:old_pj,

View file

@ -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,6 +8,11 @@ describe TypesDeChampEditor::ChampComponent, type: :component do
render_inline(component)
end
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/)
@ -19,7 +21,7 @@ describe TypesDeChampEditor::ChampComponent, type: :component do
end
context 'drop down tdc used for routing' do
let(:routing_rules_stable_ids) { [drop_down_tdc.stable_id] }
let(:routing_rules_stable_ids) { [tdc.stable_id] }
it do
expect(page).to have_css("select[disabled=\"disabled\"]")
@ -27,4 +29,25 @@ describe TypesDeChampEditor::ChampComponent, type: :component do
end
end
end
describe 'tdc ej' do
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :text }], types_de_champ_private: [{ type: :text }]) }
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
end