replace drop_down_list_enabled_non_empty_options by drop_down_options when possible

This commit is contained in:
simon lehericey 2024-09-19 16:28:09 +02:00
parent cfb03fc747
commit 532f0f48fa
No known key found for this signature in database
GPG key ID: CDE670D827C7B3C5
19 changed files with 38 additions and 41 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -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("« nest pas » ne s'applique pas au choix multiple.") }
end

View file

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

View file

@ -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",

View file

@ -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",

View file

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

View file

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

View file

@ -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'] }

View file

@ -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'] }

View file

@ -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'] }