2023-03-06 15:51:08 +01:00
|
|
|
|
describe 'users/dossiers/index', type: :view do
|
2018-06-20 15:29:52 +02:00
|
|
|
|
let(:user) { create(:user) }
|
2024-03-27 11:44:35 +01:00
|
|
|
|
let(:procedure_accuse_lecture) { create(:procedure, :accuse_lecture) }
|
2018-08-28 14:10:55 +02:00
|
|
|
|
let(:dossier_brouillon) { create(:dossier, state: Dossier.states.fetch(:brouillon), user: user) }
|
|
|
|
|
let(:dossier_en_construction) { create(:dossier, state: Dossier.states.fetch(:en_construction), user: user) }
|
2024-03-27 11:44:35 +01:00
|
|
|
|
let(:dossier_en_construction_with_accuse_lecture) { create(:dossier, state: Dossier.states.fetch(:en_construction), user: user, procedure: procedure_accuse_lecture) }
|
2021-11-10 17:36:42 +01:00
|
|
|
|
let(:dossier_termine) { create(:dossier, state: Dossier.states.fetch(:accepte), user: user) }
|
2024-03-27 11:44:35 +01:00
|
|
|
|
let(:dossier_termine_with_accuse_lecture) { create(:dossier, state: Dossier.states.fetch(:accepte), user: user, procedure: procedure_accuse_lecture) }
|
2018-06-20 15:29:52 +02:00
|
|
|
|
let(:dossiers_invites) { [] }
|
2024-03-27 11:44:35 +01:00
|
|
|
|
let(:user_dossiers) { Kaminari.paginate_array([dossier_brouillon, dossier_en_construction, dossier_termine, dossier_en_construction_with_accuse_lecture, dossier_termine_with_accuse_lecture]).page(1) }
|
2021-11-10 17:36:42 +01:00
|
|
|
|
let(:statut) { 'en-cours' }
|
2023-05-02 19:24:30 +02:00
|
|
|
|
let(:filter) { DossiersFilter.new(user, ActionController::Parameters.new(random_param: 'random_param')) }
|
2018-06-20 15:29:52 +02:00
|
|
|
|
|
2023-11-30 15:37:18 +01:00
|
|
|
|
before do |config|
|
2018-06-26 18:04:04 +02:00
|
|
|
|
allow(view).to receive(:new_demarche_url).and_return('#')
|
2018-08-08 17:37:41 +02:00
|
|
|
|
allow(controller).to receive(:current_user) { user }
|
2023-11-30 15:37:18 +01:00
|
|
|
|
assign(:user_dossiers, user_dossiers)
|
2018-06-20 15:29:52 +02:00
|
|
|
|
assign(:dossiers_invites, Kaminari.paginate_array(dossiers_invites).page(1))
|
2022-01-05 10:43:20 +01:00
|
|
|
|
assign(:dossiers_supprimes_recemment, Kaminari.paginate_array(user_dossiers).page(1))
|
|
|
|
|
assign(:dossiers_supprimes_definitivement, Kaminari.paginate_array(user_dossiers).page(1))
|
2021-11-10 17:36:42 +01:00
|
|
|
|
assign(:dossiers_traites, Kaminari.paginate_array(user_dossiers).page(1))
|
2023-06-28 11:53:41 +02:00
|
|
|
|
assign(:dossier_transferes, Kaminari.paginate_array([]).page(1))
|
2021-11-19 15:53:15 +01:00
|
|
|
|
assign(:dossiers_close_to_expiration, Kaminari.paginate_array([]).page(1))
|
2023-04-27 15:26:10 +02:00
|
|
|
|
assign(:dossiers, Kaminari.paginate_array(user_dossiers).page(1))
|
2023-12-13 16:00:43 +01:00
|
|
|
|
assign(:procedures_for_select, user_dossiers.map(&:procedure))
|
2020-11-17 13:25:35 +01:00
|
|
|
|
assign(:statut, statut)
|
2023-05-02 19:24:30 +02:00
|
|
|
|
assign(:filter, filter)
|
2023-07-20 16:56:59 +02:00
|
|
|
|
assign(:all_dossiers_uniq_procedures_count, 0)
|
2023-11-30 15:37:18 +01:00
|
|
|
|
|
|
|
|
|
render if !config.metadata[:caching]
|
2018-06-20 15:29:52 +02:00
|
|
|
|
end
|
|
|
|
|
|
2023-06-28 12:48:47 +02:00
|
|
|
|
it 'affiche les dossiers' do
|
2024-03-27 11:44:35 +01:00
|
|
|
|
expect(rendered).to have_selector('.card', count: 5)
|
2018-06-20 15:29:52 +02:00
|
|
|
|
end
|
|
|
|
|
|
2018-06-25 13:34:48 +02:00
|
|
|
|
it 'affiche les informations des dossiers' do
|
|
|
|
|
dossier = user_dossiers.first
|
2019-11-28 12:09:12 +01:00
|
|
|
|
expect(rendered).to have_text(dossier_brouillon.id.to_s)
|
2018-06-28 17:19:22 +02:00
|
|
|
|
expect(rendered).to have_text(dossier_brouillon.procedure.libelle)
|
2023-06-28 12:48:47 +02:00
|
|
|
|
expect(rendered).to have_link(dossier_brouillon.procedure.libelle, href: brouillon_dossier_path(dossier_brouillon))
|
2018-06-28 17:19:22 +02:00
|
|
|
|
|
2019-11-28 12:09:12 +01:00
|
|
|
|
expect(rendered).to have_text(dossier_en_construction.id.to_s)
|
2018-06-28 17:19:22 +02:00
|
|
|
|
expect(rendered).to have_text(dossier_en_construction.procedure.libelle)
|
2023-06-28 12:48:47 +02:00
|
|
|
|
expect(rendered).to have_link(dossier_en_construction.procedure.libelle, href: dossier_path(dossier_en_construction))
|
2024-03-27 11:44:35 +01:00
|
|
|
|
|
|
|
|
|
expect(rendered).to have_selector('.fr-badge', text: 'traité', count: 1)
|
|
|
|
|
expect(rendered).to have_selector('.fr-badge', text: 'en construction', count: 2)
|
2018-06-25 13:34:48 +02:00
|
|
|
|
end
|
|
|
|
|
|
2023-04-11 15:50:17 +02:00
|
|
|
|
it 'n’affiche pas une alerte pour continuer à remplir un dossier' do
|
|
|
|
|
expect(rendered).not_to have_selector('.fr-callout', count: 1)
|
|
|
|
|
end
|
|
|
|
|
|
2023-04-18 12:03:10 +02:00
|
|
|
|
context 'quand il y a un dossier en brouillon récemment mis à jour' do
|
2023-04-11 15:50:17 +02:00
|
|
|
|
before do
|
2023-04-18 12:03:10 +02:00
|
|
|
|
assign(:first_brouillon_recently_updated, dossier_brouillon)
|
2023-04-11 15:50:17 +02:00
|
|
|
|
render
|
|
|
|
|
end
|
|
|
|
|
it 'affiche une alerte pour continuer à remplir un dossier' do
|
|
|
|
|
expect(rendered).to have_selector('.fr-callout', count: 1)
|
2023-04-26 16:54:50 +02:00
|
|
|
|
expect(rendered).to have_link(href: brouillon_dossier_path(dossier_brouillon))
|
2023-04-11 15:50:17 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2018-06-25 15:14:22 +02:00
|
|
|
|
context 'quand il n’y a aucun dossier' do
|
2023-11-30 15:37:18 +01:00
|
|
|
|
let(:user_dossiers) { [] }
|
2018-06-25 15:14:22 +02:00
|
|
|
|
let(:dossiers_invites) { [] }
|
|
|
|
|
|
|
|
|
|
it 'n’affiche pas la table' do
|
|
|
|
|
expect(rendered).not_to have_selector('.dossiers-table')
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'affiche un message' do
|
|
|
|
|
expect(rendered).to have_text('Aucun dossier')
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2018-06-20 15:29:52 +02:00
|
|
|
|
context 'quand il n’y a pas de dossiers invités' do
|
|
|
|
|
let(:dossiers_invites) { [] }
|
|
|
|
|
|
|
|
|
|
it 'affiche un titre adapté' do
|
2023-04-11 15:50:17 +02:00
|
|
|
|
expect(rendered).to have_selector('h1', text: 'Mes dossiers')
|
2018-06-20 15:29:52 +02:00
|
|
|
|
end
|
|
|
|
|
|
2020-11-17 13:25:35 +01:00
|
|
|
|
it 'n’affiche la barre d’onglets' do
|
2023-11-09 15:02:43 +01:00
|
|
|
|
expect(rendered).to have_selector('nav.fr-tabs')
|
2018-06-20 15:29:52 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2018-06-25 15:14:22 +02:00
|
|
|
|
context 'quand il y a des dossiers invités' do
|
2018-06-20 15:29:52 +02:00
|
|
|
|
let(:dossiers_invites) { create_list(:dossier, 1) }
|
|
|
|
|
|
|
|
|
|
it 'affiche un titre adapté' do
|
2023-04-11 15:50:17 +02:00
|
|
|
|
expect(rendered).to have_selector('h1', text: 'Mes dossiers')
|
2018-06-20 15:29:52 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'affiche la barre d’onglets' do
|
2023-11-09 15:02:43 +01:00
|
|
|
|
expect(rendered).to have_selector('nav.fr-tabs')
|
|
|
|
|
expect(rendered).to have_selector('nav.fr-tabs li', count: 5)
|
|
|
|
|
expect(rendered).to have_selector('nav.fr-tabs li.active', count: 1)
|
2018-06-20 15:29:52 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
2021-11-10 17:36:42 +01:00
|
|
|
|
|
|
|
|
|
context 'where there is a traite dossier' do
|
|
|
|
|
let(:dossiers_traites) { create_list(:dossier, 1) }
|
|
|
|
|
|
|
|
|
|
it "displays the hide by user at button" do
|
|
|
|
|
expect(rendered).to have_text("Supprimer le dossier")
|
|
|
|
|
end
|
|
|
|
|
end
|
2023-11-30 15:37:18 +01:00
|
|
|
|
|
|
|
|
|
context 'caching', caching: true do
|
|
|
|
|
it "works" do
|
|
|
|
|
expect(user_dossiers).to receive(:present?).once
|
|
|
|
|
2.times { render; user.reload }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "cache key depends on statut" do
|
|
|
|
|
expect(user_dossiers).to receive(:present?).twice
|
|
|
|
|
render
|
|
|
|
|
|
|
|
|
|
assign(:statut, "termines")
|
|
|
|
|
user.reload
|
|
|
|
|
|
|
|
|
|
render
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "cache key depends on dossier updated_at" do
|
|
|
|
|
expect(user_dossiers).to receive(:present?).twice
|
|
|
|
|
render
|
|
|
|
|
|
|
|
|
|
dossier_termine.touch
|
|
|
|
|
user.reload
|
|
|
|
|
|
|
|
|
|
render
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "cache key depends on dossiers list" do
|
|
|
|
|
render
|
2024-03-27 11:44:35 +01:00
|
|
|
|
expect(rendered).to have_text(/5\s+en cours/)
|
2023-11-30 15:37:18 +01:00
|
|
|
|
|
|
|
|
|
assign(:user_dossiers, Kaminari.paginate_array(user_dossiers.concat([create(:dossier, :en_construction, user: user)])).page(1))
|
|
|
|
|
user.reload
|
|
|
|
|
|
|
|
|
|
render
|
2024-03-27 11:44:35 +01:00
|
|
|
|
expect(rendered).to have_text(/6\s+en cours/)
|
2023-11-30 15:37:18 +01:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "cache key dpeends on dossier invites" do
|
|
|
|
|
expect(user_dossiers).to receive(:present?).twice
|
|
|
|
|
render
|
|
|
|
|
|
|
|
|
|
create(:invite, user:)
|
|
|
|
|
user.reload
|
|
|
|
|
|
|
|
|
|
render
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "cache key depends on dossier deletion" do
|
|
|
|
|
expect(user_dossiers).to receive(:present?).twice
|
|
|
|
|
render
|
|
|
|
|
|
|
|
|
|
dossier_termine.expired_keep_track_and_destroy!
|
|
|
|
|
user.reload
|
|
|
|
|
|
|
|
|
|
render
|
|
|
|
|
end
|
|
|
|
|
end
|
2018-06-20 15:29:52 +02:00
|
|
|
|
end
|