add action 'unfollow' to page 'suivis'

This commit is contained in:
Lisa Durand 2023-01-13 15:09:24 +01:00
parent 2f666b487e
commit 06c6a4ab0c
11 changed files with 119 additions and 5 deletions

View file

@ -219,6 +219,60 @@ RSpec.describe Dossiers::BatchAlertComponent, type: :component do
end
end
describe 'unfollow' do
let(:component) do
described_class.new(
batch: batch_operation,
procedure: procedure
)
end
let!(:dossier) { create(:dossier, :en_construction, :followed, procedure: procedure) }
let!(:dossier_2) { create(:dossier, :en_instruction, :followed, procedure: procedure) }
let!(:batch_operation) { create(:batch_operation, operation: :unfollow, 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 ne sont plus 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 ne sont plus 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 ne sont plus 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
describe 'repasser en construction' do
let(:component) do
described_class.new(

View file

@ -22,7 +22,9 @@ RSpec.describe Dossiers::BatchOperationComponent, type: :component do
let(:statut) { 'suivis' }
it { is_expected.to have_button('Passer les dossiers en instruction', disabled: true) }
it { is_expected.to have_button('Accepter les dossiers', disabled: true) }
it { is_expected.to have_button('Repasser les dossiers en construction', disabled: true) }
it { is_expected.to have_link('Repasser les dossiers en construction', disabled: true) }
it { is_expected.to have_link('Ne plus suivre les dossiers', disabled: true) }
it { is_expected.to have_button('Autres actions multiples', disabled: true) }
end
context 'statut a-suivre' do

View file

@ -51,6 +51,17 @@ FactoryBot.define do
end
end
trait :unfollow do
operation { BatchOperation.operations.fetch(:unfollow) }
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, :followed, :en_instruction, procedure: procedure),
create(:dossier, :with_individual, :followed, :en_construction, procedure: procedure)
]
end
end
trait :repasser_en_construction do
operation { BatchOperation.operations.fetch(:repasser_en_construction) }
after(:build) do |batch_operation, evaluator|

View file

@ -60,6 +60,21 @@ describe BatchOperationProcessOneJob, type: :job do
end
end
context 'when operation is "unfollow"' do
let(:batch_operation) do
create(:batch_operation, :unfollow,
options.merge(instructeur: create(:instructeur)))
end
it 'removes a follower to the dossier' do
expect { subject.perform_now }
.to change { dossier_job.reload.follows.first.unfollowed_at }
.from(nil)
.to(anything)
end
end
context 'when operation is "repasser en construction"' do
let(:batch_operation) do
create(:batch_operation, :repasser_en_construction,