diff --git a/app/views/instructeurs/procedures/show.html.haml b/app/views/instructeurs/procedures/show.html.haml index 78443dae5..c97aa3e24 100644 --- a/app/views/instructeurs/procedures/show.html.haml +++ b/app/views/instructeurs/procedures/show.html.haml @@ -83,7 +83,7 @@ %tr - if batch_operation_component.render? %th - %input{ type: "checkbox", data: { "batch-operation-target" => "all","action" => "batch-operation#onCheckAll"} } + %input{ type: "checkbox", data: { "batch-operation-target" => "all","action" => "batch-operation#onCheckAll"}, id: dom_id(BatchOperation.new, :checkbox_all), aria: { title: t('views.instructeurs.dossiers.select_all') } } - else - if @statut.in? %w(suivis traites tous) = render partial: "header_field", locals: { field: { "label" => "●", "table" => "notifications", "column" => "notifications" }, classname: "notification-col" } @@ -120,9 +120,9 @@ %td.folder-col - if batch_operation_component.render? - if p.batch_operation_id.present? - = check_box_tag :"batch_operation[dossier_ids][]", p.dossier_id, true, disabled: true + = check_box_tag :"batch_operation[dossier_ids][]", p.dossier_id, true, disabled: true, id: dom_id(BatchOperation.new, "checkbox_#{p.dossier_id}") - else - = check_box_tag :"batch_operation[dossier_ids][]", p.dossier_id, false, data: { "batch-operation-target" => "input", "action" => "batch-operation#onCheckOne"}, form: dom_id(BatchOperation.new) + = check_box_tag :"batch_operation[dossier_ids][]", p.dossier_id, false, data: { "batch-operation-target" => "input", "action" => "batch-operation#onCheckOne"}, form: dom_id(BatchOperation.new), id: dom_id(BatchOperation.new, "checkbox_#{p.dossier_id}") - else - if p.hidden_by_administration_at.present? %span.cell-link diff --git a/config/locales/en.yml b/config/locales/en.yml index 43d511510..01edce6a0 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -176,6 +176,7 @@ en: restore: "Restore" filters: title: Filter + select_all: Select all personalize: Personalize follow_file: Follow-up the file save: Save diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 503425589..37f42a6c4 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -171,6 +171,7 @@ fr: restore: "Restaurer" filters: title: Filtrer + select_all: Tout selectionner personalize: Personnaliser download: Télécharger un dossier follow_file: Suivre le dossier diff --git a/spec/system/instructeurs/batch_operation_spec.rb b/spec/system/instructeurs/batch_operation_spec.rb new file mode 100644 index 000000000..79af9e6ee --- /dev/null +++ b/spec/system/instructeurs/batch_operation_spec.rb @@ -0,0 +1,75 @@ +describe 'BatchOperation a dossier:', js: true do + 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) + visit instructeur_procedure_path(procedure, statut: 'traites') + # ensure button is disabled by default + expect(page).to have_selector('input[disabled][value="Archiver la sélection"]') + + checkbox_id = dom_id(BatchOperation.new, "checkbox_#{dossier_1.id}") + # batch one dossier + check(checkbox_id) + expect(page).to have_selector('input[value="Archiver la sélection"]') + + # ensure batch is created + expect { click_on "Archiver la sélection" } + .to change { BatchOperation.count } + .from(0).to(1) + + # ensure batched dossier is disabled + expect(page).to have_selector("##{checkbox_id}[disabled]") + + # ensure alert is present + expect(page).to have_content("Information : Une action de masse est en cours") + expect(page).to have_content("0/ 1 dossier archivé") + + # 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" + expect(page).to have_content("L'action de masse est terminée") + expect(page).to have_content("1 dossier a été archivé") + + # clean alert after reload + visit instructeur_procedure_path(procedure, statut: 'traites') + expect(page).not_to have_content("L'action de masse est terminée") + + # try checkall + find("##{dom_id(BatchOperation.new, :checkbox_all)}").check + [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 + + # submnit checkall + expect { click_on "Archiver la sélection" } + .to change { BatchOperation.count } + .from(1).to(2) + + expect(BatchOperation.last.dossiers).to match_array([dossier_2, dossier_3]) + end + 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