dossier spec: extract the dossier edition behaviors to a shared spec

This will allow to test behavior for invited users.
This commit is contained in:
Pierre de La Morinerie 2018-09-24 14:25:34 +00:00
parent df2bbba201
commit c534a9a792
2 changed files with 45 additions and 35 deletions

View file

@ -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é à lusager') }
let(:message_body) { 'Message envoyé à linstructeur' }
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

View file

@ -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é à lusager') }
let(:message_body) { 'Message envoyé à linstructeur' }
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