2022-12-13 16:13:31 +01:00
|
|
|
describe "Dossier en_construction" do
|
|
|
|
let(:user) { create(:user) }
|
2024-01-23 09:52:20 +01:00
|
|
|
let(:procedure) { create(:procedure, :for_individual, types_de_champ_public: [{ type: :piece_justificative }, { type: :titre_identite }]) }
|
2022-12-13 16:13:31 +01:00
|
|
|
let(:dossier) { create(:dossier, :en_construction, :with_individual, :with_populated_champs, user:, procedure:) }
|
|
|
|
|
|
|
|
let(:tdc) {
|
|
|
|
procedure.active_revision.types_de_champ_public.find { _1.type_champ == "piece_justificative" }
|
|
|
|
}
|
|
|
|
|
|
|
|
let(:champ) {
|
2024-07-01 15:31:32 +02:00
|
|
|
dossier.find_editing_fork(dossier.user).champs_public.find { _1.stable_id == tdc.stable_id }
|
2022-12-13 16:13:31 +01:00
|
|
|
}
|
|
|
|
|
2023-11-06 15:15:51 +01:00
|
|
|
scenario 'delete a non mandatory piece justificative', js: true do
|
2022-12-13 16:13:31 +01:00
|
|
|
visit_dossier(dossier)
|
|
|
|
|
|
|
|
expect(page).not_to have_button("Remplacer")
|
|
|
|
click_on "Supprimer le fichier toto.txt"
|
|
|
|
|
2023-05-10 10:29:23 +02:00
|
|
|
wait_until { champ.reload.for_export.blank? }
|
2022-12-13 16:13:31 +01:00
|
|
|
expect(page).not_to have_text("toto.txt")
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with a mandatory piece justificative" do
|
|
|
|
before do
|
|
|
|
tdc.update_attribute(:mandatory, true)
|
|
|
|
end
|
|
|
|
|
2023-11-06 15:15:51 +01:00
|
|
|
scenario 'remplace a mandatory piece justificative', js: true do
|
2022-12-13 16:13:31 +01:00
|
|
|
visit_dossier(dossier)
|
|
|
|
|
2023-03-21 18:24:39 +01:00
|
|
|
click_on "Supprimer le fichier toto.txt"
|
2024-07-15 16:58:45 +02:00
|
|
|
expect(page).not_to have_text("toto.txt")
|
2022-12-13 16:13:31 +01:00
|
|
|
|
2024-02-21 03:01:24 +01:00
|
|
|
input_selector = "#attachment-multiple-empty-#{champ.public_id}"
|
2022-12-13 16:13:31 +01:00
|
|
|
expect(page).to have_selector(input_selector)
|
|
|
|
find(input_selector).attach_file(Rails.root.join('spec/fixtures/files/file.pdf'))
|
|
|
|
|
2023-05-10 10:29:23 +02:00
|
|
|
wait_until { champ.reload.for_export == 'file.pdf' }
|
2022-12-13 16:13:31 +01:00
|
|
|
expect(page).to have_text("file.pdf")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with a mandatory titre identite" do
|
|
|
|
let(:tdc) {
|
|
|
|
procedure.active_revision.types_de_champ_public.find { _1.type_champ == "titre_identite" }
|
|
|
|
}
|
|
|
|
|
|
|
|
before do
|
|
|
|
tdc.update_attribute(:mandatory, true)
|
|
|
|
end
|
|
|
|
|
2023-11-06 15:15:51 +01:00
|
|
|
scenario 'remplace a mandatory titre identite', js: true do
|
2022-12-13 16:13:31 +01:00
|
|
|
visit_dossier(dossier)
|
|
|
|
|
2023-03-21 18:24:39 +01:00
|
|
|
click_on "Supprimer le fichier toto.png"
|
2024-07-15 16:58:45 +02:00
|
|
|
expect(page).not_to have_text("toto.png")
|
2022-12-13 16:13:31 +01:00
|
|
|
|
2023-03-21 18:24:39 +01:00
|
|
|
input_selector = "##{champ.input_id}"
|
2022-12-13 16:13:31 +01:00
|
|
|
expect(page).to have_selector(input_selector)
|
|
|
|
find(input_selector).attach_file(Rails.root.join('spec/fixtures/files/file.pdf'))
|
|
|
|
|
|
|
|
expect(page).to have_text("file.pdf")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def visit_dossier(dossier)
|
|
|
|
visit modifier_dossier_path(dossier)
|
|
|
|
|
|
|
|
expect(page).to have_current_path(new_user_session_path)
|
|
|
|
fill_in 'user_email', with: user.email
|
|
|
|
fill_in 'user_password', with: user.password
|
|
|
|
click_on 'Se connecter'
|
|
|
|
|
|
|
|
expect(page).to have_current_path(modifier_dossier_path(dossier))
|
|
|
|
end
|
|
|
|
end
|