Merge pull request #10826 from demarches-simplifiees/drop_down_clean_second_part

Tech: nettoyage des listes déroulantes seconde partie
This commit is contained in:
LeSim 2024-09-30 14:20:21 +00:00 committed by GitHub
commit ebb4763c86
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
39 changed files with 151 additions and 182 deletions

View file

@ -23,7 +23,7 @@ class EditableChamp::DropDownListComponent < EditableChamp::EditableChampBaseCom
def contains_long_option? def contains_long_option?
max_length = 100 max_length = 100
@champ.enabled_non_empty_options.any? { _1.size > max_length } @champ.drop_down_options.any? { _1.size > max_length }
end end
def react_props def react_props
@ -31,7 +31,7 @@ class EditableChamp::DropDownListComponent < EditableChamp::EditableChampBaseCom
class: 'fr-mt-1w', class: 'fr-mt-1w',
name: @form.field_name(:value), name: @form.field_name(:value),
selected_key: @champ.selected, selected_key: @champ.selected,
items: @champ.enabled_non_empty_options(other: true).map { _1.is_a?(Array) ? _1 : [_1, _1] }, items: @champ.drop_down_options_with_other.map { _1.is_a?(Array) ? _1 : [_1, _1] },
empty_filter_key: @champ.drop_down_other? ? Champs::DropDownListChamp::OTHER : nil, empty_filter_key: @champ.drop_down_other? ? Champs::DropDownListChamp::OTHER : nil,
'aria-describedby': @champ.describedby_id, 'aria-describedby': @champ.describedby_id,
'aria-labelledby': @champ.labelledby_id) 'aria-labelledby': @champ.labelledby_id)

View file

@ -1,6 +1,6 @@
- if @champ.render_as_radios? - if @champ.render_as_radios?
.fr-fieldset__content .fr-fieldset__content
- @champ.enabled_non_empty_options.each_with_index do |option, index| - @champ.drop_down_options.each_with_index do |option, index|
.fr-radio-group .fr-radio-group
= @form.radio_button :value, option, id: dom_id(@champ, "radio_option_#{index}") = @form.radio_button :value, option, id: dom_id(@champ, "radio_option_#{index}")
%label.fr-label{ for: dom_id(@champ, "radio_option_#{index}") } %label.fr-label{ for: dom_id(@champ, "radio_option_#{index}") }
@ -22,7 +22,7 @@
= render ReactComponent.new "ComboBox/SingleComboBox", **react_props = render ReactComponent.new "ComboBox/SingleComboBox", **react_props
- else - else
= @form.select :value, = @form.select :value,
@champ.enabled_non_empty_options(other: true), @champ.drop_down_options_with_other,
{ selected: @champ.selected, include_blank: true }, { selected: @champ.selected, include_blank: true },
required: @champ.required?, required: @champ.required?,
id: @champ.input_id, id: @champ.input_id,

View file

@ -16,7 +16,7 @@ class EditableChamp::MultipleDropDownListComponent < EditableChamp::EditableCham
class: 'fr-mt-1w', class: 'fr-mt-1w',
name: @form.field_name(:value, multiple: true), name: @form.field_name(:value, multiple: true),
selected_keys: @champ.selected_options, selected_keys: @champ.selected_options,
items: @champ.enabled_non_empty_options, items: @champ.drop_down_options,
value_separator: false, value_separator: false,
'aria-label': @champ.libelle, 'aria-label': @champ.libelle,
'aria-describedby': @champ.describedby_id, 'aria-describedby': @champ.describedby_id,

View file

@ -1,5 +1,5 @@
- if @champ.render_as_checkboxes? - if @champ.render_as_checkboxes?
= @form.collection_check_boxes :value, @champ.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 - capture do
.fr-fieldset__element .fr-fieldset__element
.fr-checkbox-group .fr-checkbox-group

View file

@ -71,8 +71,12 @@
- if type_de_champ.drop_down_list? - if type_de_champ.drop_down_list?
.flex.column.justify-start.width-33 .flex.column.justify-start.width-33
.cell .cell
= form.label :drop_down_list_value, "Options de la liste", for: dom_id(type_de_champ, :drop_down_list_value) = form.label :drop_down_options_from_text, "Options de la liste", for: dom_id(type_de_champ, :drop_down_options_from_text)
= form.text_area :drop_down_list_value, class: 'fr-input small-margin small width-100', rows: 7, id: dom_id(type_de_champ, :drop_down_list_value) = form.text_area :drop_down_options_from_text,
value: type_de_champ.drop_down_options.join("\r\n"),
class: 'fr-input small-margin small width-100',
rows: 7,
id: dom_id(type_de_champ, :drop_down_options_from_text)
- if type_de_champ.simple_drop_down_list? - if type_de_champ.simple_drop_down_list?
.cell .cell
= form.label :drop_down_other, for: dom_id(type_de_champ, :drop_down_other) do = form.label :drop_down_other, for: dom_id(type_de_champ, :drop_down_other) do

View file

@ -153,7 +153,7 @@ module Administrateurs
:libelle, :libelle,
:description, :description,
:mandatory, :mandatory,
:drop_down_list_value, :drop_down_options_from_text,
:drop_down_other, :drop_down_other,
:drop_down_secondary_libelle, :drop_down_secondary_libelle,
:drop_down_secondary_description, :drop_down_secondary_description,

View file

@ -53,19 +53,23 @@ class RootController < ApplicationController
repetition_after_stable_id = repetition_type_de_champ.stable_id repetition_after_stable_id = repetition_type_de_champ.stable_id
end end
elsif type_de_champ.linked_drop_down_list? elsif type_de_champ.linked_drop_down_list?
type_de_champ.drop_down_list_value = type_de_champ.drop_down_options =
"-- section 1 -- [
option A "-- section 1 --",
option B "option A",
-- section 2 -- "option B",
option C" "-- section 2 --",
"option C"
]
type_de_champ.save type_de_champ.save
elsif type_de_champ.drop_down_list? elsif type_de_champ.drop_down_list?
type_de_champ.drop_down_list_value = type_de_champ.drop_down_options =
"option A [
option B "option A",
-- avant l'option C -- "option B",
option C" "-- avant l'option C --",
"option C"
]
type_de_champ.save type_de_champ.save
end end
end end

View file

@ -31,7 +31,7 @@ class Champ < ApplicationRecord
:description, :description,
:drop_down_options, :drop_down_options,
:drop_down_other?, :drop_down_other?,
:drop_down_list_enabled_non_empty_options, :drop_down_options_with_other,
:drop_down_secondary_libelle, :drop_down_secondary_libelle,
:drop_down_secondary_description, :drop_down_secondary_description,
:collapsible_explanation_enabled?, :collapsible_explanation_enabled?,

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? } validate :value_is_in_options, if: -> { !(value.blank? || drop_down_other?) && validate_champ_value_or_prefill? }
def render_as_radios? def render_as_radios?
enabled_non_empty_options.size <= THRESHOLD_NB_OPTIONS_AS_RADIO drop_down_options.size <= THRESHOLD_NB_OPTIONS_AS_RADIO
end end
def render_as_combobox? def render_as_combobox?
enabled_non_empty_options.size >= THRESHOLD_NB_OPTIONS_AS_AUTOCOMPLETE drop_down_options.size >= THRESHOLD_NB_OPTIONS_AS_AUTOCOMPLETE
end end
def html_label? def html_label?
@ -28,12 +28,8 @@ class Champs::DropDownListChamp < Champ
other? ? OTHER : value other? ? OTHER : value
end end
def enabled_non_empty_options(other: false)
drop_down_list_enabled_non_empty_options(other:)
end
def other? def other?
drop_down_other? && (other || (value.present? && enabled_non_empty_options.exclude?(value))) drop_down_other? && (other || (value.present? && drop_down_options.exclude?(value)))
end end
def value=(value) def value=(value)
@ -71,7 +67,7 @@ class Champs::DropDownListChamp < Champ
private private
def value_is_in_options def value_is_in_options
return if enabled_non_empty_options.include?(value) return if drop_down_options.include?(value)
errors.add(:value, :not_in_options) errors.add(:value, :not_in_options)
end end

View file

@ -3,10 +3,6 @@
class Champs::MultipleDropDownListChamp < Champ class Champs::MultipleDropDownListChamp < Champ
validate :values_are_in_options, if: -> { value.present? && validate_champ_value_or_prefill? } validate :values_are_in_options, if: -> { value.present? && validate_champ_value_or_prefill? }
def enabled_non_empty_options
drop_down_list_enabled_non_empty_options
end
THRESHOLD_NB_OPTIONS_AS_CHECKBOX = 5 THRESHOLD_NB_OPTIONS_AS_CHECKBOX = 5
def search_terms def search_terms
@ -18,7 +14,7 @@ class Champs::MultipleDropDownListChamp < Champ
end end
def render_as_checkboxes? def render_as_checkboxes?
enabled_non_empty_options.size <= THRESHOLD_NB_OPTIONS_AS_CHECKBOX drop_down_options.size <= THRESHOLD_NB_OPTIONS_AS_CHECKBOX
end end
def html_label? def html_label?
@ -51,7 +47,7 @@ class Champs::MultipleDropDownListChamp < Champ
end end
def focusable_input_id def focusable_input_id
render_as_checkboxes? ? checkbox_id(enabled_non_empty_options.first) : input_id render_as_checkboxes? ? checkbox_id(drop_down_options.first) : input_id
end end
def checkbox_id(value) def checkbox_id(value)
@ -67,7 +63,7 @@ class Champs::MultipleDropDownListChamp < Champ
end end
def unselected_options def unselected_options
enabled_non_empty_options - selected_options drop_down_options - selected_options
end end
def value=(value) def value=(value)
@ -97,7 +93,7 @@ class Champs::MultipleDropDownListChamp < Champ
def values_are_in_options def values_are_in_options
json = selected_options.compact_blank json = selected_options.compact_blank
return if json.empty? return if json.empty?
return if (json - enabled_non_empty_options).empty? return if (json - drop_down_options).empty?
errors.add(:value, :not_in_options) errors.add(:value, :not_in_options)
end end

View file

@ -128,7 +128,7 @@ class Logic::ChampValue < Logic::Term
elsif operator_name.in?([Logic::InDepartementOperator.name, Logic::NotInDepartementOperator.name]) || tdc.type_champ.in?([MANAGED_TYPE_DE_CHAMP.fetch(:communes), MANAGED_TYPE_DE_CHAMP.fetch(:epci), MANAGED_TYPE_DE_CHAMP.fetch(:departements), MANAGED_TYPE_DE_CHAMP.fetch(:address)]) elsif operator_name.in?([Logic::InDepartementOperator.name, Logic::NotInDepartementOperator.name]) || tdc.type_champ.in?([MANAGED_TYPE_DE_CHAMP.fetch(:communes), MANAGED_TYPE_DE_CHAMP.fetch(:epci), MANAGED_TYPE_DE_CHAMP.fetch(:departements), MANAGED_TYPE_DE_CHAMP.fetch(:address)])
APIGeoService.departements.map { ["#{_1[:code]} #{_1[:name]}", _1[:code]] } APIGeoService.departements.map { ["#{_1[:code]} #{_1[:name]}", _1[:code]] }
else else
tdc.drop_down_list_enabled_non_empty_options(other: true).map { _1.is_a?(Array) ? _1 : [_1, _1] } tdc.drop_down_options_with_other.map { _1.is_a?(Array) ? _1 : [_1, _1] }
end end
end end

View file

@ -480,28 +480,18 @@ class TypeDeChamp < ApplicationRecord
Array.wrap(super) Array.wrap(super)
end end
def drop_down_list_enabled_non_empty_options(other: false) def drop_down_options_from_text=(text)
list_options = drop_down_options.reject(&:empty?) self.drop_down_options = text.to_s.lines.map(&:strip).reject(&:empty?)
if other && drop_down_other?
list_options + [[I18n.t('shared.champs.drop_down_list.other'), Champs::DropDownListChamp::OTHER]]
else
list_options
end
end end
def drop_down_list_value def drop_down_options_with_other
if drop_down_options.present? if drop_down_other?
drop_down_options.reject(&:empty?).join("\r\n") drop_down_options + [[I18n.t('shared.champs.drop_down_list.other'), Champs::DropDownListChamp::OTHER]]
else else
'' drop_down_options
end end
end end
def drop_down_list_value=(value)
self.drop_down_options = value.to_s.lines.map(&:strip).reject(&:empty?)
end
def header_section_level_value def header_section_level_value
if header_section_level.presence if header_section_level.presence
header_section_level.to_i header_section_level.to_i
@ -569,7 +559,7 @@ class TypeDeChamp < ApplicationRecord
APIGeoService.regions.map { [_1[:name], _1[:code]] } APIGeoService.regions.map { [_1[:name], _1[:code]] }
elsif choice_type? elsif choice_type?
if drop_down_list? if drop_down_list?
drop_down_list_enabled_non_empty_options drop_down_options
elsif yes_no? elsif yes_no?
Champs::YesNoChamp.options Champs::YesNoChamp.options
elsif checkbox? elsif checkbox?
@ -788,9 +778,9 @@ class TypeDeChamp < ApplicationRecord
self.drop_down_options = nil self.drop_down_options = nil
elsif !drop_down_options_changed? elsif !drop_down_options_changed?
self.drop_down_options = if linked_drop_down_list? self.drop_down_options = if linked_drop_down_list?
['', '--Fromage--', 'bleu de sassenage', 'picodon', '--Dessert--', 'éclair', 'tarte aux pommes'] ['--Fromage--', 'bleu de sassenage', 'picodon', '--Dessert--', 'éclair', 'tarte aux pommes']
else else
['', 'Premier choix', 'Deuxième choix'] ['Premier choix', 'Deuxième choix']
end end
end end
end end

View file

@ -89,9 +89,7 @@ class TypesDeChamp::LinkedDropDownListTypeDeChamp < TypesDeChamp::TypeDeChampBas
end end
def unpack_options def unpack_options
chunked = drop_down_options chunked = drop_down_options.slice_before(PRIMARY_PATTERN)
.reject(&:empty?) # TODO: remove after removing empty options
.slice_before(PRIMARY_PATTERN)
chunked.map do |chunk| chunked.map do |chunk|
primary, *secondary = chunk primary, *secondary = chunk
@ -101,8 +99,7 @@ class TypesDeChamp::LinkedDropDownListTypeDeChamp < TypesDeChamp::TypeDeChampBas
end end
def check_presence_of_primary_options def check_presence_of_primary_options
# TODO: replace by `drop_down_options.first` when the empty options are removed if !PRIMARY_PATTERN.match?(drop_down_options.first)
if !PRIMARY_PATTERN.match?(drop_down_options.find(&:present?))
errors.add(libelle.presence || "La liste", "doit commencer par une entrée de menu primaire de la forme <code style='white-space: pre-wrap;'>--texte--</code>") errors.add(libelle.presence || "La liste", "doit commencer par une entrée de menu primaire de la forme <code style='white-space: pre-wrap;'>--texte--</code>")
end end
end end

View file

@ -3,12 +3,9 @@
class TypesDeChamp::PrefillDropDownListTypeDeChamp < TypesDeChamp::PrefillTypeDeChamp class TypesDeChamp::PrefillDropDownListTypeDeChamp < TypesDeChamp::PrefillTypeDeChamp
def all_possible_values def all_possible_values
if drop_down_other? if drop_down_other?
drop_down_list_enabled_non_empty_options.insert( [I18n.t("views.prefill_descriptions.edit.possible_values.drop_down_list_other_html")] + drop_down_options
0,
I18n.t("views.prefill_descriptions.edit.possible_values.drop_down_list_other_html")
)
else else
drop_down_list_enabled_non_empty_options drop_down_options
end end
end end

View file

@ -10,7 +10,7 @@ class TypesDeChamp::NoEmptyDropDownValidator < ActiveModel::EachValidator
private private
def validate_drop_down_not_empty(procedure, attribute, drop_down) 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( procedure.errors.add(
attribute, attribute,
procedure.errors.generate_message(attribute, :empty_drop_down, { value: drop_down.libelle }), 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_libelle(pdf, type_de_champ)
add_optionnal_description(pdf, type_de_champ) add_optionnal_description(pdf, type_de_champ)
add_explanation(pdf, 'Cochez la mention applicable, une seule valeur possible') 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) format_with_checkbox(pdf, option)
end end
pdf.text "\n" pdf.text "\n"
@ -171,7 +171,7 @@ def render_single_champ(pdf, revision, type_de_champ)
add_libelle(pdf, type_de_champ) add_libelle(pdf, type_de_champ)
add_optionnal_description(pdf, type_de_champ) add_optionnal_description(pdf, type_de_champ)
add_explanation(pdf, 'Cochez la mention applicable, plusieurs valeurs possibles') 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) format_with_checkbox(pdf, option)
end end
pdf.text "\n" pdf.text "\n"

View file

@ -15,7 +15,7 @@ namespace :after_party do
progress = ProgressReport.new(types_de_champ.count) progress = ProgressReport.new(types_de_champ.count)
types_de_champ.find_each do |type_de_champ| types_de_champ.find_each do |type_de_champ|
type_de_champ.drop_down_list_value = type_de_champ.drop_down_list_value type_de_champ.drop_down_options_from_text = type_de_champ.drop_down_list_value
if type_de_champ.save if type_de_champ.save
type_de_champ.drop_down_list.destroy type_de_champ.drop_down_list.destroy

View file

@ -15,7 +15,7 @@ class TypesDeChampEditor::ConditionsComponentPreview < ViewComponent::Preview
def with_conditions def with_conditions
surface = TypeDeChamp.create(type_champ: :integer_number, libelle: 'surface') surface = TypeDeChamp.create(type_champ: :integer_number, libelle: 'surface')
appartement = TypeDeChamp.create(type_champ: :yes_no, libelle: 'appartement') appartement = TypeDeChamp.create(type_champ: :yes_no, libelle: 'appartement')
type_appartement = TypeDeChamp.create(type_champ: :drop_down_list, libelle: 'type', drop_down_list_value: "T1\r\nT2\r\nT3") type_appartement = TypeDeChamp.create(type_champ: :drop_down_list, libelle: 'type', drop_down_options: ["T1", "T2", "T3"])
upper_tdcs = [surface, appartement, type_appartement] upper_tdcs = [surface, appartement, type_appartement]
condition = ds_and([ condition = ds_and([

View file

@ -19,7 +19,7 @@ describe Procedure::OneGroupeManagementComponent, type: :component do
procedure.draft_revision.add_type_de_champ({ procedure.draft_revision.add_type_de_champ({
type_champ: :drop_down_list, type_champ: :drop_down_list,
libelle: 'Votre ville', libelle: 'Votre ville',
drop_down_list_value: "Paris\nLyon\nMarseille" drop_down_options: ["Paris", "Lyon", "Marseille"]
}) })
procedure.publish_revision! procedure.publish_revision!
procedure.reload procedure.reload

View file

@ -77,7 +77,7 @@ describe Conditions::ConditionsErrorsComponent, type: :component do
context 'when an eq operator applies to a multiple_drop_down' do context 'when an eq operator applies to a multiple_drop_down' do
let(:tdc) { create(:type_de_champ_multiple_drop_down_list) } let(:tdc) { create(:type_de_champ_multiple_drop_down_list) }
let(:source_tdcs) { [tdc] } 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.") } it { expect(page).to have_content("« est » ne s'applique pas au choix multiple.") }
end end
@ -85,7 +85,7 @@ describe Conditions::ConditionsErrorsComponent, type: :component do
context 'when an not_eq operator applies to a multiple_drop_down' 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(:tdc) { create(:type_de_champ_multiple_drop_down_list) }
let(:source_tdcs) { [tdc] } 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.") } it { expect(page).to have_content("« nest pas » ne s'applique pas au choix multiple.") }
end end

View file

@ -263,9 +263,9 @@ FactoryBot.define do
dossier.champs_to_destroy.where(private: false).destroy_all dossier.champs_to_destroy.where(private: false).destroy_all
dossier.types_de_champ.each do |type_de_champ| dossier.types_de_champ.each do |type_de_champ|
value = if type_de_champ.simple_drop_down_list? 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? 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 end
attrs = { stable_id: type_de_champ.stable_id, dossier:, value: }.compact attrs = { stable_id: type_de_champ.stable_id, dossier:, value: }.compact
create(:"champ_do_not_use_#{type_de_champ.type_champ}", **attrs) 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.champs_to_destroy.where(private: true).destroy_all
dossier.types_de_champ_private.each do |type_de_champ| dossier.types_de_champ_private.each do |type_de_champ|
value = if type_de_champ.simple_drop_down_list? 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? 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 end
attrs = { stable_id: type_de_champ.stable_id, dossier:, private: true, value: }.compact attrs = { stable_id: type_de_champ.stable_id, dossier:, private: true, value: }.compact
create(:"champ_do_not_use_#{type_de_champ.type_champ}", **attrs) create(:"champ_do_not_use_#{type_de_champ.type_champ}", **attrs)

View file

@ -308,13 +308,7 @@ def build_types_de_champ(types_de_champ, revision:, scope: :public, parent: nil)
end end
if type.in?([:drop_down_list, :multiple_drop_down_list, :linked_drop_down_list]) if type.in?([:drop_down_list, :multiple_drop_down_list, :linked_drop_down_list])
if options.delete(:short).present? type_de_champ_attributes[:drop_down_options] = options
type_de_champ_attributes[:drop_down_list_value] = "val1\r\nval2\r\n--separateur--\r\nval3"
elsif options.delete(:long).present?
type_de_champ_attributes[:drop_down_list_value] = "alpha\r\nbravo\r\n--separateur--\r\ncharly\r\ndelta\r\necho\r\nfox-trot\r\ngolf"
else
type_de_champ_attributes[:drop_down_list_value] = options.join("\r\n")
end
end end
end end

View file

@ -79,9 +79,9 @@ FactoryBot.define do
factory :type_de_champ_drop_down_list do factory :type_de_champ_drop_down_list do
libelle { 'Choix unique' } libelle { 'Choix unique' }
type_champ { TypeDeChamp.type_champs.fetch(:drop_down_list) } type_champ { TypeDeChamp.type_champs.fetch(:drop_down_list) }
drop_down_list_value { "val1\r\nval2\r\nval3" } drop_down_options { ["val1", "val2", "val3"] }
trait :long do trait :long do
drop_down_list_value { "alpha\r\nbravo\r\ncharly\r\ndelta\r\necho\r\nfox-trot\r\ngolf" } drop_down_options { ["alpha", "bravo", "charly", "delta", "echo", "fox-trot", "golf"] }
end end
trait :with_other do trait :with_other do
drop_down_other { true } drop_down_other { true }
@ -89,14 +89,14 @@ FactoryBot.define do
end end
factory :type_de_champ_multiple_drop_down_list do factory :type_de_champ_multiple_drop_down_list do
type_champ { TypeDeChamp.type_champs.fetch(:multiple_drop_down_list) } type_champ { TypeDeChamp.type_champs.fetch(:multiple_drop_down_list) }
drop_down_list_value { "val1\r\nval2\r\nval3" } drop_down_options { ["val1", "val2", "val3"] }
trait :long do trait :long do
drop_down_list_value { "alpha\r\nbravo\r\ncharly\r\ndelta\r\necho\r\nfox-trot\r\ngolf" } drop_down_options { ["alpha", "bravo", "charly", "delta", "echo", "fox-trot", "golf"] }
end end
end end
factory :type_de_champ_linked_drop_down_list do factory :type_de_champ_linked_drop_down_list do
type_champ { TypeDeChamp.type_champs.fetch(:linked_drop_down_list) } type_champ { TypeDeChamp.type_champs.fetch(:linked_drop_down_list) }
drop_down_list_value { "--primary--\r\nsecondary\n" } drop_down_options { ["--primary--", "secondary"] }
end end
factory :type_de_champ_expression_reguliere do factory :type_de_champ_expression_reguliere do
type_champ { TypeDeChamp.type_champs.fetch(:expression_reguliere) } type_champ { TypeDeChamp.type_champs.fetch(:expression_reguliere) }

View file

@ -4,18 +4,18 @@ describe '20240912091625_clean_drop_down_options.rake' do
let(:rake_task) { Rake::Task['after_party:clean_drop_down_options'] } let(:rake_task) { Rake::Task['after_party:clean_drop_down_options'] }
let!(:dashed_drop_down_list) do let!(:dashed_drop_down_list) do
drop_down_list_value = ['1', '-- nop --', '2'].join("\r\n") drop_down_options = ['1', '-- nop --', '2']
create(:type_de_champ_drop_down_list, drop_down_list_value:) create(:type_de_champ_drop_down_list, drop_down_options:)
end end
let!(:witness_drop_down_list) do let!(:witness_drop_down_list) do
drop_down_list_value = ['1', 'hi', '2'].join("\r\n") drop_down_options = ['1', 'hi', '2']
create(:type_de_champ_drop_down_list, drop_down_list_value:) create(:type_de_champ_drop_down_list, drop_down_options:)
end end
let!(:multiple_drop_down_list) do let!(:multiple_drop_down_list) do
drop_down_list_value = ['1', '-- nop --', '2'].join("\r\n") drop_down_options = ['1', '-- nop --', '2']
create(:type_de_champ_multiple_drop_down_list, drop_down_list_value:) create(:type_de_champ_multiple_drop_down_list, drop_down_options:)
end end
before do before do
@ -27,8 +27,8 @@ describe '20240912091625_clean_drop_down_options.rake' do
after { rake_task.reenable } after { rake_task.reenable }
it 'removes the hidden options' do it 'removes the hidden options' do
expect(dashed_drop_down_list.drop_down_list_value).to eq(['1', '2'].join("\r\n")) expect(dashed_drop_down_list.drop_down_options).to eq(['1', '2'])
expect(witness_drop_down_list.drop_down_list_value).to eq(['1', 'hi', '2'].join("\r\n")) expect(witness_drop_down_list.drop_down_options).to eq(['1', 'hi', '2'])
expect(multiple_drop_down_list.drop_down_list_value).to eq(['1', '2'].join("\r\n")) expect(multiple_drop_down_list.drop_down_options).to eq(['1', '2'])
end end
end end

View file

@ -78,13 +78,13 @@ describe Champs::LinkedDropDownListChamp do
end end
describe '#mandatory_and_blank' do describe '#mandatory_and_blank' do
let(:value) { "--Primary--\r\nSecondary" } let(:options) { ["--Primary--", "Secondary"] }
subject { described_class.new } subject { described_class.new }
before { allow(subject).to receive(:type_de_champ).and_return(type_de_champ) } before { allow(subject).to receive(:type_de_champ).and_return(type_de_champ) }
context 'when the champ is not mandatory' do context 'when the champ is not mandatory' do
let(:type_de_champ) { build(:type_de_champ_linked_drop_down_list, mandatory: false, drop_down_list_value: value) } let(:type_de_champ) { build(:type_de_champ_linked_drop_down_list, mandatory: false, drop_down_options: options) }
it 'blank is fine' do it 'blank is fine' do
is_expected.not_to be_mandatory_blank is_expected.not_to be_mandatory_blank
@ -92,7 +92,7 @@ describe Champs::LinkedDropDownListChamp do
end end
context 'when the champ is mandatory' do context 'when the champ is mandatory' do
let(:type_de_champ) { build(:type_de_champ_linked_drop_down_list, mandatory: true, drop_down_list_value: value) } let(:type_de_champ) { build(:type_de_champ_linked_drop_down_list, mandatory: true, drop_down_options: options) }
context 'when there is no value' do context 'when there is no value' do
it { is_expected.to be_mandatory_blank } it { is_expected.to be_mandatory_blank }
@ -112,7 +112,7 @@ describe Champs::LinkedDropDownListChamp do
end end
context 'when there is nothing to select for the secondary value' do context 'when there is nothing to select for the secondary value' do
let(:value) { "--A--\nAbbott\nAbelard\n--B--\n--C--\nCynthia" } let(:options) { ["--A--", "Abbott", "Abelard", "--B--", "--C--", "Cynthia"] }
before { subject.primary_value = 'B' } before { subject.primary_value = 'B' }
it { is_expected.not_to be_mandatory_blank } it { is_expected.not_to be_mandatory_blank }

View file

@ -1,7 +1,7 @@
# frozen_string_literal: true # frozen_string_literal: true
describe Champs::MultipleDropDownListChamp do describe Champs::MultipleDropDownListChamp do
let(:type_de_champ) { build(:type_de_champ_multiple_drop_down_list, drop_down_list_value: "val1\r\nval2\r\nval3\r\n[brackets] val4") } let(:type_de_champ) { build(:type_de_champ_multiple_drop_down_list, drop_down_options: ["val1", "val2", "val3", "[brackets] val4"]) }
let(:value) { nil } let(:value) { nil }
let(:champ) { Champs::MultipleDropDownListChamp.new(value:, dossier: build(:dossier)) } let(:champ) { Champs::MultipleDropDownListChamp.new(value:, dossier: build(:dossier)) }
before do before do

View file

@ -229,7 +229,7 @@ RSpec.describe DossierCloneConcern do
context 'invalid origin' do context 'invalid origin' do
let(:procedure) do let(:procedure) do
create(:procedure, types_de_champ_public: [ create(:procedure, types_de_champ_public: [
{ type: :drop_down_list, libelle: "Le savez-vous?", stable_id: 992, drop_down_list_value: ["Oui", "Non", "Peut-être"].join("\r\n"), mandatory: true } { type: :drop_down_list, libelle: "Le savez-vous?", stable_id: 992, drop_down_options: ["Oui", "Non", "Peut-être"], mandatory: true }
]) ])
end end

View file

@ -422,7 +422,7 @@ describe DossierRebaseConcern do
context 'with a procedure with a dropdown tdc' do context 'with a procedure with a dropdown tdc' do
let!(:procedure) do let!(:procedure) do
create(:procedure).tap do |p| create(:procedure).tap do |p|
p.draft_revision.add_type_de_champ(type_champ: :drop_down_list, libelle: 'l1', drop_down_list_value: "option\nv1\n") p.draft_revision.add_type_de_champ(type_champ: :drop_down_list, libelle: 'l1', drop_down_options: ["option", "v1"])
p.publish! p.publish!
end end
end end
@ -434,7 +434,7 @@ describe DossierRebaseConcern do
stable_id = procedure.draft_revision.types_de_champ.find_by(libelle: 'l1') stable_id = procedure.draft_revision.types_de_champ.find_by(libelle: 'l1')
tdc_to_update = procedure.draft_revision.find_and_ensure_exclusive_use(stable_id) tdc_to_update = procedure.draft_revision.find_and_ensure_exclusive_use(stable_id)
tdc_to_update.update(drop_down_list_value: "option\nupdated\nv1") tdc_to_update.update(drop_down_options: ["option", "updated", "v1"])
end end
it { expect { subject }.not_to change { dossier.champs_public.first.value } } it { expect { subject }.not_to change { dossier.champs_public.first.value } }
@ -446,7 +446,7 @@ describe DossierRebaseConcern do
stable_id = procedure.draft_revision.types_de_champ.find_by(libelle: 'l1') stable_id = procedure.draft_revision.types_de_champ.find_by(libelle: 'l1')
tdc_to_update = procedure.draft_revision.find_and_ensure_exclusive_use(stable_id) tdc_to_update = procedure.draft_revision.find_and_ensure_exclusive_use(stable_id)
tdc_to_update.update(drop_down_list_value: "option\nupdated") tdc_to_update.update(drop_down_options: ["option", "updated"])
end end
it { expect { subject }.to change { dossier.champs_public.first.value }.from('v1').to(nil) } it { expect { subject }.to change { dossier.champs_public.first.value }.from('v1').to(nil) }
@ -458,7 +458,7 @@ describe DossierRebaseConcern do
stable_id = procedure.draft_revision.types_de_champ.find_by(libelle: 'l1') stable_id = procedure.draft_revision.types_de_champ.find_by(libelle: 'l1')
tdc_to_update = procedure.draft_revision.find_and_ensure_exclusive_use(stable_id) tdc_to_update = procedure.draft_revision.find_and_ensure_exclusive_use(stable_id)
tdc_to_update.update(drop_down_list_value: "v1\nupdated") tdc_to_update.update(drop_down_options: ["v1", "updated"])
end end
it { expect { subject }.not_to change { dossier.champs_public.first.value } } it { expect { subject }.not_to change { dossier.champs_public.first.value } }
@ -468,7 +468,7 @@ describe DossierRebaseConcern do
context 'with a procedure with a multiple dropdown tdc' do context 'with a procedure with a multiple dropdown tdc' do
let!(:procedure) do let!(:procedure) do
create(:procedure).tap do |p| create(:procedure).tap do |p|
p.draft_revision.add_type_de_champ(type_champ: :multiple_drop_down_list, libelle: 'l1', drop_down_list_value: "option\nv1\n") p.draft_revision.add_type_de_champ(type_champ: :multiple_drop_down_list, libelle: 'l1', drop_down_options: ["option", "v1"])
p.publish! p.publish!
end end
end end
@ -480,7 +480,7 @@ describe DossierRebaseConcern do
stable_id = procedure.draft_revision.types_de_champ.find_by(libelle: 'l1') stable_id = procedure.draft_revision.types_de_champ.find_by(libelle: 'l1')
tdc_to_update = procedure.draft_revision.find_and_ensure_exclusive_use(stable_id) tdc_to_update = procedure.draft_revision.find_and_ensure_exclusive_use(stable_id)
tdc_to_update.update(drop_down_list_value: "option\nupdated\nv1") tdc_to_update.update(drop_down_options: ["option", "updated", "v1"])
end end
it { expect { subject }.not_to change { dossier.champs_public.first.value } } it { expect { subject }.not_to change { dossier.champs_public.first.value } }
@ -492,7 +492,7 @@ describe DossierRebaseConcern do
stable_id = procedure.draft_revision.types_de_champ.find_by(libelle: 'l1') stable_id = procedure.draft_revision.types_de_champ.find_by(libelle: 'l1')
tdc_to_update = procedure.draft_revision.find_and_ensure_exclusive_use(stable_id) tdc_to_update = procedure.draft_revision.find_and_ensure_exclusive_use(stable_id)
tdc_to_update.update(drop_down_list_value: "option\nupdated") tdc_to_update.update(drop_down_options: ["option", "updated"])
end end
it { expect { subject }.to change { dossier.champs_public.first.value }.from('["v1","option"]').to('["option"]') } it { expect { subject }.to change { dossier.champs_public.first.value }.from('["v1","option"]').to('["option"]') }
@ -504,7 +504,7 @@ describe DossierRebaseConcern do
stable_id = procedure.draft_revision.types_de_champ.find_by(libelle: 'l1') stable_id = procedure.draft_revision.types_de_champ.find_by(libelle: 'l1')
tdc_to_update = procedure.draft_revision.find_and_ensure_exclusive_use(stable_id) tdc_to_update = procedure.draft_revision.find_and_ensure_exclusive_use(stable_id)
tdc_to_update.update(drop_down_list_value: "v1\nupdated") tdc_to_update.update(drop_down_options: ["v1", "updated"])
end end
it { expect { subject }.not_to change { dossier.champs_public.first.value } } it { expect { subject }.not_to change { dossier.champs_public.first.value } }
@ -514,7 +514,7 @@ describe DossierRebaseConcern do
context 'with a procedure with a linked dropdown tdc' do context 'with a procedure with a linked dropdown tdc' do
let!(:procedure) do let!(:procedure) do
create(:procedure).tap do |p| create(:procedure).tap do |p|
p.draft_revision.add_type_de_champ(type_champ: :linked_drop_down_list, libelle: 'l1', drop_down_list_value: "--titre1--\noption\nv1\n--titre2--\noption2\nv2\n") p.draft_revision.add_type_de_champ(type_champ: :linked_drop_down_list, libelle: 'l1', drop_down_options: ["--titre1--", "option", "v1", "--titre2--", "option2", "v2"])
p.publish! p.publish!
end end
end end
@ -526,7 +526,7 @@ describe DossierRebaseConcern do
stable_id = procedure.draft_revision.types_de_champ.find_by(libelle: 'l1') stable_id = procedure.draft_revision.types_de_champ.find_by(libelle: 'l1')
tdc_to_update = procedure.draft_revision.find_and_ensure_exclusive_use(stable_id) tdc_to_update = procedure.draft_revision.find_and_ensure_exclusive_use(stable_id)
tdc_to_update.update(drop_down_list_value: "--titre1--\noption\nv1\nupdated\n--titre2--\noption2\nv2\n") tdc_to_update.update(drop_down_options: ["--titre1--", "option", "v1", "updated", "--titre2--", "option2", "v2"])
end end
it { expect { subject }.not_to change { dossier.champs_public.first.value } } it { expect { subject }.not_to change { dossier.champs_public.first.value } }
@ -538,7 +538,7 @@ describe DossierRebaseConcern do
stable_id = procedure.draft_revision.types_de_champ.find_by(libelle: 'l1') stable_id = procedure.draft_revision.types_de_champ.find_by(libelle: 'l1')
tdc_to_update = procedure.draft_revision.find_and_ensure_exclusive_use(stable_id) tdc_to_update = procedure.draft_revision.find_and_ensure_exclusive_use(stable_id)
tdc_to_update.update(drop_down_list_value: "--titre1--\noption\nupdated\n--titre2--\noption2\nv2\n") tdc_to_update.update(drop_down_options: ["--titre1--", "option", "updated", "--titre2--", "option2", "v2"])
end end
it { expect { subject }.to change { dossier.champs_public.first.value }.from('["v1","option2"]').to(nil) } it { expect { subject }.to change { dossier.champs_public.first.value }.from('["v1","option2"]').to(nil) }
@ -550,7 +550,7 @@ describe DossierRebaseConcern do
stable_id = procedure.draft_revision.types_de_champ.find_by(libelle: 'l1') stable_id = procedure.draft_revision.types_de_champ.find_by(libelle: 'l1')
tdc_to_update = procedure.draft_revision.find_and_ensure_exclusive_use(stable_id) tdc_to_update = procedure.draft_revision.find_and_ensure_exclusive_use(stable_id)
tdc_to_update.update(drop_down_list_value: "--titre1--\nv1\nupdated\n--titre2--\noption2\nv2\n") tdc_to_update.update(drop_down_options: ["--titre1--", "v1", "updated", "--titre2--", "option2", "v2"])
end end
it { expect { subject }.not_to change { dossier.champs_public.first.value } } it { expect { subject }.not_to change { dossier.champs_public.first.value } }

View file

@ -22,7 +22,7 @@ describe Logic::Eq do
it do it do
multiple_drop_down = create(:type_de_champ_multiple_drop_down_list) 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 = { expected = {
operator_name: "Logic::Eq", operator_name: "Logic::Eq",

View file

@ -22,7 +22,7 @@ describe Logic::NotEq do
it do it do
multiple_drop_down = create(:type_de_champ_multiple_drop_down_list) 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 = { expected = {
operator_name: "Logic::NotEq", operator_name: "Logic::NotEq",

View file

@ -48,7 +48,7 @@ describe Logic do
context 'when dropdown empty operator true' do context 'when dropdown empty operator true' do
let(:drop_down) { create(:type_de_champ_drop_down_list) } let(:drop_down) { create(:type_de_champ_drop_down_list) }
let(:type_de_champs) { [drop_down] } 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)) } 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))) } 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 context 'when multiple dropdown empty operator true' do
let(:multiple_drop_down) { create(:type_de_champ_multiple_drop_down_list) } let(:multiple_drop_down) { create(:type_de_champ_multiple_drop_down_list) }
let(:type_de_champs) { [multiple_drop_down] } 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)) } 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))) } 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 context 'with a dropdown' do
let(:drop_down) { create(:type_de_champ_drop_down_list) } 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 it do
expect(Logic.compatible_type?(champ_value(drop_down.stable_id), constant('a'), [drop_down])).to be true expect(Logic.compatible_type?(champ_value(drop_down.stable_id), constant('a'), [drop_down])).to be true

View file

@ -397,7 +397,7 @@ describe Procedure do
expect(procedure.errors.messages_for(:draft_types_de_champ_public)).to include(invalid_drop_down_error_message) expect(procedure.errors.messages_for(:draft_types_de_champ_public)).to include(invalid_drop_down_error_message)
drop_down = procedure.draft_revision.types_de_champ_public.find(&:drop_down_list?) drop_down = procedure.draft_revision.types_de_champ_public.find(&:drop_down_list?)
drop_down.update!(drop_down_list_value: "--title--\r\nsome value") drop_down.update!(drop_down_options: ["--title--", "some value"])
procedure.reload.validate(:publication) procedure.reload.validate(:publication)
expect(procedure.errors.messages_for(:draft_types_de_champ_public)).not_to include(invalid_drop_down_error_message) expect(procedure.errors.messages_for(:draft_types_de_champ_public)).not_to include(invalid_drop_down_error_message)
end end

View file

@ -149,7 +149,7 @@ describe TypeDeChamp do
let(:type_de_champ) { create(:type_de_champ_linked_drop_down_list) } let(:type_de_champ) { create(:type_de_champ_linked_drop_down_list) }
it 'should validate without label' do it 'should validate without label' do
type_de_champ.drop_down_list_value = 'toto' type_de_champ.drop_down_options = ['toto']
expect(type_de_champ.validate).to be_falsey expect(type_de_champ.validate).to be_falsey
messages = type_de_champ.errors.full_messages messages = type_de_champ.errors.full_messages
expect(messages.size).to eq(1) expect(messages.size).to eq(1)
@ -196,13 +196,13 @@ describe TypeDeChamp do
let(:type_de_champ) { create(:type_de_champ_drop_down_list) } let(:type_de_champ) { create(:type_de_champ_drop_down_list) }
it "splits input" do it "splits input" do
type_de_champ.drop_down_list_value = nil type_de_champ.drop_down_options_from_text = nil
expect(type_de_champ.drop_down_options).to eq([]) expect(type_de_champ.drop_down_options).to eq([])
type_de_champ.drop_down_list_value = "\n\r" type_de_champ.drop_down_options_from_text = "\n\r"
expect(type_de_champ.drop_down_options).to eq([]) expect(type_de_champ.drop_down_options).to eq([])
type_de_champ.drop_down_list_value = " 1 / 2 \r\n 3" type_de_champ.drop_down_options_from_text = " 1 / 2 \r\n 3"
expect(type_de_champ.drop_down_options).to eq(['1 / 2', '3']) expect(type_de_champ.drop_down_options).to eq(['1 / 2', '3'])
end end
end end

View file

@ -1,7 +1,7 @@
# frozen_string_literal: true # frozen_string_literal: true
describe TypesDeChamp::LinkedDropDownListTypeDeChamp do describe TypesDeChamp::LinkedDropDownListTypeDeChamp do
let(:type_de_champ) { build(:type_de_champ_linked_drop_down_list, drop_down_list_value: menu_options) } let(:type_de_champ) { build(:type_de_champ_linked_drop_down_list, drop_down_options: menu_options) }
subject { type_de_champ.dynamic_type } subject { type_de_champ.dynamic_type }
@ -9,26 +9,22 @@ describe TypesDeChamp::LinkedDropDownListTypeDeChamp do
context 'It must start with one primary option' do context 'It must start with one primary option' do
context 'valid menu' do context 'valid menu' do
let(:menu_options) do let(:menu_options) do
<<~END_OPTIONS [
--Primary 1-- "--Primary 1--",
secondary 1.1 "secondary 1.1",
secondary 1.2 "secondary 1.2",
--Primary 2-- "--Primary 2--",
secondary 2.1 "secondary 2.1",
secondary 2.2 "secondary 2.2",
secondary 2.3 "secondary 2.3"
END_OPTIONS ]
end end
it { is_expected.to be_valid } it { is_expected.to be_valid }
end end
context 'degenerate but valid menu' do context 'degenerate but valid menu' do
let(:menu_options) do let(:menu_options) { ["--Primary 1--"] }
<<~END_OPTIONS
--Primary 1--
END_OPTIONS
end
it { is_expected.to be_valid } it { is_expected.to be_valid }
end end
@ -43,26 +39,21 @@ describe TypesDeChamp::LinkedDropDownListTypeDeChamp do
end end
context 'no primary option' do context 'no primary option' do
let(:menu_options) do let(:menu_options) { ["secondary 1.1", "secondary 1.2"] }
<<~END_OPTIONS
secondary 1.1
secondary 1.2
END_OPTIONS
end
it_should_behave_like 'missing primary option' it_should_behave_like 'missing primary option'
end end
context 'starting with secondary options' do context 'starting with secondary options' do
let(:menu_options) do let(:menu_options) do
<<~END_OPTIONS [
secondary 1.1 "secondary 1.1",
secondary 1.2 "secondary 1.2",
--Primary 2-- "--Primary 2--",
secondary 2.1 "secondary 2.1",
secondary 2.2 "secondary 2.2",
secondary 2.3 "secondary 2.3"
END_OPTIONS ]
end end
it_should_behave_like 'missing primary option' it_should_behave_like 'missing primary option'
@ -73,22 +64,22 @@ describe TypesDeChamp::LinkedDropDownListTypeDeChamp do
describe '#unpack_options' do describe '#unpack_options' do
context 'with no options' do context 'with no options' do
let(:menu_options) { '' } let(:menu_options) { [] }
it { expect(subject.secondary_options).to eq({}) } it { expect(subject.secondary_options).to eq({}) }
it { expect(subject.primary_options).to eq([]) } it { expect(subject.primary_options).to eq([]) }
end end
context 'with two primary options' do context 'with two primary options' do
let(:menu_options) do let(:menu_options) do
<<~END_OPTIONS [
--Primary 1-- "--Primary 1--",
secondary 1.1 "secondary 1.1",
secondary 1.2 "secondary 1.2",
--Primary 2-- "--Primary 2--",
secondary 2.1 "secondary 2.1",
secondary 2.2 "secondary 2.2",
secondary 2.3 "secondary 2.3"
END_OPTIONS ]
end end
context "mandatory tdc" do context "mandatory tdc" do
@ -106,7 +97,7 @@ describe TypesDeChamp::LinkedDropDownListTypeDeChamp do
end end
context "not mandatory" do context "not mandatory" do
let(:type_de_champ) { build(:type_de_champ_linked_drop_down_list, drop_down_list_value: menu_options, mandatory: false) } let(:type_de_champ) { build(:type_de_champ_linked_drop_down_list, drop_down_options: menu_options, mandatory: false) }
it do it do
expect(subject.secondary_options).to eq( expect(subject.secondary_options).to eq(

View file

@ -12,7 +12,7 @@ RSpec.describe TypesDeChamp::PrefillDropDownListTypeDeChamp do
it { it {
expect(possible_values).to match( 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 end
@ -20,7 +20,7 @@ RSpec.describe TypesDeChamp::PrefillDropDownListTypeDeChamp do
context "when the drop down list does not accept 'other'" do context "when the drop down list does not accept 'other'" do
let(:type_de_champ) { build(:type_de_champ_drop_down_list, procedure:) } 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
end end
@ -29,6 +29,6 @@ RSpec.describe TypesDeChamp::PrefillDropDownListTypeDeChamp do
let(:type_de_champ) { build(:type_de_champ_drop_down_list, procedure: procedure) } 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 } 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
end end

View file

@ -10,23 +10,23 @@ RSpec.describe TypesDeChamp::PrefillMultipleDropDownListTypeDeChamp do
end end
describe '#example_value' do describe '#example_value' do
let(:type_de_champ) { build(:type_de_champ_multiple_drop_down_list, drop_down_list_value: drop_down_list_value, procedure: procedure) } let(:type_de_champ) { build(:type_de_champ_multiple_drop_down_list, drop_down_options_from_text: drop_down_options_from_text, procedure: procedure) }
subject(:example_value) { described_class.new(type_de_champ, procedure.active_revision).example_value } subject(:example_value) { described_class.new(type_de_champ, procedure.active_revision).example_value }
context 'when the multiple drop down list has no option' do context 'when the multiple drop down list has no option' do
let(:drop_down_list_value) { "" } let(:drop_down_options_from_text) { "" }
it { expect(example_value).to eq(nil) } it { expect(example_value).to eq(nil) }
end end
context 'when the multiple drop down list only has one option' do context 'when the multiple drop down list only has one option' do
let(:drop_down_list_value) { "value" } let(:drop_down_options_from_text) { "value" }
it { expect(example_value).to eq("value") } it { expect(example_value).to eq("value") }
end end
context 'when the multiple drop down list has two options or more' do context 'when the multiple drop down list has two options or more' do
let(:drop_down_list_value) { "value1\r\nvalue2\r\nvalue3" } let(:drop_down_options_from_text) { "value1\r\nvalue2\r\nvalue3" }
it { expect(example_value).to eq(["value1", "value2"]) } it { expect(example_value).to eq(["value1", "value2"]) }
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(:datetime_value) { "2023-02-01T10:32" }
let(:multiple_drop_down_list_values) { 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_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.last
] ]
} }
let(:epci_value) { ['01', '200029999'] } 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(:datetime_value) { "2023-02-01T10:32" }
let(:multiple_drop_down_list_values) { 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_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.last
] ]
} }
let(:epci_value) { ['01', '200029999'] } 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(:types_de_champ_public) { [{ type: :drop_down_list, options:, mandatory: }] }
let(:champ) { dossier.champs_public.first } let(:champ) { dossier.champs_public.first }
let(:type_de_champ) { champ.type_de_champ } 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(:mandatory) { true }
let(:options) { nil } let(:options) { nil }
@ -71,7 +71,7 @@ describe 'shared/dossiers/edit', type: :view do
context 'when the list is long' do context 'when the list is long' do
let(:value) { 'alpha' } let(:value) { 'alpha' }
let(:options) { [:long] } let(:options) { ['1', '2', '3', '4', '5', '6'] }
before { champ.update(value:) } before { champ.update(value:) }
@ -86,7 +86,7 @@ describe 'shared/dossiers/edit', type: :view do
let(:champ) { dossier.champs.first } let(:champ) { dossier.champs.first }
let(:type_de_champ) { champ.type_de_champ } let(:type_de_champ) { champ.type_de_champ }
let(:options) { type_de_champ.drop_down_options } 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 context 'when the list is short' do
let(:options) { ['valid', 'invalid', 'not sure yet'] } let(:options) { ['valid', 'invalid', 'not sure yet'] }