Merge pull request #7922 from betagouv/fix_mandatory_options
fix(drop_down_list): corrige l'apparition de l'option 'non renseigné' dans une liste de choix obligatoire
This commit is contained in:
commit
1d82d5f7bb
35 changed files with 57 additions and 54 deletions
|
@ -1,6 +1,6 @@
|
||||||
= @form.hidden_field :value
|
= @form.hidden_field :value
|
||||||
= @form.hidden_field :external_id
|
= @form.hidden_field :external_id
|
||||||
= react_component("ComboAdresseSearch",
|
= react_component("ComboAdresseSearch",
|
||||||
required: @champ.mandatory?,
|
required: @champ.required?,
|
||||||
id: @champ.input_id,
|
id: @champ.input_id,
|
||||||
describedby: @champ.describedby_id)
|
describedby: @champ.describedby_id)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
= @form.hidden_field :value
|
= @form.hidden_field :value
|
||||||
= @form.hidden_field :external_id
|
= @form.hidden_field :external_id
|
||||||
= react_component("ComboAnnuaireEducationSearch",
|
= react_component("ComboAnnuaireEducationSearch",
|
||||||
required: @champ.mandatory?,
|
required: @champ.required?,
|
||||||
id: @champ.input_id,
|
id: @champ.input_id,
|
||||||
describedby: @champ.describedby_id)
|
describedby: @champ.describedby_id)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
= @form.check_box :value,
|
= @form.check_box :value,
|
||||||
{ required: @champ.mandatory?, id: @champ.input_id, aria: { describedby: @champ.describedby_id } },
|
{ required: @champ.required?, id: @champ.input_id, aria: { describedby: @champ.describedby_id } },
|
||||||
'on',
|
'on',
|
||||||
'off'
|
'off'
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
= @form.label :numero_allocataire, t('.numero_allocataire_label')
|
= @form.label :numero_allocataire, t('.numero_allocataire_label')
|
||||||
%p.notice= t('.numero_allocataire_notice')
|
%p.notice= t('.numero_allocataire_notice')
|
||||||
= @form.text_field :numero_allocataire,
|
= @form.text_field :numero_allocataire,
|
||||||
required: @champ.mandatory?,
|
required: @champ.required?,
|
||||||
aria: { describedby: @champ.describedby_id },
|
aria: { describedby: @champ.describedby_id },
|
||||||
class: "width-33-desktop"
|
class: "width-33-desktop"
|
||||||
|
|
||||||
|
@ -11,6 +11,6 @@
|
||||||
= @form.label :code_postal, t('.code_postal_label')
|
= @form.label :code_postal, t('.code_postal_label')
|
||||||
%p.notice= t('.code_postal_notice')
|
%p.notice= t('.code_postal_notice')
|
||||||
= @form.text_field :code_postal,
|
= @form.text_field :code_postal,
|
||||||
required: @champ.mandatory?,
|
required: @champ.required?,
|
||||||
aria: { describedby: @champ.describedby_id },
|
aria: { describedby: @champ.describedby_id },
|
||||||
class: "width-33-desktop"
|
class: "width-33-desktop"
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
= @form.hidden_field :departement
|
= @form.hidden_field :departement
|
||||||
= @form.hidden_field :code_departement
|
= @form.hidden_field :code_departement
|
||||||
= react_component("ComboCommunesSearch",
|
= react_component("ComboCommunesSearch",
|
||||||
required: @champ.mandatory?,
|
required: @champ.required?,
|
||||||
id: @champ.input_id,
|
id: @champ.input_id,
|
||||||
classNameDepartement: "width-33-desktop width-100-mobile",
|
classNameDepartement: "width-33-desktop width-100-mobile",
|
||||||
className: "width-66-desktop width-100-mobile",
|
className: "width-66-desktop width-100-mobile",
|
||||||
|
|
|
@ -2,6 +2,6 @@
|
||||||
id: @champ.input_id,
|
id: @champ.input_id,
|
||||||
aria: { describedby: @champ.describedby_id },
|
aria: { describedby: @champ.describedby_id },
|
||||||
value: @champ.value,
|
value: @champ.value,
|
||||||
required: @champ.mandatory?,
|
required: @champ.required?,
|
||||||
placeholder: 'aaaa-mm-jj',
|
placeholder: 'aaaa-mm-jj',
|
||||||
class: "width-33-desktop"
|
class: "width-33-desktop"
|
||||||
|
|
|
@ -3,4 +3,4 @@
|
||||||
aria: { describedby: @champ.describedby_id },
|
aria: { describedby: @champ.describedby_id },
|
||||||
step: :any,
|
step: :any,
|
||||||
placeholder: "3.14",
|
placeholder: "3.14",
|
||||||
required: @champ.mandatory?
|
required: @champ.required?
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
= @form.hidden_field :value
|
= @form.hidden_field :value
|
||||||
= @form.hidden_field :external_id
|
= @form.hidden_field :external_id
|
||||||
= react_component("ComboDepartementsSearch",
|
= react_component("ComboDepartementsSearch",
|
||||||
required: @champ.mandatory?,
|
required: @champ.required?,
|
||||||
id: @champ.input_id,
|
id: @champ.input_id,
|
||||||
className: "width-33-desktop width-100-mobile",
|
className: "width-33-desktop width-100-mobile",
|
||||||
describedby: @champ.describedby_id)
|
describedby: @champ.describedby_id)
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
= @form.label :numero_fiscal, t('.numero_fiscal_label')
|
= @form.label :numero_fiscal, t('.numero_fiscal_label')
|
||||||
%p.notice= t('.numero_fiscal_notice')
|
%p.notice= t('.numero_fiscal_notice')
|
||||||
= @form.text_field :numero_fiscal,
|
= @form.text_field :numero_fiscal,
|
||||||
required: @champ.mandatory?,
|
required: @champ.required?,
|
||||||
aria: { describedby: @champ.describedby_id },
|
aria: { describedby: @champ.describedby_id },
|
||||||
class: "width-33-desktop"
|
class: "width-33-desktop"
|
||||||
|
|
||||||
|
@ -11,6 +11,6 @@
|
||||||
= @form.label :reference_avis, t('.reference_avis_label')
|
= @form.label :reference_avis, t('.reference_avis_label')
|
||||||
%p.notice= t('.reference_avis_notice')
|
%p.notice= t('.reference_avis_notice')
|
||||||
= @form.text_field :reference_avis,
|
= @form.text_field :reference_avis,
|
||||||
required: @champ.mandatory?,
|
required: @champ.required?,
|
||||||
aria: { describedby: @champ.describedby_id },
|
aria: { describedby: @champ.describedby_id },
|
||||||
class: "width-33-desktop"
|
class: "width-33-desktop"
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
aria: { describedby: @champ.describedby_id },
|
aria: { describedby: @champ.describedby_id },
|
||||||
placeholder: "Numéro de dossier",
|
placeholder: "Numéro de dossier",
|
||||||
autocomplete: 'off',
|
autocomplete: 'off',
|
||||||
required: @champ.mandatory?,
|
required: @champ.required?,
|
||||||
data: { controller: 'turbo-input', turbo_input_url_value: champs_dossier_link_path(@champ.id) },
|
data: { controller: 'turbo-input', turbo_input_url_value: champs_dossier_link_path(@champ.id) },
|
||||||
class: "width-33-desktop"
|
class: "width-33-desktop"
|
||||||
|
|
||||||
|
|
|
@ -2,4 +2,4 @@
|
||||||
id: @champ.input_id,
|
id: @champ.input_id,
|
||||||
aria: { describedby: @champ.describedby_id },
|
aria: { describedby: @champ.describedby_id },
|
||||||
placeholder: t(".placeholder"),
|
placeholder: t(".placeholder"),
|
||||||
required: @champ.mandatory?
|
required: @champ.required?
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
= @form.check_box :value,
|
= @form.check_box :value,
|
||||||
{ required: @champ.mandatory?, id: @champ.input_id, aria: { describedby: @champ.describedby_id } },
|
{ required: @champ.required?, id: @champ.input_id, aria: { describedby: @champ.describedby_id } },
|
||||||
'on',
|
'on',
|
||||||
'off'
|
'off'
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
= @form.text_field :value,
|
= @form.text_field :value,
|
||||||
id: @champ.input_id,
|
id: @champ.input_id,
|
||||||
placeholder: t(".placeholder"),
|
placeholder: t(".placeholder"),
|
||||||
required: @champ.mandatory?,
|
required: @champ.required?,
|
||||||
aria: { describedby: @champ.describedby_id },
|
aria: { describedby: @champ.describedby_id },
|
||||||
data: { controller: 'iban-input'},
|
data: { controller: 'iban-input'},
|
||||||
class: "width-66-desktop",
|
class: "width-66-desktop",
|
||||||
|
|
|
@ -2,4 +2,4 @@
|
||||||
id: @champ.input_id,
|
id: @champ.input_id,
|
||||||
aria: { describedby: @champ.describedby_id },
|
aria: { describedby: @champ.describedby_id },
|
||||||
placeholder: 5,
|
placeholder: 5,
|
||||||
required: @champ.mandatory?
|
required: @champ.required?
|
||||||
|
|
|
@ -2,17 +2,15 @@
|
||||||
= @form.select :primary_value,
|
= @form.select :primary_value,
|
||||||
@champ.primary_options,
|
@champ.primary_options,
|
||||||
{},
|
{},
|
||||||
{ data: { secondary_options: @champ.secondary_options }, required: @champ.mandatory?, id: @champ.input_id, aria: { describedby: @champ.describedby_id } }
|
{ data: { secondary_options: @champ.secondary_options }, required: @champ.required?, id: @champ.input_id, aria: { describedby: @champ.describedby_id } }
|
||||||
|
|
||||||
.secondary{ class: @champ.has_secondary_options_for_primary? ? '' : 'hidden' }
|
.secondary{ class: @champ.has_secondary_options_for_primary? ? '' : 'hidden' }
|
||||||
= @form.label :secondary_value, for: "#{@champ.input_id}-secondary" do
|
= @form.label :secondary_value, for: "#{@champ.input_id}-secondary" do
|
||||||
- sanitize((@champ.drop_down_secondary_libelle.presence || "Valeur secondaire dépendant de la première") + (@champ.type_de_champ.mandatory? ? tag.span(' *', class: 'mandatory') : ''))
|
- sanitize((@champ.drop_down_secondary_libelle.presence || "Valeur secondaire dépendant de la première") + (@champ.type_de_champ.mandatory? ? tag.span(' *', class: 'mandatory') : ''))
|
||||||
-# - if @champ.type_de_champ.mandatory?
|
|
||||||
-# %span.mandatory *
|
|
||||||
- if @champ.drop_down_secondary_description.present?
|
- if @champ.drop_down_secondary_description.present?
|
||||||
.notice{ id: "#{@champ.describedby_id}-secondary" }= string_to_html(@champ.drop_down_secondary_description)
|
.notice{ id: "#{@champ.describedby_id}-secondary" }= string_to_html(@champ.drop_down_secondary_description)
|
||||||
= @form.select :secondary_value,
|
= @form.select :secondary_value,
|
||||||
@champ.secondary_options[@champ.primary_value],
|
@champ.secondary_options[@champ.primary_value],
|
||||||
{},
|
{},
|
||||||
{ data: { secondary: true }, disabled: !@champ.has_secondary_options_for_primary?, required: @champ.mandatory?, id: "#{@champ.input_id}-secondary", aria: { describedby: "#{@champ.describedby_id}-secondary" } }
|
{ data: { secondary: true }, disabled: !@champ.has_secondary_options_for_primary?, required: @champ.required?, id: "#{@champ.input_id}-secondary", aria: { describedby: "#{@champ.describedby_id}-secondary" } }
|
||||||
= @form.hidden_field :secondary_value, value: '', disabled: @champ.has_secondary_options_for_primary?
|
= @form.hidden_field :secondary_value, value: '', disabled: @champ.has_secondary_options_for_primary?
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
= @form.label :ine, t('.ine_label')
|
= @form.label :ine, t('.ine_label')
|
||||||
%p.notice= t('.ine_notice')
|
%p.notice= t('.ine_notice')
|
||||||
= @form.text_field :ine,
|
= @form.text_field :ine,
|
||||||
required: @champ.mandatory?,
|
required: @champ.required?,
|
||||||
aria: { describedby: @champ.describedby_id },
|
aria: { describedby: @champ.describedby_id },
|
||||||
class: "width-33-desktop"
|
class: "width-33-desktop"
|
||||||
|
|
||||||
|
|
|
@ -2,4 +2,4 @@
|
||||||
id: @champ.input_id,
|
id: @champ.input_id,
|
||||||
aria: { describedby: @champ.describedby_id },
|
aria: { describedby: @champ.describedby_id },
|
||||||
placeholder: @champ.libelle,
|
placeholder: @champ.libelle,
|
||||||
required: @champ.mandatory?
|
required: @champ.required?
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
= @form.hidden_field :value
|
= @form.hidden_field :value
|
||||||
= @form.hidden_field :external_id
|
= @form.hidden_field :external_id
|
||||||
= react_component("ComboPaysSearch",
|
= react_component("ComboPaysSearch",
|
||||||
required: @champ.mandatory?,
|
required: @champ.required?,
|
||||||
id: @champ.input_id,
|
id: @champ.input_id,
|
||||||
className: "width-33-desktop width-100-mobile",
|
className: "width-33-desktop width-100-mobile",
|
||||||
describedby: @champ.describedby_id)
|
describedby: @champ.describedby_id)
|
||||||
|
|
|
@ -5,5 +5,5 @@
|
||||||
id: @champ.input_id,
|
id: @champ.input_id,
|
||||||
aria: { describedby: @champ.describedby_id },
|
aria: { describedby: @champ.describedby_id },
|
||||||
placeholder: t(".placeholder"),
|
placeholder: t(".placeholder"),
|
||||||
required: @champ.mandatory?,
|
required: @champ.required?,
|
||||||
pattern: "[^a-z^A-Z]+"
|
pattern: "[^a-z^A-Z]+"
|
||||||
|
|
|
@ -3,6 +3,6 @@
|
||||||
= @form.label :identifiant, t('.identifiant_label')
|
= @form.label :identifiant, t('.identifiant_label')
|
||||||
%p.notice= t('.identifiant_notice')
|
%p.notice= t('.identifiant_notice')
|
||||||
= @form.text_field :identifiant,
|
= @form.text_field :identifiant,
|
||||||
required: @champ.mandatory?,
|
required: @champ.required?,
|
||||||
aria: { describedby: @champ.describedby_id },
|
aria: { describedby: @champ.describedby_id },
|
||||||
class: "width-33-desktop"
|
class: "width-33-desktop"
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
= @form.hidden_field :value
|
= @form.hidden_field :value
|
||||||
= @form.hidden_field :external_id
|
= @form.hidden_field :external_id
|
||||||
= react_component("ComboRegionsSearch",
|
= react_component("ComboRegionsSearch",
|
||||||
required: @champ.mandatory?,
|
required: @champ.required?,
|
||||||
id: @champ.input_id,
|
id: @champ.input_id,
|
||||||
className: "width-33-desktop width-100-mobile",
|
className: "width-33-desktop width-100-mobile",
|
||||||
describedby: @champ.describedby_id)
|
describedby: @champ.describedby_id)
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
aria: { describedby: @champ.describedby_id },
|
aria: { describedby: @champ.describedby_id },
|
||||||
placeholder: t(".placeholder"),
|
placeholder: t(".placeholder"),
|
||||||
data: { controller: 'turbo-input', turbo_input_url_value: champs_rna_path(@champ.id) },
|
data: { controller: 'turbo-input', turbo_input_url_value: champs_rna_path(@champ.id) },
|
||||||
required: @champ.mandatory?,
|
required: @champ.required?,
|
||||||
pattern: "W[0-9]{9}",
|
pattern: "W[0-9]{9}",
|
||||||
title: t(".title"),
|
title: t(".title"),
|
||||||
class: "width-33-desktop",
|
class: "width-33-desktop",
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
aria: { describedby: @champ.describedby_id },
|
aria: { describedby: @champ.describedby_id },
|
||||||
placeholder: t(".placeholder"),
|
placeholder: t(".placeholder"),
|
||||||
data: { controller: 'turbo-input', turbo_input_url_value: champs_siret_path(@champ.id) },
|
data: { controller: 'turbo-input', turbo_input_url_value: champs_siret_path(@champ.id) },
|
||||||
required: @champ.mandatory?,
|
required: @champ.required?,
|
||||||
pattern: "[0-9]{14}",
|
pattern: "[0-9]{14}",
|
||||||
title: t(".title"),
|
title: t(".title"),
|
||||||
class: "width-33-desktop",
|
class: "width-33-desktop",
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
= @form.text_field :value,
|
= @form.text_field :value,
|
||||||
id: @champ.input_id,
|
id: @champ.input_id,
|
||||||
required: @champ.mandatory?,
|
required: @champ.required?,
|
||||||
aria: { describedby: @champ.describedby_id }
|
aria: { describedby: @champ.describedby_id }
|
||||||
|
|
|
@ -2,5 +2,5 @@
|
||||||
id: @champ.input_id,
|
id: @champ.input_id,
|
||||||
aria: { describedby: @champ.describedby_id },
|
aria: { describedby: @champ.describedby_id },
|
||||||
rows: 6,
|
rows: 6,
|
||||||
required: @champ.mandatory?,
|
required: @champ.required?,
|
||||||
value: html_to_string(@champ.value)
|
value: html_to_string(@champ.value)
|
||||||
|
|
|
@ -462,7 +462,7 @@ module Users
|
||||||
end
|
end
|
||||||
|
|
||||||
if dossier.en_construction?
|
if dossier.en_construction?
|
||||||
errors += @dossier.check_mandatory_champs
|
errors += @dossier.check_mandatory_and_visible_champs
|
||||||
end
|
end
|
||||||
|
|
||||||
errors
|
errors
|
||||||
|
@ -473,7 +473,7 @@ module Users
|
||||||
|
|
||||||
@dossier.valid?(**submit_validation_options)
|
@dossier.valid?(**submit_validation_options)
|
||||||
errors += @dossier.errors.full_messages
|
errors += @dossier.errors.full_messages
|
||||||
errors += @dossier.check_mandatory_champs
|
errors += @dossier.check_mandatory_and_visible_champs
|
||||||
|
|
||||||
if should_fill_groupe_instructeur?
|
if should_fill_groupe_instructeur?
|
||||||
@dossier.assign_to_groupe_instructeur(defaut_groupe_instructeur)
|
@dossier.assign_to_groupe_instructeur(defaut_groupe_instructeur)
|
||||||
|
|
|
@ -60,6 +60,7 @@ class Champ < ApplicationRecord
|
||||||
:rna?,
|
:rna?,
|
||||||
:siret?,
|
:siret?,
|
||||||
:stable_id,
|
:stable_id,
|
||||||
|
:mandatory?,
|
||||||
to: :type_de_champ
|
to: :type_de_champ
|
||||||
|
|
||||||
scope :updated_since?, -> (date) { where('champs.updated_at > ?', date) }
|
scope :updated_since?, -> (date) { where('champs.updated_at > ?', date) }
|
||||||
|
@ -93,11 +94,14 @@ class Champ < ApplicationRecord
|
||||||
@sections ||= dossier.sections_for(self)
|
@sections ||= dossier.sections_for(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
def mandatory?
|
# used for the `required` html attribute
|
||||||
|
# check visibility to avoid hidden required input
|
||||||
|
# which prevent the form from being sent.
|
||||||
|
def required?
|
||||||
type_de_champ.mandatory? && visible?
|
type_de_champ.mandatory? && visible?
|
||||||
end
|
end
|
||||||
|
|
||||||
def mandatory_blank_and_visible?
|
def mandatory_blank?
|
||||||
mandatory? && blank?
|
mandatory? && blank?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ class Champs::CheckboxChamp < Champs::YesNoChamp
|
||||||
true? ? 'on' : 'off'
|
true? ? 'on' : 'off'
|
||||||
end
|
end
|
||||||
|
|
||||||
def mandatory_blank_and_visible?
|
def mandatory_blank?
|
||||||
mandatory? && (blank? || !true?)
|
mandatory? && (blank? || !true?)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -38,7 +38,7 @@ class Champs::PieceJustificativeChamp < Champ
|
||||||
# We don’t know how to search inside documents yet
|
# We don’t know how to search inside documents yet
|
||||||
end
|
end
|
||||||
|
|
||||||
def mandatory_blank_and_visible?
|
def mandatory_blank?
|
||||||
mandatory? && !piece_justificative_file.attached?
|
mandatory? && !piece_justificative_file.attached?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ class Champs::SiretChamp < Champ
|
||||||
etablissement.present? ? etablissement.search_terms : [value]
|
etablissement.present? ? etablissement.search_terms : [value]
|
||||||
end
|
end
|
||||||
|
|
||||||
def mandatory_blank_and_visible?
|
def mandatory_blank?
|
||||||
mandatory? && Siret.new(siret: value).invalid?
|
mandatory? && Siret.new(siret: value).invalid?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -32,7 +32,7 @@ class Champs::TitreIdentiteChamp < Champ
|
||||||
# We don’t know how to search inside documents yet
|
# We don’t know how to search inside documents yet
|
||||||
end
|
end
|
||||||
|
|
||||||
def mandatory_blank_and_visible?
|
def mandatory_blank?
|
||||||
mandatory? && !piece_justificative_file.attached?
|
mandatory? && !piece_justificative_file.attached?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -981,9 +981,10 @@ class Dossier < ApplicationRecord
|
||||||
champs.filter(&:titre_identite?).map(&:piece_justificative_file).each(&:purge_later)
|
champs.filter(&:titre_identite?).map(&:piece_justificative_file).each(&:purge_later)
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_mandatory_champs
|
def check_mandatory_and_visible_champs
|
||||||
(champs + champs.filter(&:block?).filter(&:visible?).flat_map(&:champs))
|
(champs + champs.filter(&:block?).filter(&:visible?).flat_map(&:champs))
|
||||||
.filter(&:mandatory_blank_and_visible?)
|
.filter(&:visible?)
|
||||||
|
.filter(&:mandatory_blank?)
|
||||||
.map do |champ|
|
.map do |champ|
|
||||||
"Le champ #{champ.libelle.truncate(200)} doit être rempli."
|
"Le champ #{champ.libelle.truncate(200)} doit être rempli."
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,26 +1,26 @@
|
||||||
shared_examples 'champ_spec' do
|
shared_examples 'champ_spec' do
|
||||||
describe 'mandatory_blank_and_visible?' do
|
describe 'mandatory_blank?' do
|
||||||
let(:type_de_champ) { build(:type_de_champ, mandatory: mandatory) }
|
let(:type_de_champ) { build(:type_de_champ, mandatory: mandatory) }
|
||||||
let(:champ) { build(:champ, type_de_champ: type_de_champ, value: value) }
|
let(:champ) { build(:champ, type_de_champ: type_de_champ, value: value) }
|
||||||
let(:value) { '' }
|
let(:value) { '' }
|
||||||
let(:mandatory) { true }
|
let(:mandatory) { true }
|
||||||
|
|
||||||
context 'when mandatory and blank' do
|
context 'when mandatory and blank' do
|
||||||
it { expect(champ.mandatory_blank_and_visible?).to be(true) }
|
it { expect(champ.mandatory_blank?).to be(true) }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when carte mandatory and blank' do
|
context 'when carte mandatory and blank' do
|
||||||
let(:type_de_champ) { build(:type_de_champ_carte, mandatory: mandatory) }
|
let(:type_de_champ) { build(:type_de_champ_carte, mandatory: mandatory) }
|
||||||
let(:champ) { build(:champ_carte, type_de_champ: type_de_champ, value: value) }
|
let(:champ) { build(:champ_carte, type_de_champ: type_de_champ, value: value) }
|
||||||
let(:value) { nil }
|
let(:value) { nil }
|
||||||
it { expect(champ.mandatory_blank_and_visible?).to be(true) }
|
it { expect(champ.mandatory_blank?).to be(true) }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when multiple_drop_down_list mandatory and blank' do
|
context 'when multiple_drop_down_list mandatory and blank' do
|
||||||
let(:type_de_champ) { build(:type_de_champ_multiple_drop_down_list, mandatory: mandatory) }
|
let(:type_de_champ) { build(:type_de_champ_multiple_drop_down_list, mandatory: mandatory) }
|
||||||
let(:champ) { build(:champ_multiple_drop_down_list, type_de_champ: type_de_champ, value: value) }
|
let(:champ) { build(:champ_multiple_drop_down_list, type_de_champ: type_de_champ, value: value) }
|
||||||
let(:value) { '[]' }
|
let(:value) { '[]' }
|
||||||
it { expect(champ.mandatory_blank_and_visible?).to be(true) }
|
it { expect(champ.mandatory_blank?).to be(true) }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when repetition blank' do
|
context 'when repetition blank' do
|
||||||
|
@ -39,18 +39,18 @@ shared_examples 'champ_spec' do
|
||||||
|
|
||||||
context 'when not blank' do
|
context 'when not blank' do
|
||||||
let(:value) { 'yop' }
|
let(:value) { 'yop' }
|
||||||
it { expect(champ.mandatory_blank_and_visible?).to be(false) }
|
it { expect(champ.mandatory_blank?).to be(false) }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when not mandatory' do
|
context 'when not mandatory' do
|
||||||
let(:mandatory) { false }
|
let(:mandatory) { false }
|
||||||
it { expect(champ.mandatory_blank_and_visible?).to be(false) }
|
it { expect(champ.mandatory_blank?).to be(false) }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when not mandatory or blank' do
|
context 'when not mandatory or blank' do
|
||||||
let(:value) { 'u' }
|
let(:value) { 'u' }
|
||||||
let(:mandatory) { false }
|
let(:mandatory) { false }
|
||||||
it { expect(champ.mandatory_blank_and_visible?).to be(false) }
|
it { expect(champ.mandatory_blank?).to be(false) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -78,7 +78,7 @@ describe Champs::LinkedDropDownListChamp do
|
||||||
let(:type_de_champ) { build(:type_de_champ_linked_drop_down_list, drop_down_list_value: value) }
|
let(:type_de_champ) { build(:type_de_champ_linked_drop_down_list, drop_down_list_value: value) }
|
||||||
|
|
||||||
it 'blank is fine' do
|
it 'blank is fine' do
|
||||||
is_expected.not_to be_mandatory_blank_and_visible
|
is_expected.not_to be_mandatory_blank
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -86,27 +86,27 @@ describe Champs::LinkedDropDownListChamp 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_list_value: value) }
|
||||||
|
|
||||||
context 'when there is no value' do
|
context 'when there is no value' do
|
||||||
it { is_expected.to be_mandatory_blank_and_visible }
|
it { is_expected.to be_mandatory_blank }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when there is a primary value' do
|
context 'when there is a primary value' do
|
||||||
before { subject.primary_value = 'Primary' }
|
before { subject.primary_value = 'Primary' }
|
||||||
|
|
||||||
context 'when there is no secondary value' do
|
context 'when there is no secondary value' do
|
||||||
it { is_expected.to be_mandatory_blank_and_visible }
|
it { is_expected.to be_mandatory_blank }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when there is a secondary value' do
|
context 'when there is a secondary value' do
|
||||||
before { subject.secondary_value = 'Secondary' }
|
before { subject.secondary_value = 'Secondary' }
|
||||||
|
|
||||||
it { is_expected.not_to be_mandatory_blank_and_visible }
|
it { is_expected.not_to be_mandatory_blank }
|
||||||
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(:value) { "--A--\nAbbott\nAbelard\n--B--\n--C--\nCynthia" }
|
||||||
before { subject.primary_value = 'B' }
|
before { subject.primary_value = 'B' }
|
||||||
|
|
||||||
it { is_expected.not_to be_mandatory_blank_and_visible }
|
it { is_expected.not_to be_mandatory_blank }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1172,14 +1172,14 @@ describe Dossier do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#check_mandatory_champs" do
|
describe "#check_mandatory_and_visible_champs" do
|
||||||
include Logic
|
include Logic
|
||||||
|
|
||||||
let(:procedure) { create(:procedure, types_de_champ_public: types_de_champ) }
|
let(:procedure) { create(:procedure, types_de_champ_public: types_de_champ) }
|
||||||
let(:dossier) { create(:dossier, procedure: procedure) }
|
let(:dossier) { create(:dossier, procedure: procedure) }
|
||||||
let(:types_de_champ) { [type_de_champ] }
|
let(:types_de_champ) { [type_de_champ] }
|
||||||
let(:type_de_champ) { {} }
|
let(:type_de_champ) { {} }
|
||||||
let(:errors) { dossier.check_mandatory_champs }
|
let(:errors) { dossier.check_mandatory_and_visible_champs }
|
||||||
|
|
||||||
it 'no mandatory champs' do
|
it 'no mandatory champs' do
|
||||||
expect(errors).to be_empty
|
expect(errors).to be_empty
|
||||||
|
|
Loading…
Reference in a new issue