Merge pull request #9045 from mfo/US/fix-anchor-to-error-elements

correctif(users/dossiers/brouillon#submit): ETQ usager, je souhaite que chaque lien pointant vers une erreur de champ m'oriente sur le champ
This commit is contained in:
mfo 2023-05-23 04:08:38 +00:00 committed by GitHub
commit 3620cbadda
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 4 deletions

View file

@ -561,7 +561,7 @@ module Users
[ [
"Le champ « #{model.libelle.truncate(200)} » #{str_error}", "Le champ « #{model.libelle.truncate(200)} » #{str_error}",
helpers.link_to(t('views.users.dossiers.fix_champ'), public_send(route_helper, anchor: model.input_id)) helpers.link_to(t('views.users.dossiers.fix_champ'), public_send(route_helper, anchor: model.labelledby_id), class: 'error-anchor')
].join(", ") ].join(", ")
rescue # case of invalid type de champ on champ rescue # case of invalid type de champ on champ
str_error str_error

View file

@ -345,7 +345,7 @@ describe Users::DossiersController, type: :controller do
let!(:dossier) { create(:dossier, user: user) } let!(:dossier) { create(:dossier, user: user) }
let(:first_champ) { dossier.champs_public.first } let(:first_champ) { dossier.champs_public.first }
let(:anchor_to_first_champ) { controller.helpers.link_to I18n.t('views.users.dossiers.fix_champ'), brouillon_dossier_path(anchor: first_champ.input_id) } let(:anchor_to_first_champ) { controller.helpers.link_to I18n.t('views.users.dossiers.fix_champ'), brouillon_dossier_path(anchor: first_champ.labelledby_id), class: 'error-anchor' }
let(:value) { 'beautiful value' } let(:value) { 'beautiful value' }
let(:now) { Time.zone.parse('01/01/2100') } let(:now) { Time.zone.parse('01/01/2100') }
let(:payload) { { id: dossier.id } } let(:payload) { { id: dossier.id } }
@ -450,7 +450,7 @@ describe Users::DossiersController, type: :controller do
let!(:dossier) { create(:dossier, :en_construction, user: user) } let!(:dossier) { create(:dossier, :en_construction, user: user) }
let(:first_champ) { dossier.owner_editing_fork.champs_public.first } let(:first_champ) { dossier.owner_editing_fork.champs_public.first }
let(:anchor_to_first_champ) { controller.helpers.link_to I18n.t('views.users.dossiers.fix_champ'), modifier_dossier_path(anchor: first_champ.input_id) } let(:anchor_to_first_champ) { controller.helpers.link_to I18n.t('views.users.dossiers.fix_champ'), modifier_dossier_path(anchor: first_champ.labelledby_id), class: 'error-anchor' }
let(:value) { 'beautiful value' } let(:value) { 'beautiful value' }
let(:now) { Time.zone.parse('01/01/2100') } let(:now) { Time.zone.parse('01/01/2100') }
let(:payload) { { id: dossier.id } } let(:payload) { { id: dossier.id } }
@ -616,7 +616,7 @@ describe Users::DossiersController, type: :controller do
let(:procedure) { create(:procedure, :published, types_de_champ_public: [{}, { type: :piece_justificative }]) } let(:procedure) { create(:procedure, :published, types_de_champ_public: [{}, { type: :piece_justificative }]) }
let!(:dossier) { create(:dossier, :en_construction, user:, procedure:) } let!(:dossier) { create(:dossier, :en_construction, user:, procedure:) }
let(:first_champ) { dossier.champs_public.first } let(:first_champ) { dossier.champs_public.first }
let(:anchor_to_first_champ) { controller.helpers.link_to I18n.t('views.users.dossiers.fix_champ'), brouillon_dossier_path(anchor: first_champ.input_id) } let(:anchor_to_first_champ) { controller.helpers.link_to I18n.t('views.users.dossiers.fix_champ'), brouillon_dossier_path(anchor: first_champ.labelledby_id), class: 'error-anchor' }
let(:piece_justificative_champ) { dossier.champs_public.last } let(:piece_justificative_champ) { dossier.champs_public.last }
let(:value) { 'beautiful value' } let(:value) { 'beautiful value' }
let(:file) { fixture_file_upload('spec/fixtures/files/piece_justificative_0.pdf', 'application/pdf') } let(:file) { fixture_file_upload('spec/fixtures/files/piece_justificative_0.pdf', 'application/pdf') }

View file

@ -104,6 +104,18 @@ describe 'The user' do
expect(page).to have_text('Analyse antivirus en cours') expect(page).to have_text('Analyse antivirus en cours')
end end
scenario 'fill nothing and every error anchor links points to an existing element', js: true do
log_in(user, procedure)
fill_individual
click_on 'Déposer le dossier'
expect(page).to have_selector("#flash_message")
all('.error-anchor').map do |link_element|
error_anchor = URI(link_element['href'])
expect(page).to have_selector("##{error_anchor.fragment}")
end
end
let(:procedure_with_repetition) do let(:procedure_with_repetition) do
create(:procedure, :published, :for_individual, types_de_champ_public: [{ type: :repetition, mandatory: true, children: [{ libelle: 'sub type de champ' }] }]) create(:procedure, :published, :for_individual, types_de_champ_public: [{ type: :repetition, mandatory: true, children: [{ libelle: 'sub type de champ' }] }])
end end