From 25a7fa5a34115235f5b2df145907f2c5d092e67d Mon Sep 17 00:00:00 2001 From: Lisa Durand Date: Wed, 4 Jan 2023 11:51:22 +0100 Subject: [PATCH] add bulk action 'follow' --- .../batch_alert_component.en.yml | 9 +++ .../batch_alert_component.fr.yml | 9 +++ .../dossiers/batch_operation_component.rb | 17 +++++- .../batch_operation_component.en.yml | 1 + .../batch_operation_component.fr.yml | 1 + app/models/batch_operation.rb | 9 ++- .../dossiers/batch_alert_component_spec.rb | 55 +++++++++++++++++++ .../batch_operation_component_spec.rb | 5 ++ spec/factories/batch_operation.rb | 11 ++++ .../batch_operation_process_one_job_spec.rb | 14 +++++ 10 files changed, 126 insertions(+), 5 deletions(-) diff --git a/app/components/dossiers/batch_alert_component/batch_alert_component.en.yml b/app/components/dossiers/batch_alert_component/batch_alert_component.en.yml index efc78ad32..72be3351c 100644 --- a/app/components/dossiers/batch_alert_component/batch_alert_component.en.yml +++ b/app/components/dossiers/batch_alert_component/batch_alert_component.en.yml @@ -26,6 +26,15 @@ en: text_success: one: 1/1 is being accepted other: "%{progress_count}/%{count} files have been accepted" + follow: + finish: + text_success: + one: 1/1 file has been followed + other: "%{success_count}/%{count} files have been followed" + in_progress: + text_success: + one: 1/1 is being followed + other: "%{progress_count}/%{count} files have been followed" title: finish: The bulk action is finished in_progress: A bulk action is processing diff --git a/app/components/dossiers/batch_alert_component/batch_alert_component.fr.yml b/app/components/dossiers/batch_alert_component/batch_alert_component.fr.yml index de0427853..1149e373f 100644 --- a/app/components/dossiers/batch_alert_component/batch_alert_component.fr.yml +++ b/app/components/dossiers/batch_alert_component/batch_alert_component.fr.yml @@ -26,6 +26,15 @@ fr: text_success: one: 1 dossier sera accepté other: "%{progress_count}/%{count} dossiers ont été acceptés" + follow: + finish: + text_success: + one: 1 dossier a été suivi + other: "%{success_count}/%{count} dossiers ont été suivis" + in_progress: + text_success: + one: 1 dossier sera suivi + other: "%{progress_count}/%{count} dossiers ont été suivis" title: finish: L'action de masse est terminée in_progress: Une action de masse est en cours diff --git a/app/components/dossiers/batch_operation_component.rb b/app/components/dossiers/batch_operation_component.rb index 3de3bdf13..db9ac3573 100644 --- a/app/components/dossiers/batch_operation_component.rb +++ b/app/components/dossiers/batch_operation_component.rb @@ -7,11 +7,21 @@ class Dossiers::BatchOperationComponent < ApplicationComponent end def render? - ['traites', 'suivis'].include?(@statut) + ['a-suivre', 'traites', 'suivis'].include?(@statut) end def available_operations case @statut + when 'a-suivre' then + { + options: + [ + { + label: t(".operations.follow"), + operation: BatchOperation.operations.fetch(:follow) + } + ] + } when 'traites' then { options: @@ -47,9 +57,10 @@ class Dossiers::BatchOperationComponent < ApplicationComponent def icons { + accepter: 'fr-icon-success-line', archiver: 'fr-icon-folder-2-line', - passer_en_instruction: 'fr-icon-edit-line', - accepter: 'fr-icon-success-line' + follow: 'fr-icon-star-line', + passer_en_instruction: 'fr-icon-edit-line' } end end diff --git a/app/components/dossiers/batch_operation_component/batch_operation_component.en.yml b/app/components/dossiers/batch_operation_component/batch_operation_component.en.yml index 692414ffd..2811b976c 100644 --- a/app/components/dossiers/batch_operation_component/batch_operation_component.en.yml +++ b/app/components/dossiers/batch_operation_component/batch_operation_component.en.yml @@ -3,3 +3,4 @@ fr: archiver: 'Archive selected files' passer_en_instruction: 'Change selected files to instructing' accepter: 'Accept seleted files' + follow: 'Follow seleted files' diff --git a/app/components/dossiers/batch_operation_component/batch_operation_component.fr.yml b/app/components/dossiers/batch_operation_component/batch_operation_component.fr.yml index ae3044643..ab809deb9 100644 --- a/app/components/dossiers/batch_operation_component/batch_operation_component.fr.yml +++ b/app/components/dossiers/batch_operation_component/batch_operation_component.fr.yml @@ -3,3 +3,4 @@ fr: archiver: 'Archiver les dossiers sélectionnés' passer_en_instruction: 'Passer en instruction les dossiers sélectionnés' accepter: 'Accepter les dossiers sélectionnés' + follow: 'Suivre les dossiers sélectionnés' diff --git a/app/models/batch_operation.rb b/app/models/batch_operation.rb index d223a2afe..987d7ac2c 100644 --- a/app/models/batch_operation.rb +++ b/app/models/batch_operation.rb @@ -17,9 +17,10 @@ class BatchOperation < ApplicationRecord enum operation: { + accepter: 'accepter', archiver: 'archiver', - passer_en_instruction: 'passer_en_instruction', - accepter: 'accepter' + follow: 'follow', + passer_en_instruction: 'passer_en_instruction' } has_many :dossiers, dependent: :nullify @@ -58,6 +59,8 @@ class BatchOperation < ApplicationRecord query.state_en_construction when BatchOperation.operations.fetch(:accepter) then query.state_en_instruction + when BatchOperation.operations.fetch(:follow) then + query.without_followers end end @@ -74,6 +77,8 @@ class BatchOperation < ApplicationRecord dossier.passer_en_instruction(instructeur: instructeur) when BatchOperation.operations.fetch(:accepter) dossier.accepter(instructeur: instructeur, motivation: motivation, justificatif: justificatif_motivation) + when BatchOperation.operations.fetch(:follow) + instructeur.follow(dossier) end end diff --git a/spec/components/dossiers/batch_alert_component_spec.rb b/spec/components/dossiers/batch_alert_component_spec.rb index 44d19a308..de85d268e 100644 --- a/spec/components/dossiers/batch_alert_component_spec.rb +++ b/spec/components/dossiers/batch_alert_component_spec.rb @@ -110,6 +110,7 @@ RSpec.describe Dossiers::BatchAlertComponent, type: :component do end end end + describe 'accepter' do let(:component) do described_class.new( @@ -163,4 +164,58 @@ RSpec.describe Dossiers::BatchAlertComponent, type: :component do end end end + + describe 'follow' do + let(:component) do + described_class.new( + batch: batch_operation, + procedure: procedure + ) + end + let!(:dossier) { create(:dossier, :en_construction, procedure: procedure) } + let!(:dossier_2) { create(:dossier, :en_instruction, procedure: procedure) } + let!(:batch_operation) { create(:batch_operation, operation: :follow, dossiers: [dossier, dossier_2], instructeur: instructeur) } + + context 'in_progress' do + before { + batch_operation.track_processed_dossier(true, dossier) + batch_operation.reload + } + + it { is_expected.to have_selector('.fr-alert--info') } + it { is_expected.to have_text("Une action de masse est en cours") } + it { is_expected.to have_text("1/2 dossiers ont été suivis") } + end + + context 'finished and success' do + before { + batch_operation.track_processed_dossier(true, dossier) + batch_operation.track_processed_dossier(true, dossier_2) + batch_operation.reload + } + + it { is_expected.to have_selector('.fr-alert--success') } + it { is_expected.to have_text("L'action de masse est terminée") } + it { is_expected.to have_text("2 dossiers ont été suivis") } + it { expect(batch_operation.seen_at).to eq(nil) } + end + + context 'finished and fail' do + before { + batch_operation.track_processed_dossier(false, dossier) + batch_operation.track_processed_dossier(true, dossier_2) + batch_operation.reload + } + + it { is_expected.to have_selector('.fr-alert--warning') } + it { is_expected.to have_text("L'action de masse est terminée") } + it { is_expected.to have_text("1/2 dossiers ont été suivis") } + it { expect(batch_operation.seen_at).to eq(nil) } + + it 'on next render "seen_at" is set to avoid rendering alert' do + render_inline(component).to_html + expect(batch_operation.seen_at).not_to eq(nil) + end + end + end end diff --git a/spec/components/dossiers/batch_operation_component_spec.rb b/spec/components/dossiers/batch_operation_component_spec.rb index c7633f86b..909705042 100644 --- a/spec/components/dossiers/batch_operation_component_spec.rb +++ b/spec/components/dossiers/batch_operation_component_spec.rb @@ -25,6 +25,11 @@ RSpec.describe Dossiers::BatchOperationComponent, type: :component do it { is_expected.to have_link('Accepter les dossiers sélectionnés') } end + context 'statut a-suivre' do + let(:statut) { 'a-suivre' } + it { is_expected.to have_button('Suivre les dossiers sélectionnés', disabled: true) } + end + context 'statut tous' do let(:statut) { 'tous' } it { is_expected.not_to have_selector('button') } diff --git a/spec/factories/batch_operation.rb b/spec/factories/batch_operation.rb index 66e8b5930..454b7d5bf 100644 --- a/spec/factories/batch_operation.rb +++ b/spec/factories/batch_operation.rb @@ -39,5 +39,16 @@ FactoryBot.define do ] end end + + trait :follow do + operation { BatchOperation.operations.fetch(:follow) } + after(:build) do |batch_operation, evaluator| + procedure = create(:simple_procedure, :published, instructeurs: [evaluator.invalid_instructeur.presence || batch_operation.instructeur], administrateurs: [create(:administrateur)]) + batch_operation.dossiers = [ + create(:dossier, :with_individual, :en_instruction, procedure: procedure), + create(:dossier, :with_individual, :en_construction, procedure: procedure) + ] + end + end end end diff --git a/spec/jobs/batch_operation_process_one_job_spec.rb b/spec/jobs/batch_operation_process_one_job_spec.rb index 568576f6c..1e99caf73 100644 --- a/spec/jobs/batch_operation_process_one_job_spec.rb +++ b/spec/jobs/batch_operation_process_one_job_spec.rb @@ -46,6 +46,20 @@ describe BatchOperationProcessOneJob, type: :job do end end + context 'when operation is "follow"' do + let(:batch_operation) do + create(:batch_operation, :follow, + options.merge(instructeur: create(:instructeur))) + end + + it 'adds a follower to the dossier' do + expect { subject.perform_now } + .to change { dossier_job.reload.follows } + .from([]) + .to(anything) + end + end + context 'when operation is "accepter"' do let(:batch_operation) do create(:batch_operation, :accepter,