2022-08-31 12:44:00 +02:00
|
|
|
|
describe 'user access to the list of their dossiers', js: true do
|
2015-09-23 12:04:57 +02:00
|
|
|
|
let(:user) { create(:user) }
|
2019-02-06 19:12:04 +01:00
|
|
|
|
let!(:dossier_brouillon) { create(:dossier, user: user) }
|
2021-11-03 15:52:53 +01:00
|
|
|
|
let!(:dossier_en_construction) { create(:dossier, :with_populated_champs, :en_construction, user: user) }
|
2019-02-06 19:12:04 +01:00
|
|
|
|
let!(:dossier_en_instruction) { create(:dossier, :en_instruction, user: user) }
|
|
|
|
|
let!(:dossier_archived) { create(:dossier, :en_instruction, :archived, user: user) }
|
2018-06-27 14:47:02 +02:00
|
|
|
|
let(:dossiers_per_page) { 25 }
|
2019-02-06 19:12:04 +01:00
|
|
|
|
let(:last_updated_dossier) { dossier_en_construction }
|
2015-11-20 17:50:54 +01:00
|
|
|
|
|
2015-09-23 12:04:57 +02:00
|
|
|
|
before do
|
2018-06-27 14:47:02 +02:00
|
|
|
|
@default_per_page = Dossier.default_per_page
|
|
|
|
|
Dossier.paginates_per dossiers_per_page
|
|
|
|
|
|
2017-04-12 11:18:28 +02:00
|
|
|
|
last_updated_dossier.update_column(:updated_at, "19/07/2052 15:35".to_time)
|
2016-07-19 16:10:50 +02:00
|
|
|
|
|
2019-02-06 19:12:04 +01:00
|
|
|
|
login_as user, scope: :user
|
|
|
|
|
visit dossiers_path
|
2015-09-23 12:04:57 +02:00
|
|
|
|
end
|
2017-04-12 11:18:28 +02:00
|
|
|
|
|
2018-06-27 14:47:02 +02:00
|
|
|
|
after do
|
|
|
|
|
Dossier.paginates_per @default_per_page
|
|
|
|
|
end
|
|
|
|
|
|
2017-04-12 11:18:28 +02:00
|
|
|
|
it 'the list of dossier is displayed' do
|
2019-02-06 19:12:04 +01:00
|
|
|
|
expect(page).to have_content(dossier_brouillon.procedure.libelle)
|
|
|
|
|
expect(page).to have_content(dossier_en_construction.procedure.libelle)
|
|
|
|
|
expect(page).to have_content(dossier_en_instruction.procedure.libelle)
|
|
|
|
|
expect(page).to have_content(dossier_archived.procedure.libelle)
|
2015-09-23 12:04:57 +02:00
|
|
|
|
end
|
2015-09-25 10:26:50 +02:00
|
|
|
|
|
2018-06-27 14:47:02 +02:00
|
|
|
|
it 'the list must be ordered by last updated' do
|
2019-02-06 19:12:04 +01:00
|
|
|
|
expect(page.body).to match(/#{last_updated_dossier.procedure.libelle}.*#{dossier_en_instruction.procedure.libelle}/m)
|
2015-09-25 10:26:50 +02:00
|
|
|
|
end
|
|
|
|
|
|
2019-02-06 19:12:04 +01:00
|
|
|
|
context 'when there are dossiers from other users' do
|
|
|
|
|
let!(:dossier_other_user) { create(:dossier) }
|
2017-04-12 11:18:28 +02:00
|
|
|
|
|
2019-02-06 19:12:04 +01:00
|
|
|
|
it 'doesn’t display dossiers belonging to other users' do
|
|
|
|
|
expect(page).not_to have_content(dossier_other_user.procedure.libelle)
|
|
|
|
|
end
|
2019-01-16 15:34:38 +01:00
|
|
|
|
end
|
|
|
|
|
|
2019-02-06 19:12:04 +01:00
|
|
|
|
context 'when there is more than one page' do
|
|
|
|
|
let(:dossiers_per_page) { 2 }
|
2019-01-24 16:38:34 +01:00
|
|
|
|
|
2019-02-06 19:12:04 +01:00
|
|
|
|
scenario 'the user can navigate through the other pages' do
|
|
|
|
|
expect(page).not_to have_content(dossier_en_instruction.procedure.libelle)
|
|
|
|
|
page.click_link("Suivant")
|
|
|
|
|
expect(page).to have_content(dossier_en_instruction.procedure.libelle)
|
2019-01-16 15:34:38 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2019-02-06 19:12:04 +01:00
|
|
|
|
context 'when user clicks on a projet in list' do
|
2015-09-24 12:02:59 +02:00
|
|
|
|
before do
|
2019-02-06 19:12:04 +01:00
|
|
|
|
page.click_on(dossier_en_construction.procedure.libelle)
|
2015-09-24 12:02:59 +02:00
|
|
|
|
end
|
2019-02-06 19:12:04 +01:00
|
|
|
|
|
2015-09-24 12:02:59 +02:00
|
|
|
|
scenario 'user is redirected to dossier page' do
|
2019-02-06 19:12:04 +01:00
|
|
|
|
expect(page).to have_current_path(dossier_path(dossier_en_construction))
|
2015-09-24 12:02:59 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
2018-06-27 14:47:02 +02:00
|
|
|
|
|
2019-02-06 19:12:04 +01:00
|
|
|
|
describe 'deletion' do
|
|
|
|
|
it 'should have links to delete dossiers' do
|
2023-04-03 20:00:52 +02:00
|
|
|
|
expect(page).to have_link('Supprimer le dossier', href: dossier_path(dossier_brouillon))
|
|
|
|
|
expect(page).to have_link('Supprimer le dossier', href: dossier_path(dossier_en_construction))
|
|
|
|
|
expect(page).not_to have_link('Supprimer le dossier', href: dossier_path(dossier_en_instruction))
|
2019-02-06 19:12:04 +01:00
|
|
|
|
end
|
2018-06-27 14:47:02 +02:00
|
|
|
|
|
2019-02-06 19:12:04 +01:00
|
|
|
|
context 'when user clicks on delete button', js: true do
|
|
|
|
|
scenario 'the dossier is deleted' do
|
2019-03-26 17:55:40 +01:00
|
|
|
|
within(:css, "tr[data-dossier-id=\"#{dossier_brouillon.id}\"]") do
|
|
|
|
|
click_on 'Actions'
|
|
|
|
|
page.accept_alert('Confirmer la suppression ?') do
|
|
|
|
|
click_on 'Supprimer le dossier'
|
|
|
|
|
end
|
2019-02-06 19:12:04 +01:00
|
|
|
|
end
|
|
|
|
|
|
2021-12-01 11:02:16 +01:00
|
|
|
|
expect(page).to have_content('Votre dossier a bien été supprimé')
|
2019-03-26 17:55:40 +01:00
|
|
|
|
expect(page).not_to have_content(dossier_brouillon.procedure.libelle)
|
2019-02-06 19:12:04 +01:00
|
|
|
|
end
|
2018-06-27 14:47:02 +02:00
|
|
|
|
end
|
2022-11-08 16:26:03 +01:00
|
|
|
|
|
|
|
|
|
describe 'clone' do
|
|
|
|
|
it 'should have links to clone dossiers' do
|
|
|
|
|
expect(page).to have_link(nil, href: clone_dossier_path(dossier_brouillon))
|
|
|
|
|
expect(page).to have_link(nil, href: clone_dossier_path(dossier_en_construction))
|
|
|
|
|
expect(page).to have_link(nil, href: clone_dossier_path(dossier_en_instruction))
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when user clicks on clone button', js: true do
|
|
|
|
|
scenario 'the dossier is deleted' do
|
|
|
|
|
within(:css, "tr[data-dossier-id=\"#{dossier_brouillon.id}\"]") do
|
|
|
|
|
click_on 'Actions'
|
|
|
|
|
click_on 'Dupliquer ce dossier'
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
expect(page).to have_content("Votre dossier a bien été dupliqué. Vous pouvez maintenant le vérifier, l’adapter puis le déposer.")
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2018-06-27 14:47:02 +02:00
|
|
|
|
end
|
2018-07-17 11:40:19 +02:00
|
|
|
|
|
|
|
|
|
describe "recherche" do
|
|
|
|
|
context "when the dossier does not exist" do
|
|
|
|
|
before do
|
2020-04-03 20:19:23 +02:00
|
|
|
|
page.find_by_id('q').set(10000000)
|
2022-08-31 12:44:00 +02:00
|
|
|
|
find('.fr-search-bar .fr-btn').click
|
2018-07-17 11:40:19 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "shows an error message on the dossiers page" do
|
|
|
|
|
expect(current_path).to eq(dossiers_path)
|
2020-04-03 20:19:23 +02:00
|
|
|
|
expect(page).to have_content("Vous n’avez pas de dossiers contenant « 10000000 ».")
|
2018-07-17 11:40:19 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context "when the dossier does not belong to the user" do
|
2019-02-06 19:12:04 +01:00
|
|
|
|
let!(:dossier_other_user) { create(:dossier) }
|
|
|
|
|
|
2018-07-17 11:40:19 +02:00
|
|
|
|
before do
|
2020-04-03 20:19:23 +02:00
|
|
|
|
page.find_by_id('q').set(dossier_other_user.id)
|
2022-08-31 12:44:00 +02:00
|
|
|
|
find('.fr-search-bar .fr-btn').click
|
2018-07-17 11:40:19 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "shows an error message on the dossiers page" do
|
|
|
|
|
expect(current_path).to eq(dossiers_path)
|
2020-04-03 20:19:23 +02:00
|
|
|
|
expect(page).to have_content("Vous n’avez pas de dossiers contenant « #{dossier_other_user.id} ».")
|
2018-07-17 11:40:19 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context "when the dossier belongs to the user" do
|
|
|
|
|
before do
|
2020-04-03 20:19:23 +02:00
|
|
|
|
page.find_by_id('q').set(dossier_en_construction.id)
|
2022-08-31 12:44:00 +02:00
|
|
|
|
find('.fr-search-bar .fr-btn').click
|
2018-07-17 11:40:19 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "redirects to the dossier page" do
|
2019-02-06 19:12:04 +01:00
|
|
|
|
expect(current_path).to eq(dossier_path(dossier_en_construction))
|
2018-07-17 11:40:19 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
2020-04-06 18:06:38 +02:00
|
|
|
|
|
|
|
|
|
context "when user search for something inside the dossier" do
|
2021-11-03 15:52:53 +01:00
|
|
|
|
let(:dossier_en_construction2) { create(:dossier, :with_populated_champs, :en_construction, user: user) }
|
2020-04-06 18:06:38 +02:00
|
|
|
|
before do
|
2022-11-10 22:21:14 +01:00
|
|
|
|
page.find_by_id('q').set(dossier_en_construction.champs_public.first.value)
|
2020-04-06 18:06:38 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when it only matches one dossier' do
|
|
|
|
|
before do
|
2022-08-31 12:44:00 +02:00
|
|
|
|
find('.fr-search-bar .fr-btn').click
|
2020-04-06 18:06:38 +02:00
|
|
|
|
end
|
|
|
|
|
it "redirects to the dossier page" do
|
|
|
|
|
expect(current_path).to eq(dossier_path(dossier_en_construction))
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when it matches multiple dossier' do
|
|
|
|
|
before do
|
2022-11-10 22:21:14 +01:00
|
|
|
|
dossier_en_construction2.champs_public.first.update(value: dossier_en_construction.champs_public.first.value)
|
2022-08-31 12:44:00 +02:00
|
|
|
|
find('.fr-search-bar .fr-btn').click
|
2020-04-06 18:06:38 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "redirects to the search results" do
|
|
|
|
|
expect(current_path).to eq(recherche_dossiers_path)
|
|
|
|
|
expect(page).to have_content(dossier_en_construction.id)
|
|
|
|
|
expect(page).to have_content(dossier_en_construction2.id)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2018-07-17 11:40:19 +02:00
|
|
|
|
end
|
2016-12-13 16:10:03 +01:00
|
|
|
|
end
|