From 0ef4a5253ce40c9dc64d924dfce815c2d5d1781f Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 26 Nov 2019 14:05:33 +0000 Subject: [PATCH 1/5] features: move feature matchers to their own file This allows to have the same syntax than native Capybara matchers. --- spec/features/sessions/sign_in_spec.rb | 4 ++-- spec/features/users/dossier_creation_spec.rb | 6 +++--- spec/features/users/sign_up_spec.rb | 4 ++-- spec/support/feature_helpers.rb | 8 -------- spec/support/feature_matchers.rb | 9 +++++++++ 5 files changed, 16 insertions(+), 15 deletions(-) create mode 100644 spec/support/feature_matchers.rb diff --git a/spec/features/sessions/sign_in_spec.rb b/spec/features/sessions/sign_in_spec.rb index 958c3b7c2..25ddf3c55 100644 --- a/spec/features/sessions/sign_in_spec.rb +++ b/spec/features/sessions/sign_in_spec.rb @@ -34,7 +34,7 @@ feature 'Signin in:' do scenario 'an existing user can sign-in and fill the procedure' do click_on 'J’ai déjà un compte' expect(page).to have_current_path new_user_session_path - expect_page_to_have_procedure_description(procedure) + expect(page).to have_procedure_description(procedure) sign_in_with user.email, password @@ -42,7 +42,7 @@ feature 'Signin in:' do click_on 'Commencer la démarche' expect(page).to have_current_path identite_dossier_path(user.reload.dossiers.last) - expect_page_to_have_procedure_description(procedure) + expect(page).to have_procedure_description(procedure) expect(page).to have_content "Données d'identité" end end diff --git a/spec/features/users/dossier_creation_spec.rb b/spec/features/users/dossier_creation_spec.rb index 682a19fe4..f6dc8de5b 100644 --- a/spec/features/users/dossier_creation_spec.rb +++ b/spec/features/users/dossier_creation_spec.rb @@ -20,7 +20,7 @@ feature 'Creating a new dossier:' do click_on 'Commencer la démarche' expect(page).to have_current_path identite_dossier_path(user.reload.dossiers.last) - expect_page_to_have_procedure_description(procedure) + expect(page).to have_procedure_description(procedure) fill_in 'individual_nom', with: 'Nom' fill_in 'individual_prenom', with: 'Prenom' @@ -82,7 +82,7 @@ feature 'Creating a new dossier:' do click_on 'Commencer la démarche' expect(page).to have_current_path siret_dossier_path(dossier) - expect_page_to_have_procedure_description(procedure) + expect(page).to have_procedure_description(procedure) fill_in 'Numéro SIRET', with: siret click_on 'Valider' @@ -99,7 +99,7 @@ feature 'Creating a new dossier:' do click_on 'Commencer la démarche' expect(page).to have_current_path(siret_dossier_path(dossier)) - expect_page_to_have_procedure_description(procedure) + expect(page).to have_procedure_description(procedure) fill_in 'Numéro SIRET', with: '0000' click_on 'Valider' diff --git a/spec/features/users/sign_up_spec.rb b/spec/features/users/sign_up_spec.rb index 72da33bcd..06eb1d831 100644 --- a/spec/features/users/sign_up_spec.rb +++ b/spec/features/users/sign_up_spec.rb @@ -42,7 +42,7 @@ feature 'Signing up:' do scenario 'a new user can sign-up and fill the procedure' do click_on 'Créer un compte' expect(page).to have_current_path new_user_registration_path - expect_page_to_have_procedure_description(procedure) + expect(page).to have_procedure_description(procedure) sign_up_with user_email, user_password expect(page).to have_content "nous avons besoin de vérifier votre adresse #{user_email}" @@ -54,7 +54,7 @@ feature 'Signing up:' do click_on 'Commencer la démarche' expect(page).to have_current_path identite_dossier_path(procedure.reload.dossiers.last) - expect_page_to_have_procedure_description(procedure) + expect(page).to have_procedure_description(procedure) end end diff --git a/spec/support/feature_helpers.rb b/spec/support/feature_helpers.rb index 4282db2ea..9e26b7d0d 100644 --- a/spec/support/feature_helpers.rb +++ b/spec/support/feature_helpers.rb @@ -55,14 +55,6 @@ module FeatureHelpers visit "/users/confirmation?#{token_params}" end - def expect_page_to_have_procedure_description(procedure) - # Procedure context on the page - expect(page).to have_content(procedure.libelle) - expect(page).to have_content(procedure.description) - # Procedure contact infos in the footer - expect(page).to have_content(procedure.service.email) - end - def click_reset_password_link_for(email) reset_password_email = open_email(email) token_params = reset_password_email.body.match(/reset_password_token=[^"]+/) diff --git a/spec/support/feature_matchers.rb b/spec/support/feature_matchers.rb new file mode 100644 index 000000000..b61c8beee --- /dev/null +++ b/spec/support/feature_matchers.rb @@ -0,0 +1,9 @@ +module Capybara + class Session + # Find the description of a procedure on the page + # Usage: expect(page).to have_procedure_description(procedure) + def has_procedure_description?(procedure) + has_content?(procedure.libelle) && has_content?(procedure.description) && has_content?(procedure.service.email) + end + end +end From d0cd875e910691f09c58d13fb51e69fc2c281cd7 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 26 Nov 2019 15:30:45 +0000 Subject: [PATCH 2/5] features: add a `leave_browser_open` helper --- spec/support/feature_helpers.rb | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/spec/support/feature_helpers.rb b/spec/support/feature_helpers.rb index 9e26b7d0d..4602dbf4d 100644 --- a/spec/support/feature_helpers.rb +++ b/spec/support/feature_helpers.rb @@ -77,6 +77,32 @@ module FeatureHelpers value end end + + # Keep the brower window open after a test success of failure, to + # allow inspecting the page or the console. + # + # Usage: + # 1. Disable the 'headless' mode in `spec_helper.rb` + # 2. Call `leave_browser_open` at the beginning of your scenario + def leave_browser_open + Selenium::WebDriver::Chrome::Service.class_eval do + def stop + STDOUT.puts "#{self.class}#stop is a no-op, because leave_browser_open is enabled" + end + end + + Selenium::WebDriver::Driver.class_eval do + def quit + STDOUT.puts "#{self.class}#quit is a no-op, because leave_browser_open is enabled" + end + end + + Capybara::Selenium::Driver.class_eval do + def reset! + STDOUT.puts "#{self.class}#reset! is a no-op, because leave_browser_open is enabled" + end + end + end end RSpec.configure do |config| From 7ed649dfcae975658dad81dbc97269ff85af0f7f Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 26 Nov 2019 16:57:03 +0100 Subject: [PATCH 3/5] editor: don't create a champ by default Before the editor attempted to create a default champ as soon as the list became empty. This created many race conditions, which made the tests flaky. Remove this behavior, and add an empty label instead. --- .../components/TypeDeChamps.js | 14 +++++----- .../components/TypesDeChampEditor/index.js | 10 ++++++- .../TypesDeChampEditor/typeDeChampsReducer.js | 27 ++++++------------- 3 files changed, 24 insertions(+), 27 deletions(-) diff --git a/app/javascript/components/TypesDeChampEditor/components/TypeDeChamps.js b/app/javascript/components/TypesDeChampEditor/components/TypeDeChamps.js index 13ba32302..104ca2fa2 100644 --- a/app/javascript/components/TypesDeChampEditor/components/TypeDeChamps.js +++ b/app/javascript/components/TypesDeChampEditor/components/TypeDeChamps.js @@ -12,13 +12,6 @@ function TypeDeChamps({ state: rootState, typeDeChamps }) { typeDeChamps }); - if (state.typeDeChamps.length === 0) { - dispatch({ - type: 'addFirstTypeDeChamp', - done: () => dispatch({ type: 'refresh' }) - }); - } - return (
))} + {state.typeDeChamps.length === 0 && ( +

+ +   Cliquez sur le bouton « Ajouter un champ » pour + créer votre premier champ. +

+ )}