From fa0f72aaba8d49c3f087b4d54b93fc4a0d956fcb Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Tue, 31 Jan 2023 18:52:47 +0100 Subject: [PATCH] feat(procedure): hide estimated fill duration when super admin disabled it Closes #8466 --- .../estimated_fill_duration_component.rb | 4 ++ .../shared/_procedure_description.html.haml | 2 +- .../administrateurs/types_de_champ_spec.rb | 47 +++++++++++++------ .../_procedure_description.html.haml_spec.rb | 11 ++++- 4 files changed, 47 insertions(+), 17 deletions(-) diff --git a/app/components/types_de_champ_editor/estimated_fill_duration_component.rb b/app/components/types_de_champ_editor/estimated_fill_duration_component.rb index 54501d755..c78087c39 100644 --- a/app/components/types_de_champ_editor/estimated_fill_duration_component.rb +++ b/app/components/types_de_champ_editor/estimated_fill_duration_component.rb @@ -10,6 +10,10 @@ class TypesDeChampEditor::EstimatedFillDurationComponent < ApplicationComponent @is_annotation end + def render? + @revision.procedure.estimated_duration_visible? + end + def show? !annotations? && @revision.types_de_champ_public.present? end diff --git a/app/views/shared/_procedure_description.html.haml b/app/views/shared/_procedure_description.html.haml index 04d56263f..6d4fb669e 100644 --- a/app/views/shared/_procedure_description.html.haml +++ b/app/views/shared/_procedure_description.html.haml @@ -8,7 +8,7 @@ %h1.procedure-title = procedure.libelle -- if procedure.persisted? +- if procedure.persisted? && procedure.estimated_duration_visible? %p.procedure-configuration.procedure-configuration--fill-duration %span.icon.clock = t('shared.procedure_description.estimated_fill_duration', estimated_minutes: estimated_fill_duration_minutes(procedure)) diff --git a/spec/system/administrateurs/types_de_champ_spec.rb b/spec/system/administrateurs/types_de_champ_spec.rb index 22ca1ea3a..835f62a3e 100644 --- a/spec/system/administrateurs/types_de_champ_spec.rb +++ b/spec/system/administrateurs/types_de_champ_spec.rb @@ -1,6 +1,7 @@ describe 'As an administrateur I can edit types de champ', js: true do let(:administrateur) { procedure.administrateurs.first } - let(:procedure) { create(:procedure) } + let(:estimated_duration_visible) { true } + let(:procedure) { create(:procedure, estimated_duration_visible:) } before do login_as administrateur.user, scope: :user @@ -156,23 +157,39 @@ describe 'As an administrateur I can edit types de champ', js: true do expect(page).to have_content('Un menu') end - scenario "displaying the estimated fill duration" do - # It doesn't display anything when there are no champs - expect(page).not_to have_content('Durée de remplissage estimée') + context "estimated duration visible" do + scenario "displaying the estimated fill duration" do + # It doesn't display anything when there are no champs + expect(page).not_to have_content('Durée de remplissage estimée') - # It displays the estimate when adding a new champ - add_champ - select('Pièce justificative', from: 'Type de champ') - expect(page).to have_content('Durée de remplissage estimée : 2 min') + # It displays the estimate when adding a new champ + add_champ + select('Pièce justificative', from: 'Type de champ') + expect(page).to have_content('Durée de remplissage estimée : 2 min') - # It updates the estimate when updating the champ - check 'Champ obligatoire' - expect(page).to have_content('Durée de remplissage estimée : 3 min') + # It updates the estimate when updating the champ + check 'Champ obligatoire' + expect(page).to have_content('Durée de remplissage estimée : 3 min') - # It updates the estimate when removing the champ - page.accept_alert do - click_on 'Supprimer' + # It updates the estimate when removing the champ + page.accept_alert do + click_on 'Supprimer' + end + expect(page).not_to have_content('Durée de remplissage estimée') + end + end + + context "estimated duration not visible" do + let(:estimated_duration_visible) { false } + + scenario "hide the estimated fill duration" do + # It doesn't display anything when there are no champs + expect(page).not_to have_content('Durée de remplissage estimée') + + # It displays the estimate when adding a new champ + add_champ + select('Pièce justificative', from: 'Type de champ') + expect(page).not_to have_content('Durée de remplissage estimée') end - expect(page).not_to have_content('Durée de remplissage estimée') end end diff --git a/spec/views/shared/_procedure_description.html.haml_spec.rb b/spec/views/shared/_procedure_description.html.haml_spec.rb index a01b11b8a..d18a215a6 100644 --- a/spec/views/shared/_procedure_description.html.haml_spec.rb +++ b/spec/views/shared/_procedure_description.html.haml_spec.rb @@ -1,5 +1,6 @@ describe 'shared/_procedure_description.html.haml', type: :view do - let(:procedure) { create(:procedure, :published, :with_service) } + let(:estimated_duration_visible) { true } + let(:procedure) { create(:procedure, :published, :with_service, estimated_duration_visible:) } subject { render partial: 'shared/procedure_description', locals: { procedure: procedure } } @@ -11,6 +12,14 @@ describe 'shared/_procedure_description.html.haml', type: :view do expect(rendered).to have_text('Temps de remplissage estimé') end + context 'procedure with estimated duration not visible' do + let(:estimated_duration_visible) { false } + it 'hides the estimated duration' do + subject + expect(rendered).not_to have_text('Temps de remplissage estimé') + end + end + it 'does not show empty date limite' do subject expect(rendered).not_to have_text('Date limite')