From 9ec5befa0960e42958424b1385d11780218c5e3a Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 7 Aug 2018 12:30:54 +0200 Subject: [PATCH 1/4] specs: increase Capybara default timeout Because CircleCI machines are slow, and tests sometimes timeout. --- spec/spec_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index c33b295f9..1de2c6b03 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -47,7 +47,7 @@ Capybara.register_driver :headless_chrome do |app| desired_capabilities: capabilities end -Capybara.default_max_wait_time = 1 +Capybara.default_max_wait_time = 2 # Save a snapshot of the HTML page when an integration test fails Capybara::Screenshot.autosave_on_failure = true From f55f949b58d8a2c791f0ddd3ee545dbe666dd171 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 7 Aug 2018 14:11:55 +0200 Subject: [PATCH 2/4] admin: disable fade on publish modal It makes Capybara tests brittle. --- app/views/admin/procedures/_modal_publish.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/admin/procedures/_modal_publish.html.haml b/app/views/admin/procedures/_modal_publish.html.haml index 14ad13e43..dc51848ce 100644 --- a/app/views/admin/procedures/_modal_publish.html.haml +++ b/app/views/admin/procedures/_modal_publish.html.haml @@ -1,4 +1,4 @@ -#publish-modal.modal.fade{ "aria-labelledby" => "myModalLabel", :role => "dialog", :tabindex => "-1" } +#publish-modal.modal{ "aria-labelledby" => "myModalLabel", :role => "dialog", :tabindex => "-1" } .modal-dialog.modal-lg{ :role => "document" } = form_tag admin_procedure_publish_path(procedure_id: @procedure.id), method: :put, remote: true do .modal-content From cc15b0bb28290f2398a867776a72369e29c0ef4d Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 7 Aug 2018 14:13:59 +0200 Subject: [PATCH 3/4] specs: make checkbox click cleaner --- spec/features/users/dossier_creation_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/features/users/dossier_creation_spec.rb b/spec/features/users/dossier_creation_spec.rb index 890d82427..504e0d007 100644 --- a/spec/features/users/dossier_creation_spec.rb +++ b/spec/features/users/dossier_creation_spec.rb @@ -81,7 +81,7 @@ feature 'As a User I wanna create a dossier' do wait_for_ajax expect(page).to have_css('#recap-info-entreprise') - find(:css, "#dossier_autorisation_donnees[value='1']").set(true) + check 'dossier_autorisation_donnees' page.find_by_id('etape_suivante').click expect(page).to have_current_path(users_dossier_carte_path(procedure_with_siret.dossiers.last.id.to_s)) page.find_by_id('etape_suivante').click From 93ba063612de391b3896c22e145c602c249d7084 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 7 Aug 2018 12:12:32 +0000 Subject: [PATCH 4/4] specs: improve reliability of procedure creation features The 'etape_suivante' button is sometimes not activated, and it could be because the event handler on the checkbox sometimes doesn't run. --- .../features/admin/procedure_creation_spec.rb | 102 ++++++++++-------- 1 file changed, 57 insertions(+), 45 deletions(-) diff --git a/spec/features/admin/procedure_creation_spec.rb b/spec/features/admin/procedure_creation_spec.rb index 8fa654aa2..3c410d020 100644 --- a/spec/features/admin/procedure_creation_spec.rb +++ b/spec/features/admin/procedure_creation_spec.rb @@ -13,95 +13,107 @@ feature 'As an administrateur I wanna create a new procedure', js: true do context 'Right after sign_in I shall see all procedure states links' do scenario 'Finding draft procedures' do - page.find_by_id('draft-procedures').click + click_on 'draft-procedures' expect(page).to have_current_path(admin_procedures_draft_path) end scenario 'Finding active procedures' do - page.find_by_id('active-procedures').click + click_on 'active-procedures' expect(page).to have_current_path(admin_procedures_path) end scenario 'Finding archived procedures' do - page.find_by_id('archived-procedures').click + click_on 'archived-procedures' expect(page).to have_current_path(admin_procedures_archived_path) end end context 'Creating a new procedure' do - scenario 'Finding new procedure link' do - page.find_by_id('new-procedure').click - page.find_by_id('from-scratch').click - expect(page).to have_current_path(new_admin_procedure_path) - end - scenario 'Finding save button for new procedure, libelle, description and cadre_juridique required' do - page.find_by_id('new-procedure').click - page.find_by_id('from-scratch').click + expect(page).to have_selector('#new-procedure') + find('#new-procedure').click + click_on 'from-scratch' + + expect(page).to have_current_path(new_admin_procedure_path) fill_in 'procedure_duree_conservation_dossiers_dans_ds', with: '3' fill_in 'procedure_duree_conservation_dossiers_hors_ds', with: '6' - page.find_by_id('save-procedure').click - page.find_by_id('flash_message').visible? + click_on 'save-procedure' + + expect(page).to have_text('Libelle doit être rempli') fill_in_dummy_procedure_details - page.find_by_id('save-procedure').click - expect(page).to have_current_path(admin_procedure_types_de_champ_path(Procedure.first.id.to_s)) + click_on 'save-procedure' + + expect(page).to have_current_path(admin_procedure_types_de_champ_path(Procedure.first)) end end context 'Editing a new procedure' do before 'Create procedure' do - page.find_by_id('new-procedure').click - page.find_by_id('from-scratch').click + expect(page).to have_selector('#new-procedure') + find('#new-procedure').click + click_on 'from-scratch' + + expect(page).to have_current_path(new_admin_procedure_path) fill_in_dummy_procedure_details - page.find_by_id('save-procedure').click + click_on 'save-procedure' procedure = Procedure.last procedure.update(service: create(:service)) end scenario 'Add champ, add file, visualize them in procedure preview' do - page.find_by_id('procedure_types_de_champ_attributes_0_libelle').set 'libelle de champ' - page.find_by_id('add_type_de_champ').click - page.find_by_id('procedure_types_de_champ_attributes_1_libelle') + fill_in 'procedure_types_de_champ_attributes_0_libelle', with: 'libelle de champ' + click_on 'add_type_de_champ' + expect(page).to have_current_path(admin_procedure_types_de_champ_path(Procedure.first)) + expect(page).to have_selector('#procedure_types_de_champ_attributes_1_libelle') expect(Procedure.first.types_de_champ.first.libelle).to eq('libelle de champ') - page.find_by_id('onglet-pieces').click - expect(page).to have_current_path(admin_procedure_pieces_justificatives_path(Procedure.first.id.to_s)) - page.find_by_id('procedure_types_de_piece_justificative_attributes_0_libelle').set 'libelle de piece' - page.find_by_id('add_piece_justificative').click - page.find_by_id('procedure_types_de_piece_justificative_attributes_1_libelle') + click_on 'onglet-pieces' + expect(page).to have_current_path(admin_procedure_pieces_justificatives_path(Procedure.first)) + fill_in 'procedure_types_de_piece_justificative_attributes_0_libelle', with: 'libelle de piece' + click_on 'add_piece_justificative' + expect(page).to have_current_path(admin_procedure_pieces_justificatives_path(Procedure.first)) + expect(page).to have_selector('#procedure_types_de_piece_justificative_attributes_1_libelle') - preview_window = window_opened_by { page.find_by_id('onglet-preview').click } + preview_window = window_opened_by { click_on 'onglet-preview' } within_window(preview_window) do expect(page).to have_current_path(apercu_procedure_path(Procedure.first)) - expect(page.find("input[type='text']")['placeholder']).to eq('libelle de champ') - expect(page.first('.pj-input label').text).to eq('libelle de piece') + expect(page).to have_field('libelle de champ') + expect(page).to have_field('libelle de piece') end end scenario 'After adding champ and file, check impossibility to publish procedure, add accompagnateur and make publication' do - page.find_by_id('procedure_types_de_champ_attributes_0_libelle').set 'libelle de champ' - page.find_by_id('add_type_de_champ').click - page.find_by_id('onglet-pieces').click - page.find_by_id('procedure_types_de_piece_justificative_attributes_0_libelle').set 'libelle de piece' - page.find_by_id('add_piece_justificative').click + fill_in 'procedure_types_de_champ_attributes_0_libelle', with: 'libelle de champ' + click_on 'add_type_de_champ' + click_on 'onglet-pieces' - page.find_by_id('onglet-infos').click - expect(page).to have_current_path(admin_procedure_path(Procedure.first.id.to_s)) - expect(page.find_by_id('publish-procedure')['disabled']).to eq('true') + expect(page).to have_current_path(admin_procedure_pieces_justificatives_path(Procedure.first)) + fill_in 'procedure_types_de_piece_justificative_attributes_0_libelle', with: 'libelle de piece' + click_on 'add_piece_justificative' - page.find_by_id('onglet-accompagnateurs').click - expect(page).to have_current_path(admin_procedure_accompagnateurs_path(Procedure.first.id.to_s)) - page.find_by_id('gestionnaire_email').set 'gestionnaire@apientreprise.fr' - page.find_by_id('add-gestionnaire-email').click + click_on 'onglet-infos' + expect(page).to have_current_path(admin_procedure_path(Procedure.first)) + expect(page).to have_selector('#publish-procedure') + expect(page.find_by_id('publish-procedure')[:disabled]).to eq('true') + + click_on 'onglet-accompagnateurs' + expect(page).to have_current_path(admin_procedure_accompagnateurs_path(Procedure.first)) + fill_in 'gestionnaire_email', with: 'gestionnaire@apientreprise.fr' + click_on 'add-gestionnaire-email' page.first('.gestionnaire-affectation').click - page.find_by_id('onglet-infos').click + click_on 'onglet-infos' + expect(page).to have_current_path(admin_procedure_path(Procedure.first)) expect(page).to have_selector('#publish-procedure', visible: true) - page.find_by_id('publish-procedure').click + find('#publish-procedure').click - expect(page.find_by_id('procedure_path')['value']).to eq('libelle-de-la-procedure') - page.find_by_id('publish').click + within '#publish-modal' do + expect(page).to have_field('procedure_path', with: 'libelle-de-la-procedure') + click_on 'publish' + end + + expect(page).to have_text('Procédure publiée') expect(page).to have_selector('.procedure-lien') end end