feat(procedure): hide estimated fill duration when super admin disabled it

Closes #8466
This commit is contained in:
Colin Darie 2023-01-31 18:52:47 +01:00
parent 8e35c0a465
commit fa0f72aaba
4 changed files with 47 additions and 17 deletions

View file

@ -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

View file

@ -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))

View file

@ -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

View file

@ -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')