setup seen_at to hide alert when batch is finished and alert has been seen
This commit is contained in:
parent
6859882a58
commit
2615da1e28
3 changed files with 24 additions and 2 deletions
|
@ -5,4 +5,9 @@ class Dossiers::BatchAlertComponent < ApplicationComponent
|
|||
@batch = batch
|
||||
@procedure = procedure
|
||||
end
|
||||
|
||||
def set_seen_at!
|
||||
@batch.seen_at = Time.zone.now
|
||||
@batch.save
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,15 +1,17 @@
|
|||
.fr-mb-5v
|
||||
- if @batch.finished_and_success?
|
||||
- if @batch.finished_and_success? && @batch.seen_at.nil?
|
||||
= render Dsfr::AlertComponent.new(title: t('.finish.title'), state: :success) do |c|
|
||||
- c.body do
|
||||
%p
|
||||
= t('.finish.text_success', count: @batch.success_dossier_ids.count)
|
||||
- set_seen_at!
|
||||
|
||||
- if @batch.finished_and_fails?
|
||||
- if @batch.finished_and_fails? && @batch.seen_at.nil?
|
||||
= render Dsfr::AlertComponent.new(title: t('.finish.title'), state: :warning) do |c|
|
||||
- c.body do
|
||||
%p
|
||||
= t('.finish.text_fail', count: @batch.failed_dossier_ids.count)
|
||||
- set_seen_at!
|
||||
|
||||
- if @batch.beginning?
|
||||
= render Dsfr::AlertComponent.new(title: t('.in_progress.title'), state: :info) do |c|
|
||||
|
|
|
@ -39,6 +39,14 @@ RSpec.describe Dossiers::BatchAlertComponent, type: :component do
|
|||
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é archivés") }
|
||||
it { expect(batch_operation.seen_at).to eq(nil) }
|
||||
|
||||
it 'does not display alert on the next render' do
|
||||
render_inline(component).to_html
|
||||
expect(batch_operation.seen_at).not_to eq(nil)
|
||||
expect(subject).not_to have_text("2 dossiers ont été archivés")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context 'finished and fail' do
|
||||
|
@ -51,5 +59,12 @@ RSpec.describe Dossiers::BatchAlertComponent, type: :component do
|
|||
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 dossier n'a pas été archivé") }
|
||||
it { expect(batch_operation.seen_at).to eq(nil) }
|
||||
|
||||
it 'does not display alert on the next render' do
|
||||
render_inline(component).to_html
|
||||
expect(batch_operation.seen_at).not_to eq(nil)
|
||||
expect(subject).not_to have_text("2 dossiers ont été archivés")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue