Skip to content

Commit

Permalink
feat(TypeDeChampEditor): prevent to destroy a type de champ used by e…
Browse files Browse the repository at this point in the history
…ligibilite rules
  • Loading branch information
mfo committed May 17, 2024
1 parent 8a118ed commit 0e7c390
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
%span
utilisé pour
= link_to('le routage', admin_procedure_groupe_instructeurs_path(revision.procedure_id, anchor: 'routing-rules'))
- elsif coordinate.used_by_eligibilite_rules?
%span
utilisé pour
= link_to('l’eligibilité des dossiers', edit_admin_procedure_eligibilite_rules_path(revision.procedure_id))
- else
= button_to type_de_champ_path, class: 'fr-btn fr-btn--tertiary-no-outline fr-icon-delete-line', title: "Supprimer le champ", method: :delete, form: { data: { turbo_confirm: 'Êtes vous sûr de vouloir supprimer ce champ ?' } } do
%span.sr-only Supprimer
Expand All @@ -24,7 +28,7 @@
.flex.justify-start.width-33
.cell.flex.justify-start.column.flex-grow
= form.label :type_champ, "Type de champ", for: dom_id(type_de_champ, :type_champ)
= form.select :type_champ, grouped_options_for_select(types_of_type_de_champ, type_de_champ.type_champ), {}, class: 'fr-select small-margin small inline width-100', id: dom_id(type_de_champ, :type_champ), disabled: coordinate.used_by_routing_rules?
= form.select :type_champ, grouped_options_for_select(types_of_type_de_champ, type_de_champ.type_champ), {}, class: 'fr-select small-margin small inline width-100', id: dom_id(type_de_champ, :type_champ), disabled: coordinate.used_by_routing_rules? || coordinate.used_by_eligibilite_rules?

.flex.column.justify-start.flex-grow
.cell
Expand Down
4 changes: 4 additions & 0 deletions app/models/procedure_revision_type_de_champ.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,8 @@ def block
def used_by_routing_rules?
stable_id.in?(procedure.stable_ids_used_by_routing_rules)
end

def used_by_eligibilite_rules?
revision.eligibilite_enabled? && stable_id.in?(revision.eligibilite_rules&.sources || [])
end
end
11 changes: 11 additions & 0 deletions spec/components/types_de_champ_editor/champ_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
describe 'render' do
let(:component) { described_class.new(coordinate:, upper_coordinates: []) }
let(:routing_rules_stable_ids) { [] }
let(:eligibilite_rules_used?) { false }

before do
Flipper.enable_actor(:engagement_juridique_type_de_champ, procedure)
allow_any_instance_of(Procedure).to receive(:stable_ids_used_by_routing_rules).and_return(routing_rules_stable_ids)
allow_any_instance_of(ProcedureRevisionTypeDeChamp).to receive(:used_by_eligibilite_rules?).and_return(eligibilite_rules_used?)
render_inline(component)
end

Expand All @@ -29,6 +31,15 @@
expect(page).to have_text(/utilisé pour\nle routage/)
end
end

context 'drop down tdc used for eligibilite_rules' do
let(:eligibilite_rules_used?) { true }

it do
expect(page).to have_css("select[disabled=\"disabled\"]")
expect(page).to have_text(/l’eligibilité des dossiers/)
end
end
end

describe 'tdc ej' do
Expand Down

0 comments on commit 0e7c390

Please sign in to comment.