2016-09-08 16:21:54 +02:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe DossiersListFacades do
|
|
|
|
let(:gestionnaire) { create :gestionnaire }
|
2017-04-12 15:17:20 +02:00
|
|
|
let(:procedure) { create :procedure, libelle: 'Ma procédure' }
|
|
|
|
let(:procedure_2) { create :procedure, libelle: 'Ma seconde procédure' }
|
2016-09-08 16:21:54 +02:00
|
|
|
|
2016-10-14 12:02:39 +02:00
|
|
|
let!(:preference) { create :preference_list_dossier,
|
2017-06-12 13:49:51 +02:00
|
|
|
gestionnaire: gestionnaire,
|
|
|
|
table: nil,
|
|
|
|
attr: 'state',
|
2017-06-12 14:10:49 +02:00
|
|
|
attr_decorate: 'display_state'
|
|
|
|
}
|
2016-10-14 12:02:39 +02:00
|
|
|
|
|
|
|
let!(:preference_2) { create :preference_list_dossier,
|
2017-06-12 13:49:51 +02:00
|
|
|
gestionnaire: gestionnaire,
|
|
|
|
table: 'champs',
|
|
|
|
attr: 'state',
|
|
|
|
attr_decorate: 'display_state',
|
2017-06-12 14:10:49 +02:00
|
|
|
procedure_id: procedure.id
|
|
|
|
}
|
2016-10-14 12:02:39 +02:00
|
|
|
|
2016-09-08 16:21:54 +02:00
|
|
|
before do
|
2016-09-09 17:29:21 +02:00
|
|
|
create :assign_to, procedure: procedure, gestionnaire: gestionnaire
|
|
|
|
create :assign_to, procedure: procedure_2, gestionnaire: gestionnaire
|
2016-09-08 16:21:54 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#preference_list_dossiers_filter' do
|
|
|
|
subject { facade.preference_list_dossiers_filter }
|
|
|
|
|
|
|
|
context 'when procedure is not pasted at the facade' do
|
|
|
|
let(:facade) { described_class.new gestionnaire, 'nouveaux' }
|
|
|
|
|
|
|
|
it { expect(subject.size).to eq 6 }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when procedure is pasted at the facade' do
|
|
|
|
let(:facade) { described_class.new gestionnaire, 'nouveaux', procedure }
|
|
|
|
|
|
|
|
it { expect(subject.size).to eq 1 }
|
|
|
|
end
|
|
|
|
end
|
2016-09-09 17:29:21 +02:00
|
|
|
|
|
|
|
describe '#gestionnaire_procedures_name_and_id_list' do
|
|
|
|
let(:facade) { described_class.new gestionnaire, 'nouveaux' }
|
|
|
|
|
|
|
|
subject { facade.gestionnaire_procedures_name_and_id_list }
|
|
|
|
|
|
|
|
it { expect(subject.size).to eq 2 }
|
|
|
|
|
2017-04-12 15:17:20 +02:00
|
|
|
it { expect(subject.first).to eq({ id: procedure.id, libelle: procedure.libelle, unread_notifications: 0 }) }
|
|
|
|
it { expect(subject.last).to eq({ id: procedure_2.id, libelle: procedure_2.libelle, unread_notifications: 0 }) }
|
2016-09-09 17:29:21 +02:00
|
|
|
end
|
2016-10-14 12:02:39 +02:00
|
|
|
|
|
|
|
describe '#active_filter?' do
|
|
|
|
let(:table) { nil }
|
|
|
|
let(:filter) { nil }
|
|
|
|
let(:facade) { described_class.new gestionnaire, 'nouveaux', procedure_2 }
|
|
|
|
|
|
|
|
let!(:preference) { create :preference_list_dossier,
|
2017-06-12 13:49:51 +02:00
|
|
|
gestionnaire: gestionnaire,
|
|
|
|
table: table,
|
|
|
|
attr: 'state',
|
|
|
|
attr_decorate: 'display_state',
|
|
|
|
filter: filter,
|
2017-06-12 14:10:49 +02:00
|
|
|
procedure_id: procedure_id
|
|
|
|
}
|
2016-10-14 12:02:39 +02:00
|
|
|
|
|
|
|
subject { facade.active_filter? preference }
|
|
|
|
|
|
|
|
context 'when gestionnaire does not have select a procedure' do
|
|
|
|
let(:procedure_2) { nil }
|
|
|
|
let(:procedure_id) { nil }
|
|
|
|
|
|
|
|
it { expect(preference.procedure).to be_nil }
|
|
|
|
it { is_expected.to be_truthy }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when gestionnaire have select a procedure' do
|
|
|
|
let(:procedure_id) { procedure_2.id }
|
|
|
|
|
|
|
|
it { expect(preference.procedure).not_to be_nil }
|
|
|
|
|
|
|
|
context 'when preference is not a champs filter' do
|
|
|
|
let(:table) { 'entreprises' }
|
|
|
|
|
|
|
|
it { is_expected.to be_truthy }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when gestionnaire have an existant filter with a champ' do
|
|
|
|
let(:table) { 'champs' }
|
|
|
|
let(:filter) { 'plop' }
|
|
|
|
|
|
|
|
context 'when the preference is the existant champ filter' do
|
|
|
|
it { is_expected.to be_truthy }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the preference is not the existant champ filter' do
|
|
|
|
let(:preference) { preference_2 }
|
|
|
|
|
|
|
|
before do
|
|
|
|
create :preference_list_dossier,
|
2017-06-12 13:49:51 +02:00
|
|
|
gestionnaire: gestionnaire,
|
|
|
|
table: 'champs',
|
|
|
|
attr: 'state',
|
|
|
|
attr_decorate: 'display_state',
|
|
|
|
filter: 'plop',
|
|
|
|
procedure_id: procedure_id
|
2016-10-14 12:02:39 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to be_falsey }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when gestionnaire does not have an existant filter with a champ' do
|
|
|
|
let(:table) { nil }
|
|
|
|
let(:filter) { 'plop' }
|
|
|
|
|
|
|
|
context 'when the preference is the existant preference filter' do
|
|
|
|
it { is_expected.to be_truthy }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the preference is not the existant preference filter' do
|
|
|
|
let(:preference) { preference_2 }
|
|
|
|
|
|
|
|
it { is_expected.to be_truthy }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-04-04 15:27:04 +02:00
|
|
|
end
|