2023-08-31 09:59:18 +02:00
|
|
|
|
describe 'BatchOperation a dossier:', js: true, retry: 3 do
|
2022-12-02 15:30:35 +01:00
|
|
|
|
include ActionView::RecordIdentifier
|
|
|
|
|
include ActiveJob::TestHelper
|
|
|
|
|
|
|
|
|
|
let(:password) { 'demarches-simplifiees' }
|
|
|
|
|
let(:instructeur) { create(:instructeur, password: password) }
|
|
|
|
|
let(:procedure) { create(:simple_procedure, :published, instructeurs: [instructeur], administrateurs: [create(:administrateur)]) }
|
|
|
|
|
|
|
|
|
|
context 'with an instructeur' do
|
|
|
|
|
scenario 'create a BatchOperation' do
|
|
|
|
|
dossier_1 = create(:dossier, :accepte, procedure: procedure)
|
|
|
|
|
dossier_2 = create(:dossier, :accepte, procedure: procedure)
|
|
|
|
|
dossier_3 = create(:dossier, :accepte, procedure: procedure)
|
|
|
|
|
log_in(instructeur.email, password)
|
2022-12-15 14:13:13 +01:00
|
|
|
|
|
|
|
|
|
# visit a page without batch operation and make sure there is no checkboxes in table
|
|
|
|
|
visit instructeur_procedure_path(procedure, statut: 'tous')
|
|
|
|
|
expect(page).not_to have_selector("#checkbox_all_batch_operation")
|
|
|
|
|
expect(page).not_to have_selector("#checkbox_#{dossier_1.id}_batch_operation")
|
|
|
|
|
|
2022-12-02 15:30:35 +01:00
|
|
|
|
visit instructeur_procedure_path(procedure, statut: 'traites')
|
2022-12-02 17:16:29 +01:00
|
|
|
|
|
|
|
|
|
# check a11y with enabled checkbox
|
|
|
|
|
expect(page).to be_axe_clean
|
2022-12-02 15:30:35 +01:00
|
|
|
|
# ensure button is disabled by default
|
2023-01-10 14:06:56 +01:00
|
|
|
|
expect(page).to have_button("Archiver les dossiers", disabled: true)
|
2022-12-02 15:30:35 +01:00
|
|
|
|
|
|
|
|
|
checkbox_id = dom_id(BatchOperation.new, "checkbox_#{dossier_1.id}")
|
|
|
|
|
# batch one dossier
|
|
|
|
|
check(checkbox_id)
|
2023-01-10 14:06:56 +01:00
|
|
|
|
expect(page).to have_button("Archiver les dossiers")
|
2022-12-02 15:30:35 +01:00
|
|
|
|
|
|
|
|
|
# ensure batch is created
|
2023-07-06 11:15:41 +02:00
|
|
|
|
|
|
|
|
|
page.accept_alert do
|
|
|
|
|
click_on "Archiver les dossiers"
|
|
|
|
|
end
|
2022-12-02 15:30:35 +01:00
|
|
|
|
|
|
|
|
|
# ensure batched dossier is disabled
|
|
|
|
|
expect(page).to have_selector("##{checkbox_id}[disabled]")
|
2023-07-06 11:15:41 +02:00
|
|
|
|
# ensure Batch is created
|
|
|
|
|
expect(BatchOperation.count).to eq(1)
|
2022-12-02 17:16:29 +01:00
|
|
|
|
# check a11y with disabled checkbox
|
|
|
|
|
expect(page).to be_axe_clean
|
2022-12-02 15:30:35 +01:00
|
|
|
|
|
|
|
|
|
# ensure alert is present
|
|
|
|
|
expect(page).to have_content("Information : Une action de masse est en cours")
|
2023-07-06 11:15:41 +02:00
|
|
|
|
expect(page).to have_content("1 dossier est en cours d'archivage")
|
2022-12-02 15:30:35 +01:00
|
|
|
|
|
|
|
|
|
# ensure jobs are queued
|
|
|
|
|
perform_enqueued_jobs(only: [BatchOperationEnqueueAllJob])
|
|
|
|
|
expect { perform_enqueued_jobs(only: [BatchOperationProcessOneJob]) }
|
|
|
|
|
.to change { dossier_1.reload.archived }
|
|
|
|
|
.from(false).to(true)
|
|
|
|
|
|
|
|
|
|
# ensure alert updates when jobs are run
|
|
|
|
|
click_on "Recharger la page"
|
2023-06-08 10:03:34 +02:00
|
|
|
|
expect(page).to have_content("L’action de masse est terminée")
|
2022-12-02 15:30:35 +01:00
|
|
|
|
expect(page).to have_content("1 dossier a été archivé")
|
|
|
|
|
|
|
|
|
|
# clean alert after reload
|
|
|
|
|
visit instructeur_procedure_path(procedure, statut: 'traites')
|
2023-06-08 10:03:34 +02:00
|
|
|
|
expect(page).not_to have_content("L’action de masse est terminée")
|
2022-12-02 15:30:35 +01:00
|
|
|
|
|
|
|
|
|
# try checkall
|
|
|
|
|
find("##{dom_id(BatchOperation.new, :checkbox_all)}").check
|
2023-01-23 09:42:35 +01:00
|
|
|
|
|
|
|
|
|
# multiple select notice don't appear if all the dossiers are on the same page
|
2023-01-30 17:03:30 +01:00
|
|
|
|
expect(page).to have_selector('#js_batch_select_more', visible: false)
|
2023-01-23 09:42:35 +01:00
|
|
|
|
|
2022-12-02 15:30:35 +01:00
|
|
|
|
[dossier_2, dossier_3].map do |dossier|
|
|
|
|
|
dossier_checkbox_id = dom_id(BatchOperation.new, "checkbox_#{dossier.id}")
|
|
|
|
|
expect(page).to have_selector("##{dossier_checkbox_id}:checked")
|
|
|
|
|
end
|
|
|
|
|
|
2023-01-23 09:42:35 +01:00
|
|
|
|
# submit checkall
|
2023-07-06 11:15:41 +02:00
|
|
|
|
page.accept_alert do
|
|
|
|
|
click_on "Archiver les dossiers"
|
|
|
|
|
end
|
2022-12-02 15:30:35 +01:00
|
|
|
|
|
2023-07-06 11:15:41 +02:00
|
|
|
|
# reload
|
|
|
|
|
visit instructeur_procedure_path(procedure, statut: 'traites')
|
|
|
|
|
|
|
|
|
|
expect(BatchOperation.count).to eq(2)
|
2022-12-02 15:30:35 +01:00
|
|
|
|
expect(BatchOperation.last.dossiers).to match_array([dossier_2, dossier_3])
|
|
|
|
|
end
|
2023-01-23 09:42:35 +01:00
|
|
|
|
|
|
|
|
|
scenario 'create a BatchOperation with more dossiers than pagination' do
|
|
|
|
|
stub_const "Instructeurs::ProceduresController::ITEMS_PER_PAGE", 2
|
|
|
|
|
dossier_1 = create(:dossier, :en_instruction, procedure: procedure)
|
|
|
|
|
dossier_2 = create(:dossier, :en_instruction, procedure: procedure)
|
|
|
|
|
dossier_3 = create(:dossier, :en_instruction, procedure: procedure)
|
|
|
|
|
log_in(instructeur.email, password)
|
|
|
|
|
|
|
|
|
|
visit instructeur_procedure_path(procedure, statut: 'a-suivre')
|
|
|
|
|
|
|
|
|
|
expect(page).to have_content("1 - 2 sur 3 dossiers")
|
|
|
|
|
|
|
|
|
|
# click on check_all make the notice appear
|
|
|
|
|
find("##{dom_id(BatchOperation.new, :checkbox_all)}").check
|
2023-01-30 17:03:30 +01:00
|
|
|
|
expect(page).to have_selector('#js_batch_select_more')
|
2023-02-03 14:30:31 +01:00
|
|
|
|
expect(page).to have_content('Les 2 dossiers de cette page sont sélectionnés. Sélectionner tous les 3 dossiers.')
|
2023-01-23 09:42:35 +01:00
|
|
|
|
|
|
|
|
|
# click on selection link fill checkbox value with dossier_ids
|
2023-02-03 14:30:31 +01:00
|
|
|
|
click_on("Sélectionner tous les 3 dossiers")
|
2023-01-23 09:42:35 +01:00
|
|
|
|
expect(page).to have_content('3 dossiers sont sélectionnés. Effacer la sélection ')
|
2023-01-24 17:59:39 +01:00
|
|
|
|
expect(find_field("batch_operation[dossier_ids][]", type: :hidden).value).to eq "#{dossier_3.id},#{dossier_2.id},#{dossier_1.id}"
|
|
|
|
|
|
2023-01-23 09:42:35 +01:00
|
|
|
|
# click on delete link empty checkbox value and hide notice
|
|
|
|
|
click_on("Effacer la sélection")
|
2023-01-30 17:03:30 +01:00
|
|
|
|
expect(page).to have_selector('#js_batch_select_more', visible: false)
|
2023-01-23 09:42:35 +01:00
|
|
|
|
expect(page).to have_button("Suivre les dossiers", disabled: true)
|
2023-01-24 17:59:39 +01:00
|
|
|
|
expect(find_field("batch_operation[dossier_ids][]", type: :hidden).value).to eq ""
|
2023-01-23 09:42:35 +01:00
|
|
|
|
|
|
|
|
|
# click on check_all + notice link and submit
|
|
|
|
|
find("##{dom_id(BatchOperation.new, :checkbox_all)}").check
|
2023-02-03 14:30:31 +01:00
|
|
|
|
click_on("Sélectionner tous les 3 dossiers")
|
2023-01-23 09:42:35 +01:00
|
|
|
|
|
2023-07-06 11:15:41 +02:00
|
|
|
|
accept_alert do
|
|
|
|
|
click_on "Suivre les dossiers"
|
|
|
|
|
end
|
2023-01-23 09:42:35 +01:00
|
|
|
|
|
2023-07-06 11:15:41 +02:00
|
|
|
|
# reload
|
|
|
|
|
visit instructeur_procedure_path(procedure, statut: 'a-suivre')
|
|
|
|
|
|
|
|
|
|
expect(BatchOperation.count).to eq(1)
|
2023-01-23 09:42:35 +01:00
|
|
|
|
expect(BatchOperation.last.dossiers).to match_array([dossier_1, dossier_2, dossier_3])
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
scenario 'create a BatchOperation within the limit of selection' do
|
|
|
|
|
stub_const "Instructeurs::ProceduresController::ITEMS_PER_PAGE", 2
|
|
|
|
|
stub_const "Instructeurs::ProceduresController::BATCH_SELECTION_LIMIT", 3
|
|
|
|
|
dossier_1 = create(:dossier, :en_instruction, procedure: procedure)
|
|
|
|
|
dossier_2 = create(:dossier, :en_instruction, procedure: procedure)
|
|
|
|
|
dossier_3 = create(:dossier, :en_instruction, procedure: procedure)
|
|
|
|
|
dossier_4 = create(:dossier, :en_instruction, procedure: procedure)
|
|
|
|
|
log_in(instructeur.email, password)
|
|
|
|
|
|
|
|
|
|
visit instructeur_procedure_path(procedure, statut: 'a-suivre')
|
|
|
|
|
|
|
|
|
|
# click on check_all make the notice appear
|
|
|
|
|
find("##{dom_id(BatchOperation.new, :checkbox_all)}").check
|
2023-01-30 17:03:30 +01:00
|
|
|
|
expect(page).to have_selector('#js_batch_select_more')
|
2023-01-23 09:42:35 +01:00
|
|
|
|
expect(page).to have_content('Les 2 dossiers de cette page sont sélectionnés. Sélectionner les 3 premiers dossiers sur les 4')
|
|
|
|
|
|
|
|
|
|
# click on selection link fill checkbox value with dossier_ids
|
|
|
|
|
click_on("Sélectionner les 3 premiers dossiers sur les 4")
|
|
|
|
|
expect(page).to have_content('3 dossiers sont sélectionnés. Effacer la sélection')
|
2023-01-24 17:59:39 +01:00
|
|
|
|
expect(find_field("batch_operation[dossier_ids][]", type: :hidden).value).to eq "#{dossier_4.id},#{dossier_3.id},#{dossier_2.id}"
|
2023-01-23 09:42:35 +01:00
|
|
|
|
|
|
|
|
|
# create batch
|
2023-07-06 11:15:41 +02:00
|
|
|
|
accept_alert do
|
|
|
|
|
click_on "Suivre les dossiers"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# reload
|
|
|
|
|
visit instructeur_procedure_path(procedure, statut: 'a-suivre')
|
2023-01-23 09:42:35 +01:00
|
|
|
|
|
2023-07-06 11:15:41 +02:00
|
|
|
|
expect(BatchOperation.count).to eq(1)
|
2023-01-23 09:42:35 +01:00
|
|
|
|
expect(BatchOperation.last.dossiers).to match_array([dossier_2, dossier_3, dossier_4])
|
|
|
|
|
end
|
2022-12-02 15:30:35 +01:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def log_in(email, password, check_email: true)
|
|
|
|
|
visit new_user_session_path
|
|
|
|
|
expect(page).to have_current_path(new_user_session_path)
|
|
|
|
|
|
|
|
|
|
sign_in_with(email, password, check_email)
|
|
|
|
|
|
|
|
|
|
expect(page).to have_current_path(instructeur_procedures_path)
|
|
|
|
|
end
|
|
|
|
|
end
|