diff --git a/spec/controllers/users/dossiers_controller_spec.rb b/spec/controllers/users/dossiers_controller_spec.rb index 75a0dcfb3..b9a60f226 100644 --- a/spec/controllers/users/dossiers_controller_spec.rb +++ b/spec/controllers/users/dossiers_controller_spec.rb @@ -793,14 +793,14 @@ describe Users::DossiersController, type: :controller do context 'when the user does not have any dossiers' do before { get(:index) } - it { expect(assigns(:statut)).to eq('mes-dossiers') } + it { expect(assigns(:statut)).to eq('en-cours') } end context 'when the user only have its own dossiers' do let!(:own_dossier) { create(:dossier, user: user) } before { get(:index) } - it { expect(assigns(:statut)).to eq('mes-dossiers') } + it { expect(assigns(:statut)).to eq('en-cours') } it { expect(assigns(:user_dossiers)).to match([own_dossier]) } end @@ -813,14 +813,16 @@ describe Users::DossiersController, type: :controller do it { expect(assigns(:dossiers_invites)).to match([invite.dossier]) } end - context 'when the user has both' do + context 'when the user has dossiers invites, own and traites' do + let!(:procedure) { create(:procedure, :published) } let!(:own_dossier) { create(:dossier, user: user) } + let!(:own_dossier2) { create(:dossier, user: user, state: "accepte", procedure: procedure) } let!(:invite) { create(:invite, dossier: create(:dossier), user: user) } context 'and there is no statut param' do before { get(:index) } - it { expect(assigns(:statut)).to eq('mes-dossiers') } + it { expect(assigns(:statut)).to eq('en-cours') } end context 'and there is "dossiers-invites" param' do @@ -829,10 +831,24 @@ describe Users::DossiersController, type: :controller do it { expect(assigns(:statut)).to eq('dossiers-invites') } end - context 'and there is "mes-dossiers" param' do - before { get(:index, params: { statut: 'mes-dossiers' }) } + context 'and there is "en-cours" param' do + before { get(:index, params: { statut: 'en-cours' }) } - it { expect(assigns(:statut)).to eq('mes-dossiers') } + it { expect(assigns(:statut)).to eq('en-cours') } + end + + context 'and there is "traites" param' do + before { get(:index, params: { statut: 'traites' }) } + + it { expect(assigns(:statut)).to eq('traites') } + end + + context 'and the traité dossier has been hidden by user' do + before do + own_dossier2.update!(hidden_by_user_at: Time.zone.now) + get(:index, params: { statut: 'traites' }) + end + it { expect(assigns(:statut)).to eq('en-cours') } end end diff --git a/spec/views/users/dossiers/_dossier_actions.html.haml_spec.rb b/spec/views/users/dossiers/_dossier_actions.html.haml_spec.rb index c4512b41e..0859ea60f 100644 --- a/spec/views/users/dossiers/_dossier_actions.html.haml_spec.rb +++ b/spec/views/users/dossiers/_dossier_actions.html.haml_spec.rb @@ -18,14 +18,4 @@ describe 'users/dossiers/dossier_actions.html.haml', type: :view do let(:procedure) { create(:procedure, :closed) } it { is_expected.not_to have_link('Commencer un autre dossier') } end - - context 'when there are no actions to display' do - let(:procedure) { create(:procedure, :closed) } - let(:dossier) { create(:dossier, :accepte, procedure: procedure) } - let(:user) { create(:user) } - - it 'doesn’t render the menu at all' do - expect(subject).not_to have_selector('.dropdown') - end - end end diff --git a/spec/views/users/dossiers/index.html.haml_spec.rb b/spec/views/users/dossiers/index.html.haml_spec.rb index 2764bb99c..ce5d4c7f1 100644 --- a/spec/views/users/dossiers/index.html.haml_spec.rb +++ b/spec/views/users/dossiers/index.html.haml_spec.rb @@ -2,9 +2,10 @@ describe 'users/dossiers/index.html.haml', 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) } - let(:user_dossiers) { [dossier_brouillon, dossier_en_construction] } + 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) { [] } - let(:statut) { 'mes-dossiers' } + let(:statut) { 'en-cours' } before do allow(view).to receive(:new_demarche_url).and_return('#') @@ -12,6 +13,7 @@ describe 'users/dossiers/index.html.haml', type: :view do assign(:user_dossiers, Kaminari.paginate_array(user_dossiers).page(1)) assign(:dossiers_invites, Kaminari.paginate_array(dossiers_invites).page(1)) assign(:dossiers_supprimes, Kaminari.paginate_array(user_dossiers).page(1)) + assign(:dossiers_traites, Kaminari.paginate_array(user_dossiers).page(1)) assign(:dossier_transfers, Kaminari.paginate_array([]).page(1)) assign(:dossiers_close_to_expiration, Kaminari.paginate_array([]).page(1)) assign(:statut, statut) @@ -19,7 +21,7 @@ describe 'users/dossiers/index.html.haml', type: :view do end it 'affiche la liste des dossiers' do - expect(rendered).to have_selector('.dossiers-table tbody tr', count: 2) + expect(rendered).to have_selector('.dossiers-table tbody tr', count: 3) end it 'affiche les informations des dossiers' do @@ -67,8 +69,16 @@ describe 'users/dossiers/index.html.haml', type: :view do it 'affiche la barre d’onglets' do expect(rendered).to have_selector('ul.tabs') - expect(rendered).to have_selector('ul.tabs li', count: 3) + expect(rendered).to have_selector('ul.tabs li', count: 4) expect(rendered).to have_selector('ul.tabs li.active', count: 1) end end + + 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