Merge pull request #7669 from betagouv/fix_hidden_required_in_conditionnel

fix(conditionnel): corrige les champs obligatoires mais cachés
This commit is contained in:
LeSim 2022-08-09 14:43:12 +02:00 committed by GitHub
commit 3eb440b9da
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 91 additions and 49 deletions

View file

@ -34,7 +34,6 @@ class Champ < ApplicationRecord
delegate :libelle,
:type_champ,
:procedure,
:mandatory?,
:description,
:drop_down_list_options,
:drop_down_other?,
@ -92,8 +91,12 @@ class Champ < ApplicationRecord
@sections ||= dossier.sections_for(self)
end
def mandatory?
type_de_champ.mandatory? && visible?
end
def mandatory_blank_and_visible?
mandatory? && blank? && visible?
mandatory? && blank?
end
def blank?

View file

@ -39,7 +39,7 @@ class Champs::PieceJustificativeChamp < Champ
end
def mandatory_blank_and_visible?
mandatory? && !piece_justificative_file.attached? && visible?
mandatory? && !piece_justificative_file.attached?
end
def for_export

View file

@ -25,6 +25,6 @@ class Champs::SiretChamp < Champ
end
def mandatory_blank_and_visible?
mandatory? && Siret.new(siret: value).invalid? && visible?
mandatory? && Siret.new(siret: value).invalid?
end
end

View file

@ -33,7 +33,7 @@ class Champs::TitreIdentiteChamp < Champ
end
def mandatory_blank_and_visible?
mandatory? && !piece_justificative_file.attached? && visible?
mandatory? && !piece_justificative_file.attached?
end
def for_export

View file

@ -1,5 +1,5 @@
#{champ.libelle}
- if champ.mandatory?
- if champ.type_de_champ.mandatory?
%span.mandatory *
- if champ.updated_at.present? && seen_at.present?

View file

@ -7,7 +7,7 @@
.secondary{ class: champ.has_secondary_options_for_primary? ? '' : 'hidden' }
= form.label :secondary_value, for: "#{champ.input_id}-secondary" do
= champ.drop_down_secondary_libelle.presence || "Valeur secondaire dépendant de la première"
- if champ.mandatory?
- if champ.type_de_champ.mandatory?
%span.mandatory *
- if champ.drop_down_secondary_description.present?
.notice{ id: "#{champ.describedby_id}-secondary" }= string_to_html(champ.drop_down_secondary_description)

View file

@ -269,6 +269,44 @@ describe 'The user' do
context 'with condition' do
include Logic
context 'with a required conditionnal champ' do
let(:procedure) do
procedure = create(:procedure, :published, :for_individual,
types_de_champ_public: [
{ type: :integer_number, libelle: 'age' },
{ type: :text, libelle: 'nom', mandatory: true }
])
age, nom = procedure.draft_revision.types_de_champ.all
nom.update(condition: greater_than_eq(champ_value(age.stable_id), constant(18)))
procedure
end
scenario 'submit a dossier with an hidden mandatory champ ', js: true do
log_in(user, procedure)
fill_individual
click_on 'Déposer le dossier'
expect(page).to have_current_path(merci_dossier_path(user_dossier))
end
scenario 'cannot submit a reveal dossier with a revealed mandatory champ ', js: true do
log_in(user, procedure)
fill_individual
fill_in('age', with: '18')
expect(page).to have_css('label', text: 'nom *', visible: :visible)
click_on 'Déposer le dossier'
expect(page).to have_current_path(brouillon_dossier_path(user_dossier))
end
end
context 'with a visibilite in cascade' do
let(:procedure) do
procedure = create(:procedure, :for_individual).tap do |p|
p.draft_revision.add_type_de_champ(type_champ: :integer_number, libelle: 'age')
@ -330,6 +368,7 @@ describe 'The user' do
expect(page).to have_css('label', text: 'tonnage', visible: true)
end
end
end
context 'draft autosave' do
scenario 'autosave a draft', js: true do