demarches-normaliennes/spec/views/users/dossiers/index.html.haml_spec.rb

105 lines
4 KiB
Ruby
Raw Normal View History

describe 'users/dossiers/index', type: :view do
let(:user) { create(:user) }
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) }
2021-11-10 17:36:42 +01:00
let(:dossier_termine) { create(:dossier, state: Dossier.states.fetch(:accepte), user: user) }
let(:user_dossiers) { [dossier_brouillon, dossier_en_construction, dossier_termine] }
let(:dossiers_invites) { [] }
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')) }
before do
allow(view).to receive(:new_demarche_url).and_return('#')
2018-08-08 17:37:41 +02:00
allow(controller).to receive(:current_user) { user }
assign(:user_dossiers, Kaminari.paginate_array(user_dossiers).page(1))
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))
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))
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)
render
end
2023-06-28 12:48:47 +02:00
it 'affiche les dossiers' do
expect(rendered).to have_selector('.card', count: 3)
end
it 'affiche les informations des dossiers' do
dossier = user_dossiers.first
expect(rendered).to have_text(dossier_brouillon.id.to_s)
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))
expect(rendered).to have_text(dossier_en_construction.id.to_s)
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))
end
it 'naffiche pas une alerte pour continuer à remplir un dossier' do
expect(rendered).not_to have_selector('.fr-callout', count: 1)
end
context 'quand il y a un dossier en brouillon récemment mis à jour' do
before do
assign(:first_brouillon_recently_updated, dossier_brouillon)
render
end
it 'affiche une alerte pour continuer à remplir un dossier' do
expect(rendered).to have_selector('.fr-callout', count: 1)
expect(rendered).to have_link(href: brouillon_dossier_path(dossier_brouillon))
end
end
2018-06-25 15:14:22 +02:00
context 'quand il ny a aucun dossier' do
let(:user_dossiers) { [] }
let(:dossiers_invites) { [] }
it 'naffiche 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
context 'quand il ny a pas de dossiers invités' do
let(:dossiers_invites) { [] }
it 'affiche un titre adapté' do
expect(rendered).to have_selector('h1', text: 'Mes dossiers')
end
it 'naffiche la barre donglets' do
2021-12-24 18:10:50 +01:00
expect(rendered).to have_selector('nav.tabs')
end
end
2018-06-25 15:14:22 +02:00
context 'quand il y a des dossiers invités' do
let(:dossiers_invites) { create_list(:dossier, 1) }
it 'affiche un titre adapté' do
expect(rendered).to have_selector('h1', text: 'Mes dossiers')
end
it 'affiche la barre donglets' do
2021-12-24 18:10:50 +01:00
expect(rendered).to have_selector('nav.tabs')
2022-01-05 10:43:20 +01:00
expect(rendered).to have_selector('nav.tabs li', count: 5)
2021-12-24 18:10:50 +01:00
expect(rendered).to have_selector('nav.tabs li.active', count: 1)
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
end