Merge pull request #9003 from tchak/fix-dossiers-suivis-filter
ETQ Instructeur, je ne veux pas voir les dossiers terminés dans l'onglet "suivis"
This commit is contained in:
commit
e38c6ed73d
2 changed files with 31 additions and 12 deletions
|
@ -432,8 +432,8 @@ class Dossier < ApplicationRecord
|
||||||
when 'suivis'
|
when 'suivis'
|
||||||
instructeur
|
instructeur
|
||||||
.followed_dossiers
|
.followed_dossiers
|
||||||
.en_cours
|
|
||||||
.merge(visible_by_administration)
|
.merge(visible_by_administration)
|
||||||
|
.en_cours
|
||||||
when 'traites'
|
when 'traites'
|
||||||
visible_by_administration.termine
|
visible_by_administration.termine
|
||||||
when 'tous'
|
when 'tous'
|
||||||
|
|
|
@ -829,30 +829,49 @@ describe ProcedurePresentation do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#filtered_sorted_ids' do
|
describe '#filtered_sorted_ids' do
|
||||||
|
let(:procedure_presentation) { create(:procedure_presentation, assign_to:) }
|
||||||
let(:dossier_1) { create(:dossier) }
|
let(:dossier_1) { create(:dossier) }
|
||||||
let(:dossier_2) { create(:dossier) }
|
let(:dossier_2) { create(:dossier) }
|
||||||
let(:dossier_3) { create(:dossier) }
|
let(:dossier_3) { create(:dossier) }
|
||||||
let(:dossiers) { Dossier.where(id: [dossier_1, dossier_2, dossier_3].map(&:id)) }
|
let(:dossiers) { Dossier.where(id: [dossier_1, dossier_2, dossier_3].map(&:id)) }
|
||||||
|
|
||||||
let(:sorted_ids) { [dossier_2, dossier_3, dossier_1].map(&:id) }
|
let(:sorted_ids) { [dossier_2, dossier_3, dossier_1].map(&:id) }
|
||||||
|
let(:statut) { 'tous' }
|
||||||
|
|
||||||
subject { procedure_presentation.filtered_sorted_ids(dossiers, 'tous') }
|
subject { procedure_presentation.filtered_sorted_ids(dossiers, statut) }
|
||||||
|
|
||||||
before do
|
context 'with no filters' do
|
||||||
expect(procedure_presentation).to receive(:sorted_ids).and_return(sorted_ids)
|
let(:statut) { 'suivis' }
|
||||||
end
|
let(:dossiers) { procedure.dossiers }
|
||||||
|
|
||||||
it { is_expected.to eq(sorted_ids) }
|
|
||||||
|
|
||||||
context 'when a filter is present' do
|
|
||||||
let(:filtered_ids) { [dossier_1, dossier_2, dossier_3].map(&:id) }
|
|
||||||
|
|
||||||
before do
|
before do
|
||||||
procedure_presentation.filters['tous'] = 'some_filter'
|
create(:follow, dossier: en_construction_dossier, instructeur: procedure_presentation.instructeur)
|
||||||
expect(procedure_presentation).to receive(:filtered_ids).and_return(filtered_ids)
|
create(:follow, dossier: accepte_dossier, instructeur: procedure_presentation.instructeur)
|
||||||
|
end
|
||||||
|
|
||||||
|
let(:en_construction_dossier) { create(:dossier, :en_construction, procedure:) }
|
||||||
|
let(:accepte_dossier) { create(:dossier, :accepte, procedure:) }
|
||||||
|
|
||||||
|
it { is_expected.to contain_exactly(en_construction_dossier.id) }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with mocked sorted_ids' do
|
||||||
|
before do
|
||||||
|
expect(procedure_presentation).to receive(:sorted_ids).and_return(sorted_ids)
|
||||||
end
|
end
|
||||||
|
|
||||||
it { is_expected.to eq(sorted_ids) }
|
it { is_expected.to eq(sorted_ids) }
|
||||||
|
|
||||||
|
context 'when a filter is present' do
|
||||||
|
let(:filtered_ids) { [dossier_1, dossier_2, dossier_3].map(&:id) }
|
||||||
|
|
||||||
|
before do
|
||||||
|
procedure_presentation.filters['tous'] = 'some_filter'
|
||||||
|
expect(procedure_presentation).to receive(:filtered_ids).and_return(filtered_ids)
|
||||||
|
end
|
||||||
|
|
||||||
|
it { is_expected.to eq(sorted_ids) }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue