From 7b1c8824987e728ee201400b2b660229f758330e Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Tue, 10 Sep 2024 23:53:04 +0200 Subject: [PATCH] spec(js): cleanup js tags --- .../administrateurs/admin_creation_spec.rb | 2 +- spec/system/experts/expert_spec.rb | 5 +-- spec/system/instructeurs/instruction_spec.rb | 11 +++-- .../instructeurs/procedure_filters_spec.rb | 2 +- spec/system/users/brouillon_spec.rb | 45 +++++++++---------- spec/system/users/dossier_creation_spec.rb | 3 +- spec/system/users/dropdown_spec.rb | 6 +-- spec/system/users/en_construction_spec.rb | 8 ++-- spec/system/users/linked_dropdown_spec.rb | 6 +-- spec/system/users/list_dossiers_spec.rb | 8 ++-- spec/system/users/managing_password_spec.rb | 4 +- 11 files changed, 47 insertions(+), 53 deletions(-) diff --git a/spec/system/administrateurs/admin_creation_spec.rb b/spec/system/administrateurs/admin_creation_spec.rb index 528067654..18e29e59d 100644 --- a/spec/system/administrateurs/admin_creation_spec.rb +++ b/spec/system/administrateurs/admin_creation_spec.rb @@ -17,7 +17,7 @@ describe 'As an administrateur', js: true do end end - scenario 'I can register', js: true do + scenario 'I can register' do expect(new_admin.reload.user.active?).to be(false) confirmation_email = open_email(admin_email) diff --git a/spec/system/experts/expert_spec.rb b/spec/system/experts/expert_spec.rb index 6f9309734..778a1932a 100644 --- a/spec/system/experts/expert_spec.rb +++ b/spec/system/experts/expert_spec.rb @@ -146,10 +146,7 @@ describe 'Inviting an expert:' do click_on '1 avis à donner' click_on avis.dossier.user.email - # click_on 'Télécharger le dossier et toutes ses pièces jointes' - # For some reason, clicking the download link does not trigger the download in the headless browser - # for some member of the team, so we need to go to the download link directly - visit telecharger_pjs_expert_avis_path(avis.dossier.procedure, avis) + click_on 'Télécharger le dossier et toutes ses pièces jointes' DownloadHelpers.wait_for_download files = ZipTricks::FileReader.read_zip_structure(io: File.open(DownloadHelpers.download)) diff --git a/spec/system/instructeurs/instruction_spec.rb b/spec/system/instructeurs/instruction_spec.rb index 220949a4d..50d3f506a 100644 --- a/spec/system/instructeurs/instruction_spec.rb +++ b/spec/system/instructeurs/instruction_spec.rb @@ -210,7 +210,7 @@ describe 'Instructing a dossier:', js: true do expect(Archive.first.month).not_to be_nil end end - context 'with dossiers having attached files', js: true do + context 'with dossiers having attached files' do let(:procedure) { create(:procedure, :published, types_de_champ_public: [{ type: :piece_justificative }], instructeurs: [instructeur]) } let(:dossier) { create(:dossier, :en_construction, procedure: procedure) } let(:champ) { dossier.champs_public.first } @@ -231,10 +231,7 @@ describe 'Instructing a dossier:', js: true do scenario 'A instructeur can download an archive containing a single attachment' do find(:css, '[aria-controls=print-pj-menu]').click - # click_on 'Télécharger le dossier et toutes ses pièces jointes' - # For some reason, clicking the download link does not trigger the download in the headless browser - # for some member of the team, so we need to go to the download link directly - visit telecharger_pjs_instructeur_dossier_path(procedure, dossier) + click_on 'Télécharger le dossier et toutes ses pièces jointes' DownloadHelpers.wait_for_download files = ZipTricks::FileReader.read_zip_structure(io: File.open(DownloadHelpers.download)) @@ -254,7 +251,9 @@ describe 'Instructing a dossier:', js: true do content_type: "application/pdf", metadata: { virus_scan_result: ActiveStorage::VirusScanner::SAFE }) - visit telecharger_pjs_instructeur_dossier_path(procedure, dossier) + find(:css, '[aria-controls=print-pj-menu]').click + click_on 'Télécharger le dossier et toutes ses pièces jointes' + DownloadHelpers.wait_for_download files = ZipTricks::FileReader.read_zip_structure(io: File.open(DownloadHelpers.download)) diff --git a/spec/system/instructeurs/procedure_filters_spec.rb b/spec/system/instructeurs/procedure_filters_spec.rb index b5cbf350a..05c8f72c6 100644 --- a/spec/system/instructeurs/procedure_filters_spec.rb +++ b/spec/system/instructeurs/procedure_filters_spec.rb @@ -206,7 +206,7 @@ describe "procedure filters" do fill_in "Valeur", with: filter_value when :date find("input#value[type=date]", visible: true) - fill_in "Valeur", with: filter_value + fill_in "Valeur", with: Date.parse(filter_value) when :enum find("select#value", visible: false) select filter_value, from: "Valeur" diff --git a/spec/system/users/brouillon_spec.rb b/spec/system/users/brouillon_spec.rb index 3af6a2497..c03ff3a07 100644 --- a/spec/system/users/brouillon_spec.rb +++ b/spec/system/users/brouillon_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -describe 'The user' do +describe 'The user', js: true do let(:password) { SECURE_PASSWORD } let!(:user) { create(:user, password: password) } @@ -8,7 +8,7 @@ describe 'The user' do let(:user_dossier) { user.dossiers.first } let!(:dossier_to_link) { create(:dossier) } - scenario 'fill a dossier', js: true, vcr: true do + scenario 'fill a dossier', vcr: true do log_in(user, procedure) fill_individual @@ -19,9 +19,9 @@ describe 'The user' do # fill data fill_in('text', with: 'super texte', match: :first) fill_in('textarea', with: 'super textarea') - fill_in('date', with: '12-12-2012', match: :first) + fill_in('date', with: Date.parse('2012-12-12'), match: :first) fill_in('datetime', with: Time.zone.parse('2023-01-06T07:05')) - find("input[type=datetime-local]").send_keys(:arrow_up).send_keys(:arrow_down) # triggers onChange + find("input[type=datetime-local]").send_keys('ArrowUp').send_keys('ArrowDown') # triggers onChange # fill_in('number', with: '42'), deadchamp, should be migrated to textchamp fill_in('decimal_number', with: '17') fill_in('integer_number', with: '12') @@ -125,7 +125,7 @@ describe 'The user' do expect(page).to have_text('file.pdf') end - scenario 'fill nothing and every error anchor links points to an existing element', js: true do + scenario 'fill nothing and every error anchor links points to an existing element' do log_in(user, procedure) fill_individual click_on 'Déposer le dossier' @@ -141,7 +141,7 @@ describe 'The user' do create(:procedure, :published, :for_individual, types_de_champ_public: [{ type: :repetition, mandatory: true, children: [{ libelle: 'sub type de champ' }] }]) end - scenario 'fill a dossier with repetition', js: true do + scenario 'fill a dossier with repetition' do log_in(user, procedure_with_repetition) fill_individual @@ -184,7 +184,7 @@ describe 'The user' do ]) } - scenario 'save an incomplete dossier as draft but cannot not submit it', js: true do + scenario 'save an incomplete dossier as draft but cannot not submit it' do log_in(user, simple_procedure) fill_individual @@ -219,7 +219,7 @@ describe 'The user' do expect(page).to have_current_path(merci_dossier_path(user_dossier)) end - scenario 'fill address not in BAN', js: true do + scenario 'fill address not in BAN' do log_in(user, simple_procedure) fill_individual @@ -230,7 +230,7 @@ describe 'The user' do expect(champ_for('address').full_address?).to be_falsey end - scenario 'numbers champs formatting', js: true do + scenario 'numbers champs formatting' do log_in(user, simple_procedure) fill_individual @@ -287,7 +287,7 @@ describe 'The user' do } end - scenario 'extends dossier experation date more than one time, ', js: true do + scenario 'extends dossier experation date more than one time, ' do simple_procedure.update(procedure_expires_when_termine_enabled: true) user_old_dossier = create(:dossier, procedure: simple_procedure, @@ -312,7 +312,7 @@ describe 'The user' do let(:procedure_with_pjs) { create(:procedure, :published, :for_individual, types_de_champ_public: [{ type: :piece_justificative, mandatory: true, libelle: 'Pièce justificative 1' }, { type: :piece_justificative, mandatory: true, libelle: 'Pièce justificative 2' }]) } let(:old_procedure_with_disabled_pj_validation) { create(:procedure, :published, :for_individual, types_de_champ_public: [{ type: :piece_justificative, mandatory: true, libelle: 'Pièce justificative 1', skip_pj_validation: true }]) } - scenario 'add an attachment', js: true do + scenario 'add an attachment' do log_in(user, procedure_with_pjs) fill_individual @@ -336,7 +336,7 @@ describe 'The user' do expect(page).to have_text('RIB.pdf') end - scenario 'add an invalid attachment on an old procedure where pj validation is disabled', js: true do + scenario 'add an invalid attachment on an old procedure where pj validation is disabled' do log_in(user, old_procedure_with_disabled_pj_validation) fill_individual @@ -345,7 +345,7 @@ describe 'The user' do expect(page).to have_no_text('La pièce justificative n’est pas d’un type accepté') end - scenario 'retry on transcient upload error', js: true do + scenario 'retry on transcient upload error' do log_in(user, procedure_with_pjs) fill_individual @@ -374,7 +374,7 @@ describe 'The user' do expect(page).to have_text('file.pdf') end - scenario "upload multiple pieces justificatives on same champ", js: true do + scenario "upload multiple pieces justificatives on same champ" do log_in(user, procedure_with_pjs) fill_individual @@ -437,7 +437,7 @@ describe 'The user' do ]) end - scenario 'submit a dossier with an hidden mandatory champ within a repetition', js: true do + scenario 'submit a dossier with an hidden mandatory champ within a repetition' do log_in(user, procedure) fill_individual @@ -467,7 +467,7 @@ describe 'The user' do ]) end - scenario 'fill a dossier', js: true do + scenario 'fill a dossier' do log_in(user, procedure) fill_individual @@ -499,7 +499,7 @@ describe 'The user' do ]) end - scenario 'submit a dossier with an hidden mandatory champ ', js: true do + scenario 'submit a dossier with an hidden mandatory champ ' do log_in(user, procedure) fill_individual @@ -508,7 +508,7 @@ describe 'The user' do 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 + scenario 'cannot submit a reveal dossier with a revealed mandatory champ ' do log_in(user, procedure) fill_individual @@ -540,7 +540,7 @@ describe 'The user' do ]) end - scenario 'fill a dossier', js: true do + scenario 'fill a dossier' do log_in(user, procedure) fill_individual @@ -589,7 +589,7 @@ describe 'The user' do end context 'draft autosave' do - scenario 'autosave a draft', js: true do + scenario 'autosave a draft' do log_in(user, simple_procedure) fill_individual @@ -604,7 +604,7 @@ describe 'The user' do expect(page).to have_field('texte obligatoire', with: 'a valid user input') end - scenario 'retry on autosave error', :capybara_ignore_server_errors, js: true do + scenario 'retry on autosave error', :capybara_ignore_server_errors do log_in(user, simple_procedure) fill_individual @@ -624,7 +624,7 @@ describe 'The user' do expect(page).to have_field('texte obligatoire', with: 'a valid user input') end - scenario 'autosave redirects to sign-in after being disconnected', js: true do + scenario 'autosave redirects to sign-in after being disconnected' do log_in(user, simple_procedure) fill_individual @@ -632,7 +632,6 @@ describe 'The user' do # (either because signing-out in another tab, or because the session cookie expired) logout(:user) fill_in('texte obligatoire', with: 'a valid user input') - blur # … they are redirected to the sign-in page. expect(page).to have_current_path(new_user_session_path) diff --git a/spec/system/users/dossier_creation_spec.rb b/spec/system/users/dossier_creation_spec.rb index 9bdec533b..02f95a808 100644 --- a/spec/system/users/dossier_creation_spec.rb +++ b/spec/system/users/dossier_creation_spec.rb @@ -44,11 +44,10 @@ describe 'Creating a new dossier:', js: true do let(:expected_birthday) { Date.new(1987, 12, 10) } before do - fill_in 'Date de naissance', with: birthday_format + fill_in 'Date de naissance', with: expected_birthday end 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 diff --git a/spec/system/users/dropdown_spec.rb b/spec/system/users/dropdown_spec.rb index fd2c6792a..b88caab5f 100644 --- a/spec/system/users/dropdown_spec.rb +++ b/spec/system/users/dropdown_spec.rb @@ -22,14 +22,14 @@ describe 'dropdown list with other option activated', js: true do ] end - scenario 'Select other option and the other input hidden must appear', js: true do + scenario 'Select other option and the other input hidden must appear' do fill_individual - find('.fr-fieldset__content .fr-radio-group:last-of-type input').select_option + choose "Autre" expect(page).to have_selector('.drop_down_other', visible: true) end - scenario "Getting back from other save the new option", js: true do + scenario "Getting back from other save the new option" do fill_individual choose "Autre" diff --git a/spec/system/users/en_construction_spec.rb b/spec/system/users/en_construction_spec.rb index 84dab4320..f34e8c993 100644 --- a/spec/system/users/en_construction_spec.rb +++ b/spec/system/users/en_construction_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -describe "Dossier en_construction" do +describe "Dossier en_construction", js: true do let(:user) { create(:user) } let(:procedure) { create(:procedure, :for_individual, types_de_champ_public: [{ type: :piece_justificative }, { type: :titre_identite }]) } let(:dossier) { create(:dossier, :en_construction, :with_individual, :with_populated_champs, user:, procedure:) } @@ -13,7 +13,7 @@ describe "Dossier en_construction" do dossier.find_editing_fork(dossier.user).champs_public.find { _1.stable_id == tdc.stable_id } } - scenario 'delete a non mandatory piece justificative', js: true do + scenario 'delete a non mandatory piece justificative' do visit_dossier(dossier) expect(page).not_to have_button("Remplacer") @@ -28,7 +28,7 @@ describe "Dossier en_construction" do tdc.update_attribute(:mandatory, true) end - scenario 'remplace a mandatory piece justificative', js: true do + scenario 'remplace a mandatory piece justificative' do visit_dossier(dossier) click_on "Supprimer le fichier toto.txt" @@ -52,7 +52,7 @@ describe "Dossier en_construction" do tdc.update_attribute(:mandatory, true) end - scenario 'remplace a mandatory titre identite', js: true do + scenario 'remplace a mandatory titre identite' do visit_dossier(dossier) click_on "Supprimer le fichier toto.png" diff --git a/spec/system/users/linked_dropdown_spec.rb b/spec/system/users/linked_dropdown_spec.rb index 40029a15f..af5d8ff9f 100644 --- a/spec/system/users/linked_dropdown_spec.rb +++ b/spec/system/users/linked_dropdown_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -describe 'linked dropdown lists' do +describe 'linked dropdown lists', js: true do let(:password) { SECURE_PASSWORD } let!(:user) { create(:user, password: password) } @@ -21,7 +21,7 @@ describe 'linked dropdown lists' do let(:user_dossier) { user.dossiers.first } context 'not mandatory' do let(:mandatory) { false } - scenario 'change primary value, secondary options are updated', js: true do + scenario 'change primary value, secondary options are updated' do log_in(user.email, password, procedure) fill_individual @@ -44,7 +44,7 @@ describe 'linked dropdown lists' do context 'mandatory' do let(:mandatory) { true } - scenario 'change primary value, secondary options are updated', js: true do + scenario 'change primary value, secondary options are updated' do log_in(user.email, password, procedure) fill_individual diff --git a/spec/system/users/list_dossiers_spec.rb b/spec/system/users/list_dossiers_spec.rb index be9ecc6c0..5d4cc3eac 100644 --- a/spec/system/users/list_dossiers_spec.rb +++ b/spec/system/users/list_dossiers_spec.rb @@ -184,7 +184,7 @@ describe 'user access to the list of their dossiers', js: true do expect(page).not_to have_link('Supprimer le dossier', href: dossier_path(dossier_en_instruction)) end - context 'when user clicks on delete button', js: true do + context 'when user clicks on delete button' do scenario 'the dossier is deleted' do expect(page).to have_content(dossier_en_construction.procedure.libelle) within(:css, ".card", match: :first) do @@ -207,7 +207,7 @@ describe 'user access to the list of their dossiers', js: true do expect(page).to have_link(nil, href: clone_dossier_path(dossier_en_instruction)) end - context 'when user clicks on clone button', js: true do + context 'when user clicks on clone button' do scenario 'the dossier is cloned' do within(:css, ".card", match: :first) do click_on 'Autres actions' @@ -227,7 +227,7 @@ describe 'user access to the list of their dossiers', js: true do expect(page).to have_link('Télécharger mon dossier', href: dossier_path("#{dossier_traite_expire.id}.pdf")) end - context 'when user clicks on restore button', js: true do + context 'when user clicks on restore button' do scenario 'the dossier is restored' do click_on "3 supprimés" expect(page).to have_content(dossier_en_construction_supprime.procedure.libelle) @@ -238,7 +238,7 @@ describe 'user access to the list of their dossiers', js: true do end end - context 'when user clicks on restore and extend button', js: true do + context 'when user clicks on restore and extend button' do scenario 'the dossier is restored and extended' do click_on "3 supprimés" expect(page).to have_content(dossier_en_construction_expire.procedure.libelle) diff --git a/spec/system/users/managing_password_spec.rb b/spec/system/users/managing_password_spec.rb index 1c7fac97b..6965ac88e 100644 --- a/spec/system/users/managing_password_spec.rb +++ b/spec/system/users/managing_password_spec.rb @@ -36,7 +36,7 @@ describe 'Managing password:', js: true do let(:weak_password) { '12345678' } let(:strong_password) { 'a new, long, and complicated password!' } - scenario 'an admin can reset their password', js: true do + scenario 'an admin can reset their password' do visit root_path within('.fr-header .fr-container .fr-header__tools .fr-btns-group') do click_on 'Se connecter' @@ -75,7 +75,7 @@ describe 'Managing password:', js: true do let(:weak_password) { '12345678' } let(:strong_password) { 'a new, long, and complicated password!' } - scenario 'a super-admin can reset their password', js: true do + scenario 'a super-admin can reset their password' do visit manager_root_path click_on 'Mot de passe oublié' expect(page).to have_current_path(new_super_admin_password_path)