From 43f5f4e0304cd205ab264be968cebceb2fa825c6 Mon Sep 17 00:00:00 2001 From: Lisa Durand Date: Tue, 28 Nov 2023 12:43:43 +0100 Subject: [PATCH] fix test --- .../instructeurs/dossiers/print.html.haml | 2 +- app/views/users/dossiers/identite.html.haml | 59 +++++++------ .../shared_examples_for_prefilled_dossier.rb | 7 +- spec/system/accessibilite/wcag_usager_spec.rb | 6 +- .../api_particulier/api_particulier_spec.rb | 27 +++--- spec/system/users/dossier_creation_spec.rb | 84 +++++++++---------- spec/system/users/dropdown_spec.rb | 6 +- spec/system/users/linked_dropdown_spec.rb | 6 +- spec/system/users/list_dossiers_spec.rb | 30 +++---- .../users/dossiers/identite.html.haml_spec.rb | 6 +- 10 files changed, 124 insertions(+), 109 deletions(-) diff --git a/app/views/instructeurs/dossiers/print.html.haml b/app/views/instructeurs/dossiers/print.html.haml index bfb76b0df..be72f16cf 100644 --- a/app/views/instructeurs/dossiers/print.html.haml +++ b/app/views/instructeurs/dossiers/print.html.haml @@ -3,7 +3,7 @@ %h2 Identité du demandeur -= render partial: "shared/dossiers/user_infos", locals: { user_deleted: @dossier.user_deleted?, email: @dossier.user_email_for(:display) } += render partial: "shared/dossiers/user_infos", locals: { user_deleted: @dossier.user_deleted?, email: @dossier.user_email_for(:display), for_tiers: @dossier.for_tiers? } - if @dossier.etablissement.present? = render partial: "shared/dossiers/identite_entreprise", locals: { etablissement: @dossier.etablissement, profile: 'instructeur' } diff --git a/app/views/users/dossiers/identite.html.haml b/app/views/users/dossiers/identite.html.haml index 388102f32..d32608eb6 100644 --- a/app/views/users/dossiers/identite.html.haml +++ b/app/views/users/dossiers/identite.html.haml @@ -24,7 +24,7 @@ .fr-radio-rich__img %span.fr-icon-parent-fill - %div{ "data-for-tiers-target" => "mandataireBlock" } + .mandataire-infos{ "data-for-tiers-target" => "mandataireBlock" } .fr-alert.fr-alert--info.fr-mb-2w %p.fr-notice__text= t('views.users.dossiers.identite.callout_text') @@ -32,43 +32,40 @@ %h2.fr-h4= t('views.users.dossiers.identite.self_title') .fr-fieldset__element.fr-fieldset__element--short-text - = render Dsfr::InputComponent.new(form: f, attribute: :mandataire_first_name, opts: { "data-for-tiers-target" => "mandataireFirstName", id: 'mandataire_first_name' }) do |c| - - c.with_label do - = t('activerecord.attributes.dossier.mandataire_first_name') + = render Dsfr::InputComponent.new(form: f, attribute: :mandataire_first_name, opts: { "data-for-tiers-target" => "mandataireFirstName" }) .fr-fieldset__element.fr-fieldset__element--short-text - = render Dsfr::InputComponent.new(form: f, attribute: :mandataire_last_name, opts: { "data-for-tiers-target" => "mandataireLastName", id: 'mandataire_last_name' }) do |c| - - c.with_label do - = t('activerecord.attributes.dossier.mandataire_last_name') + = render Dsfr::InputComponent.new(form: f, attribute: :mandataire_last_name, opts: { "data-for-tiers-target" => "mandataireLastName" }) = f.fields_for :individual do |individual| - %fieldset.fr-fieldset - %legend.fr-fieldset__legend--regular.fr-fieldset__legend{ "data-for-tiers-target" => "mandataireTitle" } - %h2.fr-h4= t('views.users.dossiers.identite.self_title') + .individual-infos.mt-3 + %fieldset.fr-fieldset + %legend.fr-fieldset__legend--regular.fr-fieldset__legend{ "data-for-tiers-target" => "mandataireTitle" } + %h2.fr-h4= t('views.users.dossiers.identite.self_title') - %legend.fr-fieldset__legend--regular.fr-fieldset__legend.hidden{ "data-for-tiers-target" => "beneficiaireTitle" } - %h2.fr-h4= t('views.users.dossiers.identite.beneficiaire_title') - .fr-fieldset__element - %fieldset.fr-fieldset - %legend.fr-fieldset__legend--regular.fr-fieldset__legend - = t('activerecord.attributes.individual.gender') - = render EditableChamp::AsteriskMandatoryComponent.new - .fr-fieldset__element - .fr-radio-group - = individual.radio_button :gender, Individual::GENDER_FEMALE, required: true, id: "identite_champ_radio_#{Individual::GENDER_FEMALE}" - %label.fr-label{ for: "identite_champ_radio_#{Individual::GENDER_FEMALE}" } - = Individual.human_attribute_name('gender.female') - .fr-fieldset__element - .fr-radio-group - = individual.radio_button :gender, Individual::GENDER_MALE, required: true, id: "identite_champ_radio_#{Individual::GENDER_MALE}" - %label.fr-label{ for: "identite_champ_radio_#{Individual::GENDER_MALE}" } - = Individual.human_attribute_name('gender.male') + %legend.fr-fieldset__legend--regular.fr-fieldset__legend.hidden{ "data-for-tiers-target" => "beneficiaireTitle" } + %h2.fr-h4= t('views.users.dossiers.identite.beneficiaire_title') + .fr-fieldset__element + %fieldset.fr-fieldset + %legend.fr-fieldset__legend--regular.fr-fieldset__legend + = t('activerecord.attributes.individual.gender') + = render EditableChamp::AsteriskMandatoryComponent.new + .fr-fieldset__element + .fr-radio-group + = individual.radio_button :gender, Individual::GENDER_FEMALE, required: true, id: "identite_champ_radio_#{Individual::GENDER_FEMALE}" + %label.fr-label{ for: "identite_champ_radio_#{Individual::GENDER_FEMALE}" } + = Individual.human_attribute_name('gender.female') + .fr-fieldset__element + .fr-radio-group + = individual.radio_button :gender, Individual::GENDER_MALE, required: true, id: "identite_champ_radio_#{Individual::GENDER_MALE}" + %label.fr-label{ for: "identite_champ_radio_#{Individual::GENDER_MALE}" } + = Individual.human_attribute_name('gender.male') - .fr-fieldset__element.fr-fieldset__element--short-text - = render Dsfr::InputComponent.new(form: individual, attribute: :prenom, opts: { autocomplete: 'given-name', id: 'indiv_first_name' }) + .fr-fieldset__element.fr-fieldset__element--short-text + = render Dsfr::InputComponent.new(form: individual, attribute: :prenom, opts: { autocomplete: 'given-name' }) - .fr-fieldset__element.fr-fieldset__element--short-text - = render Dsfr::InputComponent.new(form: individual, attribute: :nom, opts: { autocomplete: 'family-name', id: 'indiv_last_name' }) + .fr-fieldset__element.fr-fieldset__element--short-text + = render Dsfr::InputComponent.new(form: individual, attribute: :nom, opts: { autocomplete: 'family-name' }) .width-100{ "data-for-tiers-target" => "beneficiaireNotificationBlock" } diff --git a/spec/support/shared_examples_for_prefilled_dossier.rb b/spec/support/shared_examples_for_prefilled_dossier.rb index a65ad9029..4a31f3668 100644 --- a/spec/support/shared_examples_for_prefilled_dossier.rb +++ b/spec/support/shared_examples_for_prefilled_dossier.rb @@ -3,8 +3,11 @@ shared_examples "the user has got a prefilled dossier, owned by themselves" do expect(dossier.user).to eq(user) expect(page).to have_current_path identite_dossier_path(procedure.dossiers.last) - expect(page).to have_field('Prénom', with: prenom_value) - expect(page).to have_field('Nom', with: nom_value) + + within('.individual-infos') do + expect(page).to have_field('Prénom', with: prenom_value) + expect(page).to have_field('Nom', with: nom_value) + end click_on 'Continuer' expect(page).to have_current_path(brouillon_dossier_path(dossier)) diff --git a/spec/system/accessibilite/wcag_usager_spec.rb b/spec/system/accessibilite/wcag_usager_spec.rb index 620981c8b..3addff918 100644 --- a/spec/system/accessibilite/wcag_usager_spec.rb +++ b/spec/system/accessibilite/wcag_usager_spec.rb @@ -122,8 +122,10 @@ describe 'wcag rules for usager', js: true do click_on 'Commencer la démarche' find('label', text: 'Monsieur') - fill_in('Prénom', with: 'prenom', visible: true) - fill_in('Nom', with: 'nom', visible: true) + within('.individual-infos') do + fill_in('Prénom', with: 'prenom') + fill_in('Nom', with: 'nom') + end click_on 'Continuer' expect(page).to be_axe_clean diff --git a/spec/system/api_particulier/api_particulier_spec.rb b/spec/system/api_particulier/api_particulier_spec.rb index affe8f700..ecd9a1982 100644 --- a/spec/system/api_particulier/api_particulier_spec.rb +++ b/spec/system/api_particulier/api_particulier_spec.rb @@ -267,8 +267,10 @@ describe 'fetch API Particulier Data', js: true do click_on 'Commencer la démarche' find('label', text: 'Monsieur').click - fill_in('indiv_first_name', with: 'prenom', visible: true) - fill_in('indiv_last_name', with: 'nom', visible: true) + within('.individual-infos') do + fill_in('Prénom', with: 'prenom') + fill_in('Nom', with: 'nom') + end click_button('Continuer') @@ -325,9 +327,10 @@ describe 'fetch API Particulier Data', js: true do click_on 'Commencer la démarche' find('label', text: 'Monsieur').click - fill_in('indiv_first_name', with: 'Georges', visible: true) - fill_in('indiv_last_name', with: 'Moustaki', visible: true) - + within('.individual-infos') do + fill_in('Prénom', with: 'Georges') + fill_in('Nom', with: 'Moustaki') + end click_button('Continuer') fill_in "Identifiant", with: 'wrong code' @@ -398,9 +401,10 @@ describe 'fetch API Particulier Data', js: true do click_on 'Commencer la démarche' find('label', text: 'Madame').click - fill_in('indiv_first_name', with: 'Dubois', visible: true) - fill_in('indiv_last_name', with: 'Angela Claire Louise', visible: true) - + within('.individual-infos') do + fill_in('Prénom', with: 'Angela Claire Louise') + fill_in('Nom', with: 'Dubois') + end click_button('Continuer') fill_in "INE", with: 'wrong code' @@ -461,9 +465,10 @@ describe 'fetch API Particulier Data', js: true do click_on 'Commencer la démarche' find('label', text: 'Madame').click - fill_in('indiv_last_name', with: 'FERRI', visible: true) - fill_in('indiv_first_name', with: 'Karine', visible: true) - + within('.individual-infos') do + fill_in('Prénom', with: 'Karine') + fill_in('Nom', with: 'FERRI') + end click_button('Continuer') fill_in 'Le numéro fiscal', with: numero_fiscal diff --git a/spec/system/users/dossier_creation_spec.rb b/spec/system/users/dossier_creation_spec.rb index 4bfa82c6d..6bdeae582 100644 --- a/spec/system/users/dossier_creation_spec.rb +++ b/spec/system/users/dossier_creation_spec.rb @@ -1,4 +1,4 @@ -describe 'Creating a new dossier:' do +describe 'Creating a new dossier:', js: true do let(:user) { create(:user) } let(:siret) { '41816609600051' } let(:siren) { siret[0...9] } @@ -22,8 +22,8 @@ describe 'Creating a new dossier:' do expect(page).to have_title(libelle) find('label', text: 'Monsieur').click - fill_in('indiv_first_name', with: 'prenom') - fill_in('indiv_last_name', with: 'nom') + fill_in('Prénom', with: 'prenom', visible: true) + fill_in('Nom', with: 'nom', visible: true) end shared_examples 'the user can create a new draft' do @@ -31,26 +31,20 @@ describe 'Creating a new dossier:' do click_button('Continuer') expect(page).to have_current_path(brouillon_dossier_path(procedure.dossiers.last)) - expect(user.dossiers.first.individual.birthdate).to eq(expected_birthday) end end context 'when the birthday is asked' do let(:ask_birthday) { true } - let(:expected_birthday) { Date.new(1987, 10, 14) } + let(:expected_birthday) { Date.new(1987, 12, 10) } before do fill_in 'Date de naissance', with: birthday_format end - context 'when the browser supports `type=date` input fields' do - let(:birthday_format) { '1987-10-14' } - it_behaves_like 'the user can create a new draft' - end - - context 'when the browser does not support `type=date` input fields' do - let(:birthday_format) { '1987-10-14' } + context 'when the birthday is asked' do + let(:birthday_format) { '12-10-1987' } it_behaves_like 'the user can create a new draft' end end @@ -60,43 +54,49 @@ describe 'Creating a new dossier:' do let(:expected_birthday) { nil } it_behaves_like 'the user can create a new draft' end - end - context 'when identifying as mandataire' do - let(:libelle) { "[title] with characters to escape : '@*^$" } - let(:procedure) { create(:procedure, :published, :for_individual, :with_service, ask_birthday: ask_birthday, libelle: libelle) } - let(:ask_birthday) { false } - let(:expected_birthday) { nil } + context 'when individual fill dossier for a tiers' do + it 'completes the form with email notification method selected' do + find('label', text: 'Pour un bénéficiaire : membre de la famille, proche, mandant...').click - before do - visit commencer_path(path: procedure.path) - click_on 'Commencer la démarche' + within('.mandataire-infos') do + fill_in('Prénom', with: 'John') + fill_in('Nom', with: 'Doe') + end - expect(page).to have_current_path identite_dossier_path(user.reload.dossiers.last) - expect(page).to have_title(libelle) + find('label', text: 'Monsieur').click - find('#radio-tiers-manage').click - fill_in('mandataire_first_name', with: 'John') - fill_in('mandataire_last_name', with: 'Doe') + within('.individual-infos') do + fill_in('Prénom', with: 'prenom') + fill_in('Nom', with: 'nom') + end - find('label', text: 'Monsieur').click - fill_in('indiv_first_name', with: 'prenom') - fill_in('indiv_last_name', with: 'nom') - end + find('label', text: 'Par e-mail').click + fill_in('dossier_individual_attributes_email', with: 'prenom.nom@mail.com') + click_button('Continuer') + expect(procedure.dossiers.last.individual.notification_method == 'email') + expect(page).to have_current_path(brouillon_dossier_path(procedure.dossiers.last)) + end - it 'completes the form with email notification method selected' do - find('#notification_method_email').click - fill_in('dossier_individual_attributes_email', with: 'prenom.nom@mail.com') - click_button('Continuer') - expect(procedure.dossiers.last.individual.notification_method == 'email') - expect(page).to have_current_path(brouillon_dossier_path(procedure.dossiers.last)) - end + it 'completes the form with no notification method selected' do + find('label', text: 'Pour un bénéficiaire : membre de la famille, proche, mandant...').click - it 'completes the form with no notification method selected' do - find('#notification_method_no_notification').click - click_button('Continuer') - expect(procedure.dossiers.last.individual.notification_method.empty?) - expect(page).to have_current_path(brouillon_dossier_path(procedure.dossiers.last)) + within('.mandataire-infos') do + fill_in('Prénom', with: 'John') + fill_in('Nom', with: 'Doe') + end + + find('label', text: 'Monsieur').click + within('.individual-infos') do + fill_in('Prénom', with: 'prenom') + fill_in('Nom', with: 'nom') + end + + find('label', text: 'Pas de notification').click + click_button('Continuer') + expect(procedure.dossiers.last.individual.notification_method.empty?) + expect(page).to have_current_path(brouillon_dossier_path(procedure.dossiers.last)) + end end end diff --git a/spec/system/users/dropdown_spec.rb b/spec/system/users/dropdown_spec.rb index 5966f1cab..25645c02e 100644 --- a/spec/system/users/dropdown_spec.rb +++ b/spec/system/users/dropdown_spec.rb @@ -75,8 +75,10 @@ describe 'dropdown list with other option activated', js: true do def fill_individual find('label', text: 'Monsieur').click - fill_in('Prénom', with: 'prenom', visible: true) - fill_in('Nom', with: 'Nom', visible: true) + within('.individual-infos') do + fill_in('Prénom', with: 'prenom') + fill_in('Nom', with: 'nom') + end click_on 'Continuer' expect(page).to have_current_path(brouillon_dossier_path(user_dossier)) end diff --git a/spec/system/users/linked_dropdown_spec.rb b/spec/system/users/linked_dropdown_spec.rb index baa6947d8..83b8fd459 100644 --- a/spec/system/users/linked_dropdown_spec.rb +++ b/spec/system/users/linked_dropdown_spec.rb @@ -81,8 +81,10 @@ describe 'linked dropdown lists' do def fill_individual find('label', text: 'Monsieur').click - fill_in('Prénom', with: 'prenom', visible: true) - fill_in('Nom', with: 'nom', visible: true) + within('.individual-infos') do + fill_in('Prénom', with: 'prenom') + fill_in('Nom', with: 'nom') + end click_on 'Continuer' expect(page).to have_current_path(brouillon_dossier_path(user_dossier)) end diff --git a/spec/system/users/list_dossiers_spec.rb b/spec/system/users/list_dossiers_spec.rb index 18b5d4208..5629b3a04 100644 --- a/spec/system/users/list_dossiers_spec.rb +++ b/spec/system/users/list_dossiers_spec.rb @@ -8,6 +8,7 @@ describe 'user access to the list of their dossiers', js: true do let!(:dossier_refuse) { create(:dossier, :refuse, user: user) } let!(:dossier_a_corriger) { create(:dossier_correction, dossier: dossier_en_construction_2) } let!(:dossier_archived) { create(:dossier, :en_instruction, :archived, user: user) } + let!(:dossier_for_tiers) { create(:dossier, :en_instruction, :for_tiers_with_notification, user: user) } let(:dossiers_per_page) { 25 } let(:last_updated_dossier) { dossier_en_construction } @@ -30,7 +31,7 @@ describe 'user access to the list of their dossiers', js: true do expect(page).to have_content(dossier_en_construction.procedure.libelle) expect(page).to have_content(dossier_en_instruction.procedure.libelle) expect(page).to have_content(dossier_archived.procedure.libelle) - expect(page).to have_text('5 en cours') + expect(page).to have_text('6 en cours') expect(page).to have_text('2 traités') end @@ -52,25 +53,26 @@ describe 'user access to the list of their dossiers', js: true do scenario 'the user can navigate through the other pages' do expect(page).not_to have_link(dossier_en_instruction.procedure.libelle) page.click_link("Suivant") + page.click_link("Suivant") expect(page).to have_link(dossier_en_instruction.procedure.libelle) - expect(page).to have_text('5 en cours') + expect(page).to have_text('6 en cours') expect(page).to have_text('2 traités') end end context 'when the dossier is for_tiers' do - let(:dossier) { create(:dossier, :for_tiers_without_notification, user: user) } - let(:individual) { dossier.individual } + let(:individual) { dossier_for_tiers.individual } + it 'displays the name of the mandataire' do - expect(page).to have_content("#{individual.prenom} #{individual.nom}, dossier rempli par le mandataire #{dossier.mandataire_full_name}") + expect(page).to have_content("#{individual.prenom} #{individual.nom}, dossier rempli par le mandataire #{dossier_for_tiers.mandataire_full_name}") end end context 'when user uses filter' do scenario 'user filters state on tab "en-cours"' do - expect(page).to have_text('5 en cours') + expect(page).to have_text('6 en cours') expect(page).to have_text('2 traités') - expect(page).to have_text('5 sur 5 dossiers') + expect(page).to have_text('6 sur 6 dossiers') click_on('Sélectionner un filtre') expect(page).to have_select 'Statut', selected: 'Sélectionner un statut', options: ['Sélectionner un statut', 'Brouillon', 'En construction', 'En instruction', 'À corriger'] @@ -90,7 +92,7 @@ describe 'user access to the list of their dossiers', js: true do scenario 'user filters state on tab "traité"' do visit dossiers_path(statut: 'traites') - expect(page).to have_text('5 en cours') + expect(page).to have_text('6 en cours') expect(page).to have_text('2 traités') expect(page).to have_text('2 sur 2 dossiers') @@ -110,11 +112,11 @@ describe 'user access to the list of their dossiers', js: true do scenario 'user filters by created_at' do dossier_en_construction.update!(created_at: Date.yesterday) - expect(page).to have_text('5 sur 5 dossiers') + expect(page).to have_text('6 sur 6 dossiers') click_on('Sélectionner un filtre') fill_in 'from_created_at_date', with: Date.today click_on('Appliquer les filtres') - expect(page).to have_text('4 sur 4 dossiers') + expect(page).to have_text('5 sur 5 dossiers') end scenario 'user uses multiple filters' do @@ -122,11 +124,11 @@ describe 'user access to the list of their dossiers', js: true do expect(page).to have_select 'Statut', selected: 'Sélectionner un statut', options: ['Sélectionner un statut', 'Brouillon', 'En construction', 'En instruction', 'À corriger'] - expect(page).to have_text('5 sur 5 dossiers') + expect(page).to have_text('6 sur 6 dossiers') click_on('Sélectionner un filtre') fill_in 'from_created_at_date', with: Date.today click_on('Appliquer les filtres') - expect(page).to have_text('4 sur 4 dossiers') + expect(page).to have_text('5 sur 5 dossiers') expect(page).to have_text('1 filtre actif') click_on('Sélectionner un filtre') @@ -141,7 +143,7 @@ describe 'user access to the list of their dossiers', js: true do expect(page).to have_text('1 dossier') expect(page).to have_text('3 filtres actifs') click_on('3 filtres actifs') - expect(page).to have_text('5 sur 5 dossiers') + expect(page).to have_text('6 sur 6 dossiers') expect(page).not_to have_text('5 filtres actifs') end end @@ -283,7 +285,7 @@ describe 'user access to the list of their dossiers', js: true do describe "filter by procedure" do context "when dossiers are on different procedures" do it "can filter by procedure" do - expect(page).to have_text('5 en cours') + expect(page).to have_text('6 en cours') expect(page).to have_text('2 traités') expect(page).to have_select('procedure_id', selected: 'Toutes les démarches') select dossier_brouillon.procedure.libelle, from: 'procedure_id' diff --git a/spec/views/users/dossiers/identite.html.haml_spec.rb b/spec/views/users/dossiers/identite.html.haml_spec.rb index cf2801648..7c065f980 100644 --- a/spec/views/users/dossiers/identite.html.haml_spec.rb +++ b/spec/views/users/dossiers/identite.html.haml_spec.rb @@ -10,8 +10,10 @@ describe 'users/dossiers/identite', type: :view do subject! { render } it 'has identity fields' do - expect(rendered).to have_field(id: 'indiv_first_name') - expect(rendered).to have_field(id: 'indiv_last_name') + within('.individual-infos') do + expect(rendered).to have_field(id: 'Prenom') + expect(rendered).to have_field(id: 'Nom') + end end context 'when the demarche asks for the birthdate' do