demarches-normaliennes/spec/features/users/list_dossiers_spec.rb

106 lines
3.3 KiB
Ruby
Raw Normal View History

require 'spec_helper'
describe 'user access to the list of his dossier' do
let(:user) { create(:user) }
let!(:last_updated_dossier) { create(:dossier, :with_entreprise, user: user, state: 'en_construction') }
let!(:dossier1) { create(:dossier, :with_entreprise, user: user, state: 'en_construction') }
let!(:dossier2) { create(:dossier, :with_entreprise) }
let!(:dossier_archived) { create(:dossier, :with_entreprise, user: user, state: 'en_construction') }
let(:dossiers_per_page) { 25 }
2015-11-20 17:50:54 +01:00
before do
@default_per_page = Dossier.default_per_page
Dossier.paginates_per dossiers_per_page
last_updated_dossier.update_column(:updated_at, "19/07/2052 15:35".to_time)
2016-02-01 17:16:00 +01:00
visit new_user_session_path
2017-06-13 17:46:08 +02:00
within('#new_user') do
page.find_by_id('user_email').set user.email
page.find_by_id('user_password').set user.password
page.click_on 'Se connecter'
end
end
after do
Dossier.paginates_per @default_per_page
end
it 'the list of dossier is displayed' do
2016-08-30 11:18:43 +02:00
expect(page).to have_content(dossier1.procedure.libelle)
expect(page).to have_content('en construction')
end
it 'dossiers belonging to other users are not displayed' do
2016-08-30 11:18:43 +02:00
expect(page).not_to have_content(dossier2.procedure.libelle)
end
it 'the list must be ordered by last updated' do
2016-08-30 11:18:43 +02:00
expect(page.body).to match(/#{last_updated_dossier.procedure.libelle}.*#{dossier1.procedure.libelle}/m)
end
it 'should list archived dossiers' do
expect(page).to have_content(dossier_archived.procedure.libelle)
end
2016-11-08 15:13:40 +01:00
context 'when user clicks on a projet in list', js: true do
before do
page.click_on(dossier1.procedure.libelle)
end
scenario 'user is redirected to dossier page' do
expect(page).to have_css('#users-recapitulatif-dossier-show')
end
end
context 'when there is more than one page' do
let(:dossiers_per_page) { 2 }
scenario 'the user can navigate through the other pages', js: true do
page.click_link("Suivant")
expect(page).to have_content(dossier_archived.procedure.libelle)
end
scenario 'the user sees a card asking for feedback' do
expect(page).to have_css('.card.feedback')
expect(page).to have_content(CONTACT_EMAIL)
end
end
describe "recherche" do
context "when the dossier does not exist" do
before do
page.find_by_id('dossier_id').set(10000000)
click_button("Rechercher")
end
it "shows an error message on the dossiers page" do
expect(current_path).to eq(dossiers_path)
expect(page).to have_content("Vous navez pas de dossier avec le nº 10000000.")
end
end
context "when the dossier does not belong to the user" do
before do
page.find_by_id('dossier_id').set(dossier2.id)
click_button("Rechercher")
end
it "shows an error message on the dossiers page" do
expect(current_path).to eq(dossiers_path)
expect(page).to have_content("Vous navez pas de dossier avec le nº #{dossier2.id}.")
end
end
context "when the dossier belongs to the user" do
before do
page.find_by_id('dossier_id').set(dossier1.id)
click_button("Rechercher")
end
it "redirects to the dossier page" do
expect(current_path).to eq(users_dossier_recapitulatif_path(dossier1))
end
end
end
end