2023-03-06 15:51:08 +01:00
|
|
|
describe 'shared/dossiers/edit', type: :view do
|
2020-08-19 17:27:57 +02:00
|
|
|
before do
|
|
|
|
allow(controller).to receive(:current_user).and_return(dossier.user)
|
2022-09-19 18:27:50 +02:00
|
|
|
allow(view).to receive(:administrateur_signed_in?).and_return(false)
|
2020-08-19 17:27:57 +02:00
|
|
|
end
|
|
|
|
|
2023-03-06 15:51:08 +01:00
|
|
|
subject { render 'shared/dossiers/edit', dossier: dossier, apercu: false }
|
2020-08-19 17:27:57 +02:00
|
|
|
|
2023-11-28 17:33:43 +01:00
|
|
|
let(:procedure) { create(:procedure, types_de_champ_public:) }
|
|
|
|
let(:dossier) { create(:dossier, :with_populated_champs, procedure:) }
|
|
|
|
|
2020-08-19 17:27:57 +02:00
|
|
|
context 'when there are some champs' do
|
2023-11-28 17:33:43 +01:00
|
|
|
let(:type_de_champ_header_section) { procedure.draft_types_de_champ_public.find(&:header_section?) }
|
|
|
|
let(:type_de_champ_explication) { procedure.draft_types_de_champ_public.find(&:explication?) }
|
|
|
|
let(:type_de_champ_dossier_link) { procedure.draft_types_de_champ_public.find(&:dossier_link?) }
|
|
|
|
let(:type_de_champ_checkbox) { procedure.draft_types_de_champ_public.find(&:checkbox?) }
|
|
|
|
let(:type_de_champ_textarea) { procedure.draft_types_de_champ_public.find(&:textarea?) }
|
|
|
|
|
2024-03-15 14:10:12 +01:00
|
|
|
let(:champ_checkbox) { dossier.project_champ(type_de_champ_checkbox, nil) }
|
|
|
|
let(:champ_dossier_link) { dossier.project_champ(type_de_champ_dossier_link, nil) }
|
|
|
|
let(:champ_textarea) { dossier.project_champ(type_de_champ_textarea, nil) }
|
2020-08-19 17:27:57 +02:00
|
|
|
|
2023-11-28 17:33:43 +01:00
|
|
|
let(:types_de_champ_public) { [{ type: :checkbox }, { type: :header_section }, { type: :explication }, { type: :dossier_link }, { type: :textarea }] }
|
2020-08-19 17:27:57 +02:00
|
|
|
|
|
|
|
it 'renders labels and editable values of champs' do
|
|
|
|
expect(subject).to have_field(champ_checkbox.libelle, checked: true)
|
2023-11-28 17:33:43 +01:00
|
|
|
expect(subject).to have_css(".header-section", text: type_de_champ_header_section.libelle)
|
|
|
|
expect(subject).to have_text(type_de_champ_explication.libelle)
|
|
|
|
expect(subject).to have_field(type_de_champ_dossier_link.libelle, with: champ_dossier_link.value)
|
2020-08-19 17:27:57 +02:00
|
|
|
expect(subject).to have_field(champ_textarea.libelle, with: champ_textarea.value)
|
|
|
|
end
|
2022-07-04 18:37:30 +02:00
|
|
|
|
|
|
|
context "with standard champs" do
|
2023-11-28 17:33:43 +01:00
|
|
|
let(:types_de_champ_public) { [{ type: :email }, { type: :phone }] }
|
2022-07-04 18:37:30 +02:00
|
|
|
|
2023-09-25 18:01:54 +02:00
|
|
|
it "does not render basic placeholders" do
|
|
|
|
expect(subject).not_to have_css('input[type="email"][placeholder$="exemple.fr"]')
|
|
|
|
expect(subject).not_to have_css('input[type="tel"][placeholder^="0612"]')
|
2022-07-04 18:37:30 +02:00
|
|
|
end
|
|
|
|
end
|
2020-08-19 17:27:57 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a single-value list' do
|
2023-11-28 17:33:43 +01:00
|
|
|
let(:types_de_champ_public) { [{ type: :drop_down_list, options:, mandatory: }] }
|
|
|
|
let(:champ) { dossier.champs_public.first }
|
|
|
|
let(:type_de_champ) { champ.type_de_champ }
|
2020-08-19 17:27:57 +02:00
|
|
|
let(:enabled_options) { type_de_champ.drop_down_list_enabled_non_empty_options }
|
|
|
|
let(:mandatory) { true }
|
2023-11-28 17:33:43 +01:00
|
|
|
let(:options) { nil }
|
2020-08-19 17:27:57 +02:00
|
|
|
|
|
|
|
context 'when the list is short' do
|
2023-01-18 09:47:22 +01:00
|
|
|
let(:value) { 'val1' }
|
2023-10-27 17:39:02 +02:00
|
|
|
|
2023-11-28 17:33:43 +01:00
|
|
|
before { champ.update(value:) }
|
|
|
|
|
2020-08-19 17:27:57 +02:00
|
|
|
it 'renders the list as radio buttons' do
|
|
|
|
expect(subject).to have_selector('input[type=radio]', count: enabled_options.count)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the champ is optional' do
|
|
|
|
let(:mandatory) { false }
|
|
|
|
|
|
|
|
it 'allows unselecting a previously selected value' do
|
|
|
|
expect(subject).to have_selector('input[type=radio]', count: enabled_options.count + 1)
|
|
|
|
expect(subject).to have_unchecked_field('Non renseigné', count: 1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the list is long' do
|
2023-01-18 09:47:22 +01:00
|
|
|
let(:value) { 'alpha' }
|
2023-11-28 17:33:43 +01:00
|
|
|
let(:options) { [:long] }
|
|
|
|
|
|
|
|
before { champ.update(value:) }
|
2020-08-19 17:27:57 +02:00
|
|
|
|
|
|
|
it 'renders the list as a dropdown' do
|
2023-10-27 17:39:02 +02:00
|
|
|
expect(subject).to have_select(type_de_champ.libelle, options: enabled_options + [''])
|
2020-08-19 17:27:57 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a multiple-values list' do
|
2023-11-28 17:33:43 +01:00
|
|
|
let(:types_de_champ_public) { [{ type: :multiple_drop_down_list, options: }] }
|
|
|
|
let(:champ) { dossier.champs.first }
|
|
|
|
let(:type_de_champ) { champ.type_de_champ }
|
2020-08-19 17:27:57 +02:00
|
|
|
let(:options) { type_de_champ.drop_down_list_options }
|
|
|
|
let(:enabled_options) { type_de_champ.drop_down_list_enabled_non_empty_options }
|
|
|
|
|
|
|
|
context 'when the list is short' do
|
2023-11-28 17:33:43 +01:00
|
|
|
let(:options) { ['valid', 'invalid', 'not sure yet'] }
|
2021-07-08 17:29:40 +02:00
|
|
|
|
2020-08-19 17:27:57 +02:00
|
|
|
it 'renders the list as checkboxes' do
|
|
|
|
expect(subject).to have_selector('input[type=checkbox]', count: enabled_options.count)
|
2023-11-28 17:33:43 +01:00
|
|
|
expect(subject).to have_selector('input[type=checkbox][checked=checked]', count: 2)
|
2020-08-19 17:27:57 +02:00
|
|
|
end
|
2020-08-25 12:47:36 +02:00
|
|
|
|
|
|
|
it 'adds an extra hidden input, to send a blank value even when all checkboxes are unchecked' do
|
|
|
|
expect(subject).to have_selector('input[type=hidden][value=""]')
|
|
|
|
end
|
2020-08-19 17:27:57 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the list is long' do
|
2023-11-28 17:33:43 +01:00
|
|
|
let(:options) { ['peach', 'banana', 'pear', 'apricot', 'apple', 'grapefruit'] }
|
2020-08-19 17:27:57 +02:00
|
|
|
|
|
|
|
it 'renders the list as a multiple-selection dropdown' do
|
2023-03-29 23:31:13 +02:00
|
|
|
expect(subject).to have_selector('select')
|
2020-08-19 17:27:57 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-07-28 11:08:27 +02:00
|
|
|
context 'with a mandatory piece justificative' do
|
2023-11-28 17:33:43 +01:00
|
|
|
let(:types_de_champ_public) { [{ type: :piece_justificative, mandatory: true }] }
|
|
|
|
let(:champ) { dossier.champs.first }
|
2022-07-28 11:08:27 +02:00
|
|
|
|
|
|
|
context 'when dossier is en construction' do
|
2023-11-28 17:33:43 +01:00
|
|
|
let(:dossier) { create(:dossier, :en_construction, :with_populated_champs, procedure:) }
|
2022-07-28 11:08:27 +02:00
|
|
|
|
2023-03-21 18:24:39 +01:00
|
|
|
it 'can delete a piece justificative' do
|
|
|
|
expect(subject).to have_selector("[title='Supprimer le fichier #{champ.piece_justificative_file.attachments[0].filename}']")
|
2022-07-28 11:08:27 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when dossier is brouillon' do
|
|
|
|
it 'can delete a piece justificative' do
|
2022-11-21 18:32:17 +01:00
|
|
|
expect(subject).to have_selector("[title='Supprimer le fichier #{champ.piece_justificative_file.attachments[0].filename}']")
|
2022-07-28 11:08:27 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-08-19 17:27:57 +02:00
|
|
|
context 'with a routed procedure' do
|
2023-11-28 17:33:43 +01:00
|
|
|
let(:groupe_instructeur) { create(:groupe_instructeur) }
|
|
|
|
let(:procedure) { create(:procedure, :routee, groupe_instructeurs: [groupe_instructeur], types_de_champ_public: [{ type: :drop_down_list, options: }]) }
|
|
|
|
let(:options) { [groupe_instructeur.label] }
|
|
|
|
let(:dossier) { create(:dossier, procedure:) }
|
|
|
|
let(:champ_drop_down) { dossier.champs.first }
|
2023-06-20 15:46:12 +02:00
|
|
|
|
|
|
|
it 'renders the libelle of the type de champ used for routing' do
|
|
|
|
expect(subject).to include(champ_drop_down.libelle)
|
2021-03-09 11:21:30 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when groupe instructeur is selected' do
|
|
|
|
before do
|
|
|
|
dossier.groupe_instructeur = dossier.procedure.defaut_groupe_instructeur
|
|
|
|
end
|
|
|
|
|
2023-06-20 15:46:12 +02:00
|
|
|
it 'renders the routing libelle and its value' do
|
|
|
|
expect(subject).to include(champ_drop_down.libelle)
|
2021-03-09 11:21:30 +01:00
|
|
|
expect(subject).to include(dossier.groupe_instructeur.label)
|
|
|
|
end
|
2020-08-19 17:27:57 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|