From 2b2dbcb112806a225e68af09441e7da7872b23da Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 25 Sep 2018 09:24:41 +0000 Subject: [PATCH 1/7] dossier spec: move visit_dossier to a `before` block --- .../features/new_user/dossier_details_spec.rb | 21 +++++++------------ 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/spec/features/new_user/dossier_details_spec.rb b/spec/features/new_user/dossier_details_spec.rb index fb62483bf..32efd9729 100644 --- a/spec/features/new_user/dossier_details_spec.rb +++ b/spec/features/new_user/dossier_details_spec.rb @@ -8,11 +8,10 @@ describe 'Dossier details:' do before do Flipflop::FeatureSet.current.test!.switch!(:new_dossier_details, true) + visit_dossier dossier end scenario 'the user can see the summary of the dossier status' do - visit_dossier dossier - expect(page).to have_current_path(dossier_path(dossier)) expect(page).to have_content(dossier.id) expect(page).to have_selector('.status-explanation') @@ -20,30 +19,24 @@ describe 'Dossier details:' do end describe "the user can see the mean time they are expected to wait" do - context "the dossier is in construction" do + context "when the dossier is in construction" do before do other_dossier = create(:dossier, :accepte, :for_individual, procedure: simple_procedure, en_construction_at: 10.days.ago, en_instruction_at: Time.now) + visit dossier_path(dossier) end - it "show the proper wait time" do - visit_dossier dossier - - expect(page).to have_text("Le temps moyen de vérification pour cette démarche est de 10 jours.") - end + it { expect(page).to have_text("Le temps moyen de vérification pour cette démarche est de 10 jours.") } end - context "the dossier is in instruction" do + context "when the dossier is in instruction" do let(:dossier) { create(:dossier, :en_instruction, :for_individual, :with_commentaires, user: user, procedure: simple_procedure) } before do other_dossier = create(:dossier, :accepte, :for_individual, procedure: simple_procedure, en_instruction_at: 2.months.ago, processed_at: Time.now) + visit dossier_path(dossier) end - it "show the proper wait time" do - visit_dossier dossier - - expect(page).to have_text("Le temps moyen d’instruction pour cette démarche est de 2 mois.") - end + it { expect(page).to have_text("Le temps moyen d’instruction pour cette démarche est de 2 mois.") } end end From df2bbba201cc88daf4ab8b85c487e6cce1e6a745 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Mon, 24 Sep 2018 13:54:46 +0000 Subject: [PATCH 2/7] dossier spec: create a `simple_procedure` factory --- spec/factories/procedure.rb | 8 ++++++++ spec/features/new_user/dossier_details_spec.rb | 13 +++++-------- spec/features/new_user/invite_spec.rb | 12 ++++++------ 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/spec/factories/procedure.rb b/spec/factories/procedure.rb index 182103e72..2f548163d 100644 --- a/spec/factories/procedure.rb +++ b/spec/factories/procedure.rb @@ -22,6 +22,14 @@ FactoryBot.define do end end + factory :simple_procedure do + after(:build) do |procedure, _evaluator| + procedure.for_individual = true + procedure.types_de_champ << create(:type_de_champ, libelle: 'Texte obligatoire', mandatory: true) + procedure.publish!(generate(:published_path)) + end + end + after(:build) do |procedure, _evaluator| if procedure.module_api_carto.nil? module_api_carto = create(:module_api_carto) diff --git a/spec/features/new_user/dossier_details_spec.rb b/spec/features/new_user/dossier_details_spec.rb index 32efd9729..5ac0f53a1 100644 --- a/spec/features/new_user/dossier_details_spec.rb +++ b/spec/features/new_user/dossier_details_spec.rb @@ -1,10 +1,7 @@ describe 'Dossier details:' do let(:user) { create(:user) } - let(:simple_procedure) do - tdcs = [create(:type_de_champ, libelle: 'texte obligatoire')] - create(:procedure, :published, :for_individual, types_de_champ: tdcs) - end - let(:dossier) { create(:dossier, :en_construction, :for_individual, :with_commentaires, user: user, procedure: simple_procedure) } + let(:procedure) { create(:simple_procedure) } + let(:dossier) { create(:dossier, :en_construction, :for_individual, :with_commentaires, user: user, procedure: procedure) } before do Flipflop::FeatureSet.current.test!.switch!(:new_dossier_details, true) @@ -21,7 +18,7 @@ describe 'Dossier details:' do describe "the user can see the mean time they are expected to wait" do context "when the dossier is in construction" do before do - other_dossier = create(:dossier, :accepte, :for_individual, procedure: simple_procedure, en_construction_at: 10.days.ago, en_instruction_at: Time.now) + other_dossier = create(:dossier, :accepte, :for_individual, procedure: procedure, en_construction_at: 10.days.ago, en_instruction_at: Time.now) visit dossier_path(dossier) end @@ -29,10 +26,10 @@ describe 'Dossier details:' do end context "when the dossier is in instruction" do - let(:dossier) { create(:dossier, :en_instruction, :for_individual, :with_commentaires, user: user, procedure: simple_procedure) } + let(:dossier) { create(:dossier, :en_instruction, :for_individual, :with_commentaires, user: user, procedure: procedure) } before do - other_dossier = create(:dossier, :accepte, :for_individual, procedure: simple_procedure, en_instruction_at: 2.months.ago, processed_at: Time.now) + other_dossier = create(:dossier, :accepte, :for_individual, procedure: procedure, en_instruction_at: 2.months.ago, processed_at: Time.now) visit dossier_path(dossier) end diff --git a/spec/features/new_user/invite_spec.rb b/spec/features/new_user/invite_spec.rb index 08c4d6385..fd1950f69 100644 --- a/spec/features/new_user/invite_spec.rb +++ b/spec/features/new_user/invite_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' feature 'Invitations' do let(:user) { create(:user) } let(:invited_user) { create(:user, email: 'user_invite@exemple.fr') } - let(:procedure) { create(:procedure, :published, :with_type_de_champ) } + let(:procedure) { create(:simple_procedure) } let(:invite) { create(:invite_user, user: invited_user, dossier: dossier) } context 'when the dossier is a brouillon' do @@ -13,7 +13,7 @@ feature 'Invitations' do log_in(user) navigate_to_brouillon(dossier) - fill_in 'Libelle du champ', with: 'Some edited value' + fill_in 'Texte obligatoire', with: 'Some edited value' send_invite_to "user_invite@exemple.fr" expect(page).to have_current_path(brouillon_dossier_path(dossier)) @@ -21,7 +21,7 @@ feature 'Invitations' do expect(page).to have_text("user_invite@exemple.fr") # Ensure unsaved edits to the form are not lost - expect(page).to have_field('Libelle du champ', with: 'Some edited value') + expect(page).to have_field('Texte obligatoire', with: 'Some edited value') end context 'when inviting someone without an existing account' do @@ -58,10 +58,10 @@ feature 'Invitations' do expect(page).to have_current_path(brouillon_dossier_path(dossier)) expect(page).to have_no_selector('.button.invite-user-action') - fill_in 'Libelle du champ', with: 'Some edited value' + fill_in 'Texte obligatoire', with: 'Some edited value' click_button 'Enregistrer le brouillon' expect(page).to have_text('Votre brouillon a bien été sauvegardé') - expect(page).to have_field('Libelle du champ', with: 'Some edited value') + expect(page).to have_field('Texte obligatoire', with: 'Some edited value') end scenario 'an invited user cannot submit the draft' do @@ -105,7 +105,7 @@ feature 'Invitations' do visit brouillon_dossier_path(dossier) expect(page).to have_current_path(brouillon_dossier_path(dossier)) - fill_in "Libelle du champ", with: "Some edited value" + fill_in "Texte obligatoire", with: "Some edited value" click_button "Enregistrer les modifications du dossier" expect(page).to have_current_path(users_dossiers_invite_path(invite)) From c534a9a7926744fd491e9d674e052d905984074a Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Mon, 24 Sep 2018 14:25:34 +0000 Subject: [PATCH 3/7] dossier spec: extract the dossier edition behaviors to a shared spec This will allow to test behavior for invited users. --- .../features/new_user/dossier_details_spec.rb | 39 ++---------------- .../new_user/dossier_shared_examples.rb | 41 +++++++++++++++++++ 2 files changed, 45 insertions(+), 35 deletions(-) create mode 100644 spec/features/new_user/dossier_shared_examples.rb diff --git a/spec/features/new_user/dossier_details_spec.rb b/spec/features/new_user/dossier_details_spec.rb index 5ac0f53a1..61218f8be 100644 --- a/spec/features/new_user/dossier_details_spec.rb +++ b/spec/features/new_user/dossier_details_spec.rb @@ -1,3 +1,5 @@ +require 'features/new_user/dossier_shared_examples.rb' + describe 'Dossier details:' do let(:user) { create(:user) } let(:procedure) { create(:simple_procedure) } @@ -37,41 +39,8 @@ describe 'Dossier details:' do end end - scenario 'the user can see and edit dossier before instruction' do - visit_dossier dossier - click_on 'Demande' - - expect(page).to have_current_path(demande_dossier_path(dossier)) - click_on 'Modifier le dossier' - - expect(page).to have_current_path(modifier_dossier_path(dossier)) - fill_in('texte obligatoire', with: 'Nouveau texte') - click_on 'Enregistrer les modifications du dossier' - - expect(page).to have_current_path(demande_dossier_path(dossier)) - expect(page).to have_content('Nouveau texte') - end - - context 'with messages' do - let!(:commentaire) { create(:commentaire, dossier: dossier, email: 'instructeur@exemple.fr', body: 'Message envoyé à l’usager') } - let(:message_body) { 'Message envoyé à l’instructeur' } - - scenario 'the user can send a message' do - visit_dossier dossier - click_on 'Messagerie' - - expect(page).to have_current_path(messagerie_dossier_path(dossier)) - expect(page).to have_content(commentaire.body) - - fill_in 'commentaire_body', with: message_body - click_on 'Envoyer' - - expect(page).to have_current_path(messagerie_dossier_path(dossier)) - expect(page).to have_content('Message envoyé') - expect(page).to have_content(commentaire.body) - expect(page).to have_content(message_body) - end - end + it_behaves_like 'the user can edit the submitted demande' + it_behaves_like 'the user can send messages to the instructeur' private diff --git a/spec/features/new_user/dossier_shared_examples.rb b/spec/features/new_user/dossier_shared_examples.rb new file mode 100644 index 000000000..7ff2b8c4e --- /dev/null +++ b/spec/features/new_user/dossier_shared_examples.rb @@ -0,0 +1,41 @@ +RSpec.shared_examples 'the user can edit the submitted demande' do + scenario js: true do + visit dossier_path(dossier) + + expect(page).to have_current_path(dossier_path(dossier)) + click_on 'Demande' + + expect(page).to have_current_path(demande_dossier_path(dossier)) + click_on 'Modifier le dossier' + + expect(page).to have_current_path(modifier_dossier_path(dossier)) + fill_in('Texte obligatoire', with: 'Nouveau texte') + click_on 'Enregistrer les modifications du dossier' + + expect(page).to have_current_path(demande_dossier_path(dossier)) + expect(page).to have_content('Nouveau texte') + end +end + +RSpec.shared_examples 'the user can send messages to the instructeur' do + let!(:commentaire) { create(:commentaire, dossier: dossier, email: 'instructeur@exemple.fr', body: 'Message envoyé à l’usager') } + let(:message_body) { 'Message envoyé à l’instructeur' } + + scenario js: true do + visit dossier_path(dossier) + + expect(page).to have_current_path(dossier_path(dossier)) + click_on 'Messagerie' + + expect(page).to have_current_path(messagerie_dossier_path(dossier)) + expect(page).to have_content(commentaire.body) + + fill_in 'commentaire_body', with: message_body + click_on 'Envoyer' + + expect(page).to have_current_path(messagerie_dossier_path(dossier)) + expect(page).to have_content('Message envoyé') + expect(page).to have_content(commentaire.body) + expect(page).to have_content(message_body) + end +end From fe4921bf8ec9d3db53a7730beff5573d552fce5f Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Mon, 24 Sep 2018 16:01:59 +0200 Subject: [PATCH 4/7] dossier spec: deprecate the old UI tests --- spec/features/new_user/invite_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/features/new_user/invite_spec.rb b/spec/features/new_user/invite_spec.rb index fd1950f69..7798e1d50 100644 --- a/spec/features/new_user/invite_spec.rb +++ b/spec/features/new_user/invite_spec.rb @@ -76,7 +76,7 @@ feature 'Invitations' do end end - context 'when the dossier is en_construction' do + context 'when the dossier is en_construction (legacy UI)' do let!(:dossier) { create(:dossier, :for_individual, :en_construction, user: user, procedure: procedure) } scenario 'on dossier details, a user can invite another user to collaborate on the dossier', js: true do From 1c7ad4d37bea702d5d71d3c95f3caf66c3291d38 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Mon, 24 Sep 2018 14:10:50 +0000 Subject: [PATCH 5/7] dossier spec: rename `user` to `owner` This makes the distinction between the invited user and the owner clearer. --- spec/features/new_user/invite_spec.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/spec/features/new_user/invite_spec.rb b/spec/features/new_user/invite_spec.rb index 7798e1d50..ea803078b 100644 --- a/spec/features/new_user/invite_spec.rb +++ b/spec/features/new_user/invite_spec.rb @@ -1,16 +1,16 @@ require 'spec_helper' feature 'Invitations' do - let(:user) { create(:user) } + let(:owner) { create(:user) } let(:invited_user) { create(:user, email: 'user_invite@exemple.fr') } let(:procedure) { create(:simple_procedure) } let(:invite) { create(:invite_user, user: invited_user, dossier: dossier) } context 'when the dossier is a brouillon' do - let!(:dossier) { create(:dossier, :for_individual, state: Dossier.states.fetch(:brouillon), user: user, procedure: procedure) } + let!(:dossier) { create(:dossier, :for_individual, state: Dossier.states.fetch(:brouillon), user: owner, procedure: procedure) } - scenario 'on the form, a user can invite another user to collaborate on the dossier', js: true do - log_in(user) + scenario 'on the form, the owner of a dossier can invite another user to collaborate on the dossier', js: true do + log_in(owner) navigate_to_brouillon(dossier) fill_in 'Texte obligatoire', with: 'Some edited value' @@ -77,10 +77,10 @@ feature 'Invitations' do end context 'when the dossier is en_construction (legacy UI)' do - let!(:dossier) { create(:dossier, :for_individual, :en_construction, user: user, procedure: procedure) } + let!(:dossier) { create(:dossier, :for_individual, :en_construction, user: owner, procedure: procedure) } scenario 'on dossier details, a user can invite another user to collaborate on the dossier', js: true do - log_in(user) + log_in(owner) navigate_to_recapitulatif(dossier) legacy_send_invite_to "user_invite@exemple.fr" From 12ee9ba3ce00f6d69367af4a6798d53be4a6a691 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Mon, 24 Sep 2018 16:22:37 +0200 Subject: [PATCH 6/7] dossier spec: add `navigate_to_invited_dossier` helper --- spec/features/new_user/invite_spec.rb | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/spec/features/new_user/invite_spec.rb b/spec/features/new_user/invite_spec.rb index ea803078b..b2c77565c 100644 --- a/spec/features/new_user/invite_spec.rb +++ b/spec/features/new_user/invite_spec.rb @@ -51,11 +51,9 @@ feature 'Invitations' do end scenario 'an invited user can see and edit the draft', js: true do - visit users_dossiers_invite_path(invite) - expect(page).to have_current_path(new_user_session_path) - - submit_login_form(invited_user.email, invited_user.password) + navigate_to_invited_dossier(invite) expect(page).to have_current_path(brouillon_dossier_path(dossier)) + expect(page).to have_no_selector('.button.invite-user-action') fill_in 'Texte obligatoire', with: 'Some edited value' @@ -65,10 +63,7 @@ feature 'Invitations' do end scenario 'an invited user cannot submit the draft' do - visit users_dossiers_invite_path(invite) - expect(page).to have_current_path(new_user_session_path) - - submit_login_form(invited_user.email, invited_user.password) + navigate_to_invited_dossier(invite) expect(page).to have_current_path(brouillon_dossier_path(dossier)) expect(page).to have_button('Soumettre le dossier', disabled: true) @@ -134,6 +129,12 @@ feature 'Invitations' do expect(page).to have_current_path(brouillon_dossier_path(dossier)) end + def navigate_to_invited_dossier(invite) + visit users_dossiers_invite_path(invite) + expect(page).to have_current_path(new_user_session_path) + submit_login_form(invited_user.email, invited_user.password) + end + def navigate_to_recapitulatif(dossier) expect(page).to have_current_path(dossiers_path) click_on(dossier.id) From 8a3f455aa3c5502933dbc42256535cbd3bf53606 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Mon, 24 Sep 2018 16:23:53 +0200 Subject: [PATCH 7/7] dossier spec: test invitation behavior with the new dossier UI --- spec/features/new_user/invite_spec.rb | 36 +++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/spec/features/new_user/invite_spec.rb b/spec/features/new_user/invite_spec.rb index b2c77565c..5eb7143b7 100644 --- a/spec/features/new_user/invite_spec.rb +++ b/spec/features/new_user/invite_spec.rb @@ -1,4 +1,5 @@ require 'spec_helper' +require 'features/new_user/dossier_shared_examples.rb' feature 'Invitations' do let(:owner) { create(:user) } @@ -71,6 +72,35 @@ feature 'Invitations' do end end + context 'when the dossier is en_construction' do + let!(:dossier) { create(:dossier, :for_individual, :en_construction, user: owner, procedure: procedure) } + + before do + Flipflop::FeatureSet.current.test!.switch!(:new_dossier_details, true) + end + + scenario 'on dossier details, the owner of a dossier can invite another user to collaborate on the dossier', js: true do + log_in(owner) + navigate_to_dossier(dossier) + + send_invite_to "user_invite@exemple.fr" + + expect(page).to have_current_path(dossier_path(dossier)) + expect(page).to have_text("Une invitation a été envoyée à user_invite@exemple.fr.") + expect(page).to have_text("user_invite@exemple.fr") + end + + context 'as an invited user' do + before do + navigate_to_invited_dossier(invite) + expect(page).to have_current_path(dossier_path(invite.dossier)) + end + + it_behaves_like 'the user can edit the submitted demande' + it_behaves_like 'the user can send messages to the instructeur' + end + end + context 'when the dossier is en_construction (legacy UI)' do let!(:dossier) { create(:dossier, :for_individual, :en_construction, user: owner, procedure: procedure) } @@ -129,6 +159,12 @@ feature 'Invitations' do expect(page).to have_current_path(brouillon_dossier_path(dossier)) end + def navigate_to_dossier(dossier) + expect(page).to have_current_path(dossiers_path) + click_on(dossier.id) + expect(page).to have_current_path(dossier_path(dossier)) + end + def navigate_to_invited_dossier(invite) visit users_dossiers_invite_path(invite) expect(page).to have_current_path(new_user_session_path)