diff --git a/app/components/editable_champ/drop_down_list_component.rb b/app/components/editable_champ/drop_down_list_component.rb index d6397b31c..58412ced9 100644 --- a/app/components/editable_champ/drop_down_list_component.rb +++ b/app/components/editable_champ/drop_down_list_component.rb @@ -23,7 +23,7 @@ class EditableChamp::DropDownListComponent < EditableChamp::EditableChampBaseCom def contains_long_option? max_length = 100 - @champ.drop_down_list_enabled_non_empty_options.any? { _1.size > max_length } + @champ.drop_down_options.any? { _1.size > max_length } end def react_props diff --git a/app/components/editable_champ/drop_down_list_component/drop_down_list_component.html.haml b/app/components/editable_champ/drop_down_list_component/drop_down_list_component.html.haml index 607250d8a..0fdf14c2c 100644 --- a/app/components/editable_champ/drop_down_list_component/drop_down_list_component.html.haml +++ b/app/components/editable_champ/drop_down_list_component/drop_down_list_component.html.haml @@ -1,6 +1,6 @@ - if @champ.render_as_radios? .fr-fieldset__content - - @champ.drop_down_list_enabled_non_empty_options.each_with_index do |option, index| + - @champ.drop_down_options.each_with_index do |option, index| .fr-radio-group = @form.radio_button :value, option, id: dom_id(@champ, "radio_option_#{index}") %label.fr-label{ for: dom_id(@champ, "radio_option_#{index}") } diff --git a/app/components/editable_champ/multiple_drop_down_list_component.rb b/app/components/editable_champ/multiple_drop_down_list_component.rb index 737e8720b..aec59c019 100644 --- a/app/components/editable_champ/multiple_drop_down_list_component.rb +++ b/app/components/editable_champ/multiple_drop_down_list_component.rb @@ -16,7 +16,7 @@ class EditableChamp::MultipleDropDownListComponent < EditableChamp::EditableCham class: 'fr-mt-1w', name: @form.field_name(:value, multiple: true), selected_keys: @champ.selected_options, - items: @champ.drop_down_list_enabled_non_empty_options, + items: @champ.drop_down_options, value_separator: false, 'aria-label': @champ.libelle, 'aria-describedby': @champ.describedby_id, diff --git a/app/components/editable_champ/multiple_drop_down_list_component/multiple_drop_down_list_component.html.haml b/app/components/editable_champ/multiple_drop_down_list_component/multiple_drop_down_list_component.html.haml index ca15f04f0..9faa09692 100644 --- a/app/components/editable_champ/multiple_drop_down_list_component/multiple_drop_down_list_component.html.haml +++ b/app/components/editable_champ/multiple_drop_down_list_component/multiple_drop_down_list_component.html.haml @@ -1,5 +1,5 @@ - if @champ.render_as_checkboxes? - = @form.collection_check_boxes :value, @champ.drop_down_list_enabled_non_empty_options, :to_s, :to_s do |b| + = @form.collection_check_boxes :value, @champ.drop_down_options, :to_s, :to_s do |b| - capture do .fr-fieldset__element .fr-checkbox-group diff --git a/app/models/champs/drop_down_list_champ.rb b/app/models/champs/drop_down_list_champ.rb index 0e26e7c97..67a83f281 100644 --- a/app/models/champs/drop_down_list_champ.rb +++ b/app/models/champs/drop_down_list_champ.rb @@ -9,11 +9,11 @@ class Champs::DropDownListChamp < Champ validate :value_is_in_options, if: -> { !(value.blank? || drop_down_other?) && validate_champ_value_or_prefill? } def render_as_radios? - drop_down_list_enabled_non_empty_options.size <= THRESHOLD_NB_OPTIONS_AS_RADIO + drop_down_options.size <= THRESHOLD_NB_OPTIONS_AS_RADIO end def render_as_combobox? - drop_down_list_enabled_non_empty_options.size >= THRESHOLD_NB_OPTIONS_AS_AUTOCOMPLETE + drop_down_options.size >= THRESHOLD_NB_OPTIONS_AS_AUTOCOMPLETE end def html_label? @@ -29,7 +29,7 @@ class Champs::DropDownListChamp < Champ end def other? - drop_down_other? && (other || (value.present? && drop_down_list_enabled_non_empty_options.exclude?(value))) + drop_down_other? && (other || (value.present? && drop_down_options.exclude?(value))) end def value=(value) @@ -67,7 +67,7 @@ class Champs::DropDownListChamp < Champ private def value_is_in_options - return if drop_down_list_enabled_non_empty_options.include?(value) + return if drop_down_options.include?(value) errors.add(:value, :not_in_options) end diff --git a/app/models/champs/multiple_drop_down_list_champ.rb b/app/models/champs/multiple_drop_down_list_champ.rb index fc1e34799..8ea0bec25 100644 --- a/app/models/champs/multiple_drop_down_list_champ.rb +++ b/app/models/champs/multiple_drop_down_list_champ.rb @@ -14,7 +14,7 @@ class Champs::MultipleDropDownListChamp < Champ end def render_as_checkboxes? - drop_down_list_enabled_non_empty_options.size <= THRESHOLD_NB_OPTIONS_AS_CHECKBOX + drop_down_options.size <= THRESHOLD_NB_OPTIONS_AS_CHECKBOX end def html_label? @@ -47,7 +47,7 @@ class Champs::MultipleDropDownListChamp < Champ end def focusable_input_id - render_as_checkboxes? ? checkbox_id(drop_down_list_enabled_non_empty_options.first) : input_id + render_as_checkboxes? ? checkbox_id(drop_down_options.first) : input_id end def checkbox_id(value) @@ -63,7 +63,7 @@ class Champs::MultipleDropDownListChamp < Champ end def unselected_options - drop_down_list_enabled_non_empty_options - selected_options + drop_down_options - selected_options end def value=(value) @@ -93,7 +93,7 @@ class Champs::MultipleDropDownListChamp < Champ def values_are_in_options json = selected_options.compact_blank return if json.empty? - return if (json - drop_down_list_enabled_non_empty_options).empty? + return if (json - drop_down_options).empty? errors.add(:value, :not_in_options) end diff --git a/app/models/type_de_champ.rb b/app/models/type_de_champ.rb index 8f9bc7c70..653544927 100644 --- a/app/models/type_de_champ.rb +++ b/app/models/type_de_champ.rb @@ -559,7 +559,7 @@ class TypeDeChamp < ApplicationRecord APIGeoService.regions.map { [_1[:name], _1[:code]] } elsif choice_type? if drop_down_list? - drop_down_list_enabled_non_empty_options + drop_down_options elsif yes_no? Champs::YesNoChamp.options elsif checkbox? diff --git a/app/models/types_de_champ/prefill_drop_down_list_type_de_champ.rb b/app/models/types_de_champ/prefill_drop_down_list_type_de_champ.rb index 67629cc35..65702131a 100644 --- a/app/models/types_de_champ/prefill_drop_down_list_type_de_champ.rb +++ b/app/models/types_de_champ/prefill_drop_down_list_type_de_champ.rb @@ -3,12 +3,9 @@ class TypesDeChamp::PrefillDropDownListTypeDeChamp < TypesDeChamp::PrefillTypeDeChamp def all_possible_values if drop_down_other? - drop_down_list_enabled_non_empty_options.insert( - 0, - I18n.t("views.prefill_descriptions.edit.possible_values.drop_down_list_other_html") - ) + [I18n.t("views.prefill_descriptions.edit.possible_values.drop_down_list_other_html")] + drop_down_options else - drop_down_list_enabled_non_empty_options + drop_down_options end end diff --git a/app/validators/types_de_champ/no_empty_drop_down_validator.rb b/app/validators/types_de_champ/no_empty_drop_down_validator.rb index 9c4a235d3..8dda5b772 100644 --- a/app/validators/types_de_champ/no_empty_drop_down_validator.rb +++ b/app/validators/types_de_champ/no_empty_drop_down_validator.rb @@ -10,7 +10,7 @@ class TypesDeChamp::NoEmptyDropDownValidator < ActiveModel::EachValidator private def validate_drop_down_not_empty(procedure, attribute, drop_down) - if drop_down.drop_down_list_enabled_non_empty_options.empty? + if drop_down.drop_down_options.empty? procedure.errors.add( attribute, procedure.errors.generate_message(attribute, :empty_drop_down, { value: drop_down.libelle }), diff --git a/app/views/dossiers/dossier_vide.pdf.prawn b/app/views/dossiers/dossier_vide.pdf.prawn index 0e6467972..7ff408453 100644 --- a/app/views/dossiers/dossier_vide.pdf.prawn +++ b/app/views/dossiers/dossier_vide.pdf.prawn @@ -163,7 +163,7 @@ def render_single_champ(pdf, revision, type_de_champ) add_libelle(pdf, type_de_champ) add_optionnal_description(pdf, type_de_champ) add_explanation(pdf, 'Cochez la mention applicable, une seule valeur possible') - type_de_champ.drop_down_list_enabled_non_empty_options.each do |option| + type_de_champ.drop_down_options.each do |option| format_with_checkbox(pdf, option) end pdf.text "\n" @@ -171,7 +171,7 @@ def render_single_champ(pdf, revision, type_de_champ) add_libelle(pdf, type_de_champ) add_optionnal_description(pdf, type_de_champ) add_explanation(pdf, 'Cochez la mention applicable, plusieurs valeurs possibles') - type_de_champ.drop_down_list_enabled_non_empty_options.each do |option| + type_de_champ.drop_down_options.each do |option| format_with_checkbox(pdf, option) end pdf.text "\n" diff --git a/spec/components/types_de_champ_editor/conditions_errors_component_spec.rb b/spec/components/types_de_champ_editor/conditions_errors_component_spec.rb index 3b550b3ad..8cd9e4361 100644 --- a/spec/components/types_de_champ_editor/conditions_errors_component_spec.rb +++ b/spec/components/types_de_champ_editor/conditions_errors_component_spec.rb @@ -77,7 +77,7 @@ describe Conditions::ConditionsErrorsComponent, type: :component do context 'when an eq operator applies to a multiple_drop_down' do let(:tdc) { create(:type_de_champ_multiple_drop_down_list) } let(:source_tdcs) { [tdc] } - let(:conditions) { [ds_eq(champ_value(tdc.stable_id), constant(tdc.drop_down_list_enabled_non_empty_options.first))] } + let(:conditions) { [ds_eq(champ_value(tdc.stable_id), constant(tdc.drop_down_options.first))] } it { expect(page).to have_content("« est » ne s'applique pas au choix multiple.") } end @@ -85,7 +85,7 @@ describe Conditions::ConditionsErrorsComponent, type: :component do context 'when an not_eq operator applies to a multiple_drop_down' do let(:tdc) { create(:type_de_champ_multiple_drop_down_list) } let(:source_tdcs) { [tdc] } - let(:conditions) { [ds_not_eq(champ_value(tdc.stable_id), constant(tdc.drop_down_list_enabled_non_empty_options.first))] } + let(:conditions) { [ds_not_eq(champ_value(tdc.stable_id), constant(tdc.drop_down_options.first))] } it { expect(page).to have_content("« n’est pas » ne s'applique pas au choix multiple.") } end diff --git a/spec/factories/dossier.rb b/spec/factories/dossier.rb index 20e88820c..f599a410b 100644 --- a/spec/factories/dossier.rb +++ b/spec/factories/dossier.rb @@ -263,9 +263,9 @@ FactoryBot.define do dossier.champs_to_destroy.where(private: false).destroy_all dossier.types_de_champ.each do |type_de_champ| value = if type_de_champ.simple_drop_down_list? - type_de_champ.drop_down_list_enabled_non_empty_options.first + type_de_champ.drop_down_options.first elsif type_de_champ.multiple_drop_down_list? - type_de_champ.drop_down_list_enabled_non_empty_options.first(2).to_json + type_de_champ.drop_down_options.first(2).to_json end attrs = { stable_id: type_de_champ.stable_id, dossier:, value: }.compact create(:"champ_do_not_use_#{type_de_champ.type_champ}", **attrs) @@ -279,9 +279,9 @@ FactoryBot.define do dossier.champs_to_destroy.where(private: true).destroy_all dossier.types_de_champ_private.each do |type_de_champ| value = if type_de_champ.simple_drop_down_list? - type_de_champ.drop_down_list_enabled_non_empty_options.first + type_de_champ.drop_down_options.first elsif type_de_champ.multiple_drop_down_list? - type_de_champ.drop_down_list_enabled_non_empty_options.first(2).to_json + type_de_champ.drop_down_options.first(2).to_json end attrs = { stable_id: type_de_champ.stable_id, dossier:, private: true, value: }.compact create(:"champ_do_not_use_#{type_de_champ.type_champ}", **attrs) diff --git a/spec/models/logic/eq_spec.rb b/spec/models/logic/eq_spec.rb index 39911a29d..fb84ad930 100644 --- a/spec/models/logic/eq_spec.rb +++ b/spec/models/logic/eq_spec.rb @@ -22,7 +22,7 @@ describe Logic::Eq do it do multiple_drop_down = create(:type_de_champ_multiple_drop_down_list) - first_option = multiple_drop_down.drop_down_list_enabled_non_empty_options.first + first_option = multiple_drop_down.drop_down_options.first expected = { operator_name: "Logic::Eq", diff --git a/spec/models/logic/not_eq_spec.rb b/spec/models/logic/not_eq_spec.rb index 0893bc583..a1157e311 100644 --- a/spec/models/logic/not_eq_spec.rb +++ b/spec/models/logic/not_eq_spec.rb @@ -22,7 +22,7 @@ describe Logic::NotEq do it do multiple_drop_down = create(:type_de_champ_multiple_drop_down_list) - first_option = multiple_drop_down.drop_down_list_enabled_non_empty_options.first + first_option = multiple_drop_down.drop_down_options.first expected = { operator_name: "Logic::NotEq", diff --git a/spec/models/logic_spec.rb b/spec/models/logic_spec.rb index d23bb1187..900c8ed5e 100644 --- a/spec/models/logic_spec.rb +++ b/spec/models/logic_spec.rb @@ -48,7 +48,7 @@ describe Logic do context 'when dropdown empty operator true' do let(:drop_down) { create(:type_de_champ_drop_down_list) } let(:type_de_champs) { [drop_down] } - let(:first_option) { drop_down.drop_down_list_enabled_non_empty_options.first } + let(:first_option) { drop_down.drop_down_options.first } let(:condition) { empty_operator(champ_value(drop_down.stable_id), constant(true)) } it { is_expected.to eq(ds_eq(champ_value(drop_down.stable_id), constant(first_option))) } @@ -57,7 +57,7 @@ describe Logic do context 'when multiple dropdown empty operator true' do let(:multiple_drop_down) { create(:type_de_champ_multiple_drop_down_list) } let(:type_de_champs) { [multiple_drop_down] } - let(:first_option) { multiple_drop_down.drop_down_list_enabled_non_empty_options.first } + let(:first_option) { multiple_drop_down.drop_down_options.first } let(:condition) { empty_operator(champ_value(multiple_drop_down.stable_id), constant(true)) } it { is_expected.to eq(ds_include(champ_value(multiple_drop_down.stable_id), constant(first_option))) } @@ -70,7 +70,7 @@ describe Logic do context 'with a dropdown' do let(:drop_down) { create(:type_de_champ_drop_down_list) } - let(:first_option) { drop_down.drop_down_list_enabled_non_empty_options.first } + let(:first_option) { drop_down.drop_down_options.first } it do expect(Logic.compatible_type?(champ_value(drop_down.stable_id), constant('a'), [drop_down])).to be true diff --git a/spec/models/types_de_champ/prefill_drop_down_list_type_de_champ_spec.rb b/spec/models/types_de_champ/prefill_drop_down_list_type_de_champ_spec.rb index f1a4c65da..661413489 100644 --- a/spec/models/types_de_champ/prefill_drop_down_list_type_de_champ_spec.rb +++ b/spec/models/types_de_champ/prefill_drop_down_list_type_de_champ_spec.rb @@ -12,7 +12,7 @@ RSpec.describe TypesDeChamp::PrefillDropDownListTypeDeChamp do it { expect(possible_values).to match( - ([I18n.t("views.prefill_descriptions.edit.possible_values.drop_down_list_other_html")] + type_de_champ.drop_down_list_enabled_non_empty_options).to_sentence + ([I18n.t("views.prefill_descriptions.edit.possible_values.drop_down_list_other_html")] + type_de_champ.drop_down_options).to_sentence ) } end @@ -20,7 +20,7 @@ RSpec.describe TypesDeChamp::PrefillDropDownListTypeDeChamp do context "when the drop down list does not accept 'other'" do let(:type_de_champ) { build(:type_de_champ_drop_down_list, procedure:) } - it { expect(possible_values).to match(type_de_champ.drop_down_list_enabled_non_empty_options.to_sentence) } + it { expect(possible_values).to match(type_de_champ.drop_down_options.to_sentence) } end end @@ -29,6 +29,6 @@ RSpec.describe TypesDeChamp::PrefillDropDownListTypeDeChamp do let(:type_de_champ) { build(:type_de_champ_drop_down_list, procedure: procedure) } subject(:example_value) { described_class.new(type_de_champ, procedure.active_revision).example_value } - it { expect(example_value).to eq(type_de_champ.drop_down_list_enabled_non_empty_options.first) } + it { expect(example_value).to eq(type_de_champ.drop_down_options.first) } end end diff --git a/spec/system/users/dossier_prefill_get_spec.rb b/spec/system/users/dossier_prefill_get_spec.rb index a53d50a23..616e282b0 100644 --- a/spec/system/users/dossier_prefill_get_spec.rb +++ b/spec/system/users/dossier_prefill_get_spec.rb @@ -43,8 +43,8 @@ describe 'Prefilling a dossier (with a GET request):', js: true do let(:datetime_value) { "2023-02-01T10:32" } let(:multiple_drop_down_list_values) { [ - type_de_champ_multiple_drop_down_list.drop_down_list_enabled_non_empty_options.first, - type_de_champ_multiple_drop_down_list.drop_down_list_enabled_non_empty_options.last + type_de_champ_multiple_drop_down_list.drop_down_options.first, + type_de_champ_multiple_drop_down_list.drop_down_options.last ] } let(:epci_value) { ['01', '200029999'] } diff --git a/spec/system/users/dossier_prefill_post_spec.rb b/spec/system/users/dossier_prefill_post_spec.rb index 9ae750962..55d0f99da 100644 --- a/spec/system/users/dossier_prefill_post_spec.rb +++ b/spec/system/users/dossier_prefill_post_spec.rb @@ -43,8 +43,8 @@ describe 'Prefilling a dossier (with a POST request):', js: true do let(:datetime_value) { "2023-02-01T10:32" } let(:multiple_drop_down_list_values) { [ - type_de_champ_multiple_drop_down_list.drop_down_list_enabled_non_empty_options.first, - type_de_champ_multiple_drop_down_list.drop_down_list_enabled_non_empty_options.last + type_de_champ_multiple_drop_down_list.drop_down_options.first, + type_de_champ_multiple_drop_down_list.drop_down_options.last ] } let(:epci_value) { ['01', '200029999'] } diff --git a/spec/views/shared/dossiers/_edit.html.haml_spec.rb b/spec/views/shared/dossiers/_edit.html.haml_spec.rb index 1eb3f68be..c974ecc0d 100644 --- a/spec/views/shared/dossiers/_edit.html.haml_spec.rb +++ b/spec/views/shared/dossiers/_edit.html.haml_spec.rb @@ -46,7 +46,7 @@ describe 'shared/dossiers/edit', type: :view do let(:types_de_champ_public) { [{ type: :drop_down_list, options:, mandatory: }] } let(:champ) { dossier.champs_public.first } let(:type_de_champ) { champ.type_de_champ } - let(:enabled_options) { type_de_champ.drop_down_list_enabled_non_empty_options } + let(:enabled_options) { type_de_champ.drop_down_options } let(:mandatory) { true } let(:options) { nil } @@ -86,7 +86,7 @@ describe 'shared/dossiers/edit', type: :view do let(:champ) { dossier.champs.first } let(:type_de_champ) { champ.type_de_champ } let(:options) { type_de_champ.drop_down_options } - let(:enabled_options) { type_de_champ.drop_down_list_enabled_non_empty_options } + let(:enabled_options) { type_de_champ.drop_down_options } context 'when the list is short' do let(:options) { ['valid', 'invalid', 'not sure yet'] }