pr feedbacks - add validation for yes/no answer - improve locales use

This commit is contained in:
Lisa Durand 2023-03-14 15:05:19 +01:00
parent 3b3d5182bf
commit ee2f795dec
8 changed files with 23 additions and 12 deletions

View file

@ -5,8 +5,13 @@ module CreateAvisConcern
def create_avis_from_params(dossier, instructeur_or_expert, confidentiel = false)
if create_avis_params[:emails].empty?
flash.alert = t('activerecord.errors.models.email.empty')
return Avis.new(create_avis_params)
avis = Avis.new(create_avis_params)
errors = avis.errors
errors.add(:emails, :blank)
flash.alert = errors.full_message(:emails, errors[:emails].first)
return avis
end
confidentiel ||= create_avis_params[:confidentiel]

View file

@ -43,6 +43,7 @@ class Avis < ApplicationRecord
validates :email, format: { with: Devise.email_regexp, message: "n'est pas valide" }, allow_nil: true
validates :claimant, presence: true
validates :question_answer, presence: { on: :update, if: -> { question_label.present? } }
validates :piece_justificative_file, size: { less_than: FILE_MAX_SIZE }
validates :introduction_file, size: { less_than: FILE_MAX_SIZE }
before_validation -> { sanitize_email(:email) }

View file

@ -17,6 +17,8 @@
%span.date.fr-text--xs.fr-text-mention--grey{ class: highlight_if_unseen_class(avis_seen_at, avis.created_at) }
= t('demande_envoyee_le', scope: 'views.shared.avis', date: l(avis.created_at, format: '%d/%m/%y à %H:%M'))
%p= avis.introduction
- if avis.question_label
%p= avis.question_label
.answer.flex.align-start
%span.icon.bubble.avis-icon

View file

@ -26,7 +26,10 @@
= f.text_area :introduction, rows: 3, class: 'fr-input', value: avis.introduction || 'Bonjour, merci de me donner votre avis sur ce dossier.', required: true
.fr-input-group
= f.label :question_label, t('helpers.label.question_label'), class: 'fr-label'
= f.label :question_label, class: 'fr-label' do
= t('helpers.label.question_label')
%span.fr-hint-text
= t('helpers.label.question_label_hint')
= f.text_area :question_label, label: "question", class: 'fr-input'
%p.tab-title Ajouter une pièce jointe
.form-group

View file

@ -7,10 +7,7 @@ en:
answer: "Answer"
claimant: Claimant
confidentiel: Confidential
errors:
models:
email:
empty: Email field can not be empty
question_answer: "Answer yes/no"
helpers:
label:
invite_linked_dossiers:
@ -19,6 +16,7 @@ en:
revoke: Revoke opinion request
remind: Remind the expert
question_label: Ask a question to the expert
question_label_hint: (optional field) the expert could answer by yes/no
introduction: Introduction message
question_answer:
true: 'yes'

View file

@ -7,10 +7,7 @@ fr:
answer: "Réponse"
claimant: Demandeur
confidentiel: confidentiel
errors:
models:
email:
empty: Le champ email ne peut pas être vide
question_answer: "Réponse oui/non"
helpers:
label:
invite_linked_dossiers:
@ -19,6 +16,7 @@ fr:
revoke: Révoquer la demande davis
remind: Relancer lexpert
question_label: Posez une question à l'expert
question_label_hint: (champ optionnel) l'expert pourra répondre par oui/non
introduction: Message d'introduction
question_answer:
true: oui

View file

@ -634,7 +634,7 @@ describe Instructeurs::DossiersController, type: :controller do
before { subject }
it { expect(response).to render_template :avis }
it { expect(flash.alert).to eq("Le champ email ne peut pas être vide") }
it { expect(flash.alert).to eq("Le champ « Emails » doit être rempli") }
it { expect { subject }.not_to change(Avis, :count) }
it { expect(dossier.last_avis_updated_at).to eq(nil) }
end

View file

@ -98,6 +98,10 @@ describe 'Inviting an expert:' do
expect(page).to have_text('Question ?')
expect(page).to have_text('Cet avis est confidentiel')
# check validation
click_on 'Envoyer votre avis'
expect(page).to have_content('Le champ « Réponse oui/non » doit être rempli')
choose 'oui'
fill_in 'avis_answer', with: 'Ma réponse dexpert.'
click_on 'Envoyer votre avis'