2018-08-14 13:39:49 +02:00
|
|
|
describe 'shared/dossiers/champs.html.haml', type: :view do
|
2019-08-06 11:02:54 +02:00
|
|
|
let(:instructeur) { create(:instructeur) }
|
2017-12-05 16:07:05 +01:00
|
|
|
let(:demande_seen_at) { nil }
|
2017-12-12 16:44:30 +01:00
|
|
|
|
|
|
|
before do
|
2017-12-05 16:07:05 +01:00
|
|
|
view.extend DossierHelper
|
2017-12-12 16:44:30 +01:00
|
|
|
view.extend DossierLinkHelper
|
2019-08-06 11:02:54 +02:00
|
|
|
allow(view).to receive(:current_instructeur).and_return(instructeur)
|
2017-12-12 16:44:30 +01:00
|
|
|
end
|
|
|
|
|
2019-01-30 17:20:02 +01:00
|
|
|
subject { render 'shared/dossiers/champs.html.haml', champs: champs, demande_seen_at: demande_seen_at, profile: nil }
|
2017-07-11 16:50:29 +02:00
|
|
|
|
2017-11-21 17:20:52 +01:00
|
|
|
context "there are some champs" do
|
|
|
|
let(:dossier) { create(:dossier) }
|
2019-08-06 11:02:54 +02:00
|
|
|
let(:avis) { create :avis, dossier: dossier, instructeur: instructeur }
|
2018-02-09 17:46:40 +01:00
|
|
|
let(:champ1) { create(:champ, :checkbox, value: "on") }
|
2017-07-11 16:50:29 +02:00
|
|
|
let(:champ2) { create(:champ, :header_section, value: "Section") }
|
2017-10-03 15:08:39 +02:00
|
|
|
let(:champ3) { create(:champ, :explication, value: "mazette") }
|
2017-11-21 17:20:52 +01:00
|
|
|
let(:champ4) { create(:champ, :dossier_link, value: dossier.id) }
|
2019-01-09 11:49:52 +01:00
|
|
|
let(:champ5) { create(:champ_textarea, value: "Some long text in a textarea.") }
|
|
|
|
let(:champs) { [champ1, champ2, champ3, champ4, champ5] }
|
2017-07-11 16:50:29 +02:00
|
|
|
|
2017-12-12 16:44:30 +01:00
|
|
|
before { dossier.avis << avis }
|
|
|
|
|
2019-01-09 11:50:19 +01:00
|
|
|
it "renders titles and values of champs" do
|
|
|
|
expect(subject).to include(champ1.libelle)
|
|
|
|
expect(subject).to include(champ1.value)
|
2017-12-12 16:44:30 +01:00
|
|
|
|
2019-01-09 11:50:19 +01:00
|
|
|
expect(subject).to have_css(".header-section")
|
|
|
|
expect(subject).to include(champ2.libelle)
|
2017-07-11 16:50:29 +02:00
|
|
|
|
2019-01-09 11:50:19 +01:00
|
|
|
expect(subject).to have_link("Dossier nº #{dossier.id}")
|
|
|
|
expect(subject).to include(dossier.text_summary)
|
2017-10-03 15:08:39 +02:00
|
|
|
|
2019-01-09 11:50:19 +01:00
|
|
|
expect(subject).to include(champ5.libelle)
|
|
|
|
expect(subject).to include(champ5.libelle)
|
|
|
|
end
|
2019-01-09 11:49:52 +01:00
|
|
|
|
2019-01-09 11:50:19 +01:00
|
|
|
it "doesn't render explication champs" do
|
|
|
|
expect(subject).not_to include(champ3.libelle)
|
|
|
|
expect(subject).not_to include(champ3.value)
|
|
|
|
end
|
2017-12-12 16:44:30 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context "with a dossier champ, but we are not authorized to acces the dossier" do
|
|
|
|
let(:dossier) { create(:dossier) }
|
|
|
|
let(:champ) { create(:champ, :dossier_link, value: dossier.id) }
|
|
|
|
let(:champs) { [champ] }
|
2017-11-21 17:20:52 +01:00
|
|
|
|
2017-12-12 16:44:30 +01:00
|
|
|
it { is_expected.not_to have_link("Dossier nº #{dossier.id}") }
|
|
|
|
it { is_expected.to include("Dossier nº #{dossier.id}") }
|
|
|
|
it { is_expected.to include(dossier.text_summary) }
|
2017-11-21 17:20:52 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context "with a dossier_link champ but without value" do
|
|
|
|
let(:champ) { create(:champ, :dossier_link, value: nil) }
|
|
|
|
let(:champs) { [champ] }
|
|
|
|
|
2017-12-12 16:44:30 +01:00
|
|
|
it { is_expected.to include("Pas de dossier associé") }
|
2017-07-11 16:50:29 +02:00
|
|
|
end
|
2017-12-05 16:07:05 +01:00
|
|
|
|
|
|
|
context "with seen_at" do
|
|
|
|
let(:dossier) { create(:dossier) }
|
2018-02-09 17:46:40 +01:00
|
|
|
let(:champ1) { create(:champ, :checkbox, value: "on") }
|
2017-12-05 16:07:05 +01:00
|
|
|
let(:champs) { [champ1] }
|
|
|
|
|
|
|
|
context "with a demande_seen_at after champ updated_at" do
|
|
|
|
let(:demande_seen_at) { champ1.updated_at + 1.hour }
|
|
|
|
|
|
|
|
it { is_expected.not_to have_css(".highlighted") }
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with a demande_seen_at after champ updated_at" do
|
|
|
|
let(:demande_seen_at) { champ1.updated_at - 1.hour }
|
|
|
|
|
|
|
|
it { is_expected.to have_css(".highlighted") }
|
|
|
|
end
|
|
|
|
end
|
2017-07-11 16:50:29 +02:00
|
|
|
end
|