refactor(message): badges à corriger/en attente/corrigé when related to a correction

This commit is contained in:
Colin Darie 2023-06-02 15:46:23 +02:00
parent 52c8553576
commit 7f871728c7
No known key found for this signature in database
GPG key ID: 4FB865FDBCA4BCC4
7 changed files with 48 additions and 2 deletions

View file

@ -8,6 +8,13 @@ class Dossiers::MessageComponent < ApplicationComponent
attr_reader :commentaire, :connected_user, :messagerie_seen_at
def correction_badge
return if commentaire.dossier_correction.nil?
return helpers.correction_resolved_badge if commentaire.dossier_correction.resolved?
helpers.pending_correction_badge(connected_user.is_a?(Instructeur) ? :for_instructeur : :for_user)
end
private
def show_reply_button?

View file

@ -6,8 +6,9 @@
= commentaire_issuer
- if commentaire_from_guest?
%span.fr-text--xs.fr-text-mention--grey.font-weight-normal= t('.guest')
- if commentaire.flagged_pending_correction?
= helpers.pending_correction_badge(connected_user.is_a?(Instructeur) ? :for_instructeur : :for_user)
= correction_badge
%span.date{ class: ["fr-text--xs", "fr-text-mention--grey", "font-weight-normal", highlight_if_unseen_class], data: scroll_to_target }
= commentaire_date
.rich-text

View file

@ -98,6 +98,10 @@ module DossierHelper
tag.span(Dossier.human_attribute_name("pending_correction.#{for_profile}"), class: ['fr-badge fr-badge--sm fr-badge--warning super', html_class], role: 'status')
end
def correction_resolved_badge
tag.span(Dossier.human_attribute_name("pending_correction.resolved"), class: ['fr-badge fr-badge--sm fr-badge--success super'], role: 'status')
end
def demandeur_dossier(dossier)
if dossier.procedure.for_individual?
"#{dossier&.individual&.nom} #{dossier&.individual&.prenom}"

View file

@ -16,4 +16,8 @@ class DossierCorrection < ApplicationRecord
validates_associated :commentaire
scope :pending, -> { where(resolved_at: nil) }
def resolved?
resolved_at.present?
end
end

View file

@ -18,6 +18,7 @@ en:
pending_correction:
for_instructeur: "pending"
for_user: "to be corrected"
resolved: corrected
traitement:
state: "State"
traitement/state:

View file

@ -22,6 +22,7 @@ fr:
pending_correction:
for_instructeur: "en attente"
for_user:  corriger"
resolved: corrigé
traitement:
state: "État"
traitement/state:

View file

@ -144,4 +144,32 @@ RSpec.describe Dossiers::MessageComponent, type: :component do
end
end
end
describe '#correction_badge' do
let(:resolved_at) { nil }
before do
create(:dossier_correction, commentaire:, dossier:, resolved_at:)
end
it 'returns a badge à corriger' do
expect(subject).to have_text( corriger')
end
context 'connected as instructeur' do
let(:connected_user) { create(:instructeur) }
it 'returns a badge en attente' do
expect(subject).to have_text('en attente')
end
end
context 'when the correction is resolved' do
let(:resolved_at) { 1.minute.ago }
it 'returns a badge corrigé' do
expect(subject).to have_text("corrigé")
end
end
end
end