2023-03-06 15:51:08 +01:00
|
|
|
describe 'shared/dossiers/champs', 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 }
|
2023-06-28 09:55:57 +02:00
|
|
|
let(:profile) { "instructeur" }
|
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
|
2023-06-28 09:55:57 +02:00
|
|
|
|
|
|
|
if profile == "instructeur"
|
|
|
|
allow(view).to receive(:current_instructeur).and_return(instructeur)
|
|
|
|
end
|
2017-12-12 16:44:30 +01:00
|
|
|
end
|
|
|
|
|
2023-06-28 09:55:57 +02:00
|
|
|
subject { render 'shared/dossiers/champs', champs:, dossier:, demande_seen_at:, profile: }
|
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) }
|
2023-01-05 12:18:27 +01:00
|
|
|
let(:champ1) { create(:champ_checkbox, dossier: dossier, value: 'true') }
|
2020-07-20 17:18:44 +02:00
|
|
|
let(:champ2) { create(:champ_header_section, dossier: dossier, value: "Section") }
|
|
|
|
let(:champ3) { create(:champ_explication, dossier: dossier, value: "mazette") }
|
|
|
|
let(:champ4) { create(:champ_dossier_link, dossier: dossier, value: dossier.id) }
|
|
|
|
let(:champ5) { create(:champ_textarea, dossier: dossier, value: "Some long text in a textarea.") }
|
2022-09-22 17:14:05 +02:00
|
|
|
let(:champ6) { create(:champ_rna, value: "W173847273") }
|
|
|
|
let(:champs) { [champ1, champ2, champ3, champ4, champ5, champ6] }
|
2017-07-11 16:50:29 +02:00
|
|
|
|
2019-01-09 11:50:19 +01:00
|
|
|
it "renders titles and values of champs" do
|
|
|
|
expect(subject).to include(champ1.libelle)
|
2023-01-05 12:18:27 +01:00
|
|
|
expect(subject).to include('Oui')
|
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 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)
|
2022-09-22 17:14:05 +02:00
|
|
|
expect(subject).to include(champ5.value)
|
|
|
|
expect(subject).to include(champ6.libelle)
|
|
|
|
expect(subject).to include(champ6.value)
|
2019-01-09 11:50:19 +01:00
|
|
|
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
|
2019-09-26 17:40:52 +02:00
|
|
|
|
|
|
|
context "with auto-link" do
|
|
|
|
let(:champ1) { create(:champ_text, value: "https://github.com/tchak") }
|
|
|
|
let(:champ2) { create(:champ_textarea, value: "https://github.com/LeSim") }
|
|
|
|
let(:link1) { '<a href="https://github.com/tchak" target="_blank" rel="noopener">https://github.com/tchak</a>' }
|
|
|
|
let(:link2) { '<a href="https://github.com/LeSim" target="_blank" rel="noopener">https://github.com/LeSim</a>' }
|
|
|
|
|
|
|
|
it "render links" do
|
|
|
|
expect(subject).to include(link1)
|
|
|
|
expect(subject).to include(link2)
|
|
|
|
end
|
|
|
|
end
|
2017-12-12 16:44:30 +01:00
|
|
|
end
|
|
|
|
|
2019-10-15 10:29:07 +02:00
|
|
|
context "with a routed procedure" do
|
|
|
|
let(:procedure) do
|
|
|
|
create(:procedure,
|
|
|
|
:routee,
|
|
|
|
routing_criteria_name: 'departement')
|
|
|
|
end
|
2022-11-08 12:42:16 +01:00
|
|
|
let(:dossier) { create(:dossier, :en_construction, procedure: procedure) }
|
2019-10-15 10:29:07 +02:00
|
|
|
let(:champs) { [] }
|
|
|
|
|
2022-10-24 23:08:39 +02:00
|
|
|
it "renders the routing criteria name and its value" do
|
|
|
|
expect(subject).to include(procedure.routing_criteria_name)
|
|
|
|
expect(subject).to include(dossier.groupe_instructeur.label)
|
2019-10-15 10:29:07 +02:00
|
|
|
end
|
2020-02-26 22:17:55 +01:00
|
|
|
|
|
|
|
context "with seen_at" do
|
|
|
|
let(:dossier) { create(:dossier) }
|
|
|
|
let(:nouveau_groupe_instructeur) { create(:groupe_instructeur, procedure: dossier.procedure) }
|
2023-01-05 12:18:27 +01:00
|
|
|
let(:champ1) { create(:champ_checkbox, dossier: dossier, value: 'true') }
|
2020-02-26 22:17:55 +01:00
|
|
|
let(:champs) { [champ1] }
|
|
|
|
|
|
|
|
context "with a demande_seen_at after groupe_instructeur_updated_at" do
|
|
|
|
let(:demande_seen_at) { dossier.groupe_instructeur_updated_at + 1.hour }
|
|
|
|
|
|
|
|
it "expect to not highlight new group instructeur label" do
|
|
|
|
dossier.assign_to_groupe_instructeur(nouveau_groupe_instructeur)
|
|
|
|
expect(subject).not_to have_css(".highlighted")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with a demande_seen_at before groupe_instructeur_updated_at" do
|
|
|
|
let(:demande_seen_at) { dossier.groupe_instructeur_updated_at - 1.hour }
|
|
|
|
|
|
|
|
it "expect to not highlight new group instructeur label" do
|
|
|
|
dossier.assign_to_groupe_instructeur(nouveau_groupe_instructeur)
|
|
|
|
expect(subject).to have_css(".highlighted")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-10-15 10:29:07 +02:00
|
|
|
end
|
|
|
|
|
2017-12-12 16:44:30 +01:00
|
|
|
context "with a dossier champ, but we are not authorized to acces the dossier" do
|
|
|
|
let(:dossier) { create(:dossier) }
|
2020-07-20 17:18:44 +02:00
|
|
|
let(:champ) { create(:champ_dossier_link, dossier: dossier, value: dossier.id) }
|
2017-12-12 16:44:30 +01:00
|
|
|
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
|
2019-10-15 10:29:07 +02:00
|
|
|
let(:dossier) { create(:dossier) }
|
2020-07-20 17:18:44 +02:00
|
|
|
let(:champ) { create(:champ_dossier_link, dossier: dossier, value: nil) }
|
2017-11-21 17:20:52 +01:00
|
|
|
let(:champs) { [champ] }
|
|
|
|
|
2023-06-29 07:16:39 +02:00
|
|
|
it { is_expected.not_to include("non saisi") }
|
2023-06-28 09:55:57 +02:00
|
|
|
|
|
|
|
context 'when profile is usager' do
|
|
|
|
let(:profile) { "usager" }
|
|
|
|
it { is_expected.to include("non saisi (facultatif)") }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with a piece justificative without value" do
|
|
|
|
let(:dossier) { create(:dossier) }
|
|
|
|
let(:champ) { create(:champ_without_piece_justificative, dossier:) }
|
|
|
|
let(:champs) { [champ] }
|
|
|
|
|
2023-06-29 07:16:39 +02:00
|
|
|
it { is_expected.not_to include("pièce justificative non saisie") }
|
2023-06-28 09:55:57 +02:00
|
|
|
|
|
|
|
context 'when profile is usager' do
|
|
|
|
let(:profile) { "usager" }
|
|
|
|
it { is_expected.to include("pièce justificative non saisie (facultative)") }
|
|
|
|
end
|
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) }
|
2023-01-05 12:18:27 +01:00
|
|
|
let(:champ1) { create(:champ_checkbox, dossier: dossier, value: 'true') }
|
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
|