From dfb525892ad5d7f1d362b3dde13b413b021aa60a Mon Sep 17 00:00:00 2001
From: Martin <martin@sharypic.com>
Date: Thu, 29 Jun 2023 07:16:39 +0200
Subject: [PATCH] =?UTF-8?q?amelioration(instructeurs/dossiers/show):=20ETQ?=
 =?UTF-8?q?=20instructeur,=20je=20vois=20les=20champs=20saisi,=20les=20cha?=
 =?UTF-8?q?mps=20qui=20ont=20ete=20vid=C3=A9=20apres=20le=20depot=20du=20d?=
 =?UTF-8?q?ossier,=20je=20ne=20vois=20pas=20les=20champs=20facultatif=20ja?=
 =?UTF-8?q?mais=20saisis?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../dossiers/champ_row_show_component.rb      | 27 +++++++++++++++++++
 .../champ_row_show_component.html.haml        |  2 +-
 .../shared/dossiers/_champs.html.haml_spec.rb |  4 +--
 3 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/app/components/dossiers/champ_row_show_component.rb b/app/components/dossiers/champ_row_show_component.rb
index ecaead685..906f6c47f 100644
--- a/app/components/dossiers/champ_row_show_component.rb
+++ b/app/components/dossiers/champ_row_show_component.rb
@@ -28,4 +28,31 @@ class Dossiers::ChampRowShowComponent < ApplicationComponent
 
     key
   end
+
+  def each_champ(&block)
+    @champs.filter { show_champ?(_1) }.each(&block)
+  end
+
+  private
+
+  # champ.blank? is overloaded, disable the cop
+  # rubocop:disable Rails/Present
+  def show_champ?(champ)
+    if view_usager?
+      true
+    elsif champ.blank? && updated_after_deposer?(champ)
+      true
+    else
+      !champ.blank?
+    end
+  end
+  # rubocop:enable Rails/Present
+
+  def view_usager?
+    @profile == 'usager'
+  end
+
+  def view_instructeur?
+    @profile == 'instructeur'
+  end
 end
diff --git a/app/components/dossiers/champ_row_show_component/champ_row_show_component.html.haml b/app/components/dossiers/champ_row_show_component/champ_row_show_component.html.haml
index ba4abf1a2..9e9c3afb8 100644
--- a/app/components/dossiers/champ_row_show_component/champ_row_show_component.html.haml
+++ b/app/components/dossiers/champ_row_show_component/champ_row_show_component.html.haml
@@ -1,4 +1,4 @@
-- @champs.each do |champ|
+- each_champ do |champ|
   .fr-px-4v.fr-my-2v
     - if champ.repetition?
       %p.champ-label= "#{champ.libelle} :"
diff --git a/spec/views/shared/dossiers/_champs.html.haml_spec.rb b/spec/views/shared/dossiers/_champs.html.haml_spec.rb
index ccb808886..a76bfb578 100644
--- a/spec/views/shared/dossiers/_champs.html.haml_spec.rb
+++ b/spec/views/shared/dossiers/_champs.html.haml_spec.rb
@@ -112,7 +112,7 @@ describe 'shared/dossiers/champs', type: :view do
     let(:champ) { create(:champ_dossier_link, dossier: dossier, value: nil) }
     let(:champs) { [champ] }
 
-    it { is_expected.to include("non saisi") }
+    it { is_expected.not_to include("non saisi") }
 
     context 'when profile is usager' do
       let(:profile) { "usager" }
@@ -125,7 +125,7 @@ describe 'shared/dossiers/champs', type: :view do
     let(:champ) { create(:champ_without_piece_justificative, dossier:) }
     let(:champs) { [champ] }
 
-    it { is_expected.to include("pièce justificative non saisie") }
+    it { is_expected.not_to include("pièce justificative non saisie") }
 
     context 'when profile is usager' do
       let(:profile) { "usager" }