From 725521c3a1687b211c2a53925671b1db224db252 Mon Sep 17 00:00:00 2001 From: Martin Date: Fri, 26 Nov 2021 14:31:30 +0100 Subject: [PATCH] fix(expiration_banner): only show expirations info when flip is enabled fix(lint): lint haml fix(spec): enable flipper and allow procedure to receive flipper check when checking banner presence fix(doc): add missing documentation on readme regarding system testing with a visual feedback fix(typo): add missing accent clean(PR): feedback from Tchak, better to wrap feature check for expirability by procedure within dossier.expirable? helper --- README.md | 4 ++ app/models/dossier.rb | 2 +- .../dossiers/_expiration_banner.html.haml | 37 ++++++---- app/views/shared/dossiers/_header.html.haml | 2 +- .../dossiers/_short_expires_message.html.haml | 9 --- .../users/dossiers/show/_header.html.haml | 2 +- spec/system/users/brouillon_spec.rb | 2 + .../_expiration_banner.html.haml_spec.rb | 68 +++++++++++++++++++ .../shared/dossiers/_header.html.haml_spec.rb | 56 --------------- 9 files changed, 101 insertions(+), 81 deletions(-) delete mode 100644 app/views/shared/dossiers/_short_expires_message.html.haml create mode 100644 spec/views/shared/dossiers/_expiration_banner.html.haml_spec.rb delete mode 100644 spec/views/shared/dossiers/_header.html.haml_spec.rb diff --git a/README.md b/README.md index 73acaae72..226ab9857 100644 --- a/README.md +++ b/README.md @@ -109,6 +109,10 @@ Pour exécuter les tests de l'application, plusieurs possibilités : bin/rspec --only-failures +- Lancer un ou des tests systèmes avec un browser + + NO_HEADLESS=1 bin/rspec spec/system + ### Ajout de taches à exécuter au déploiement rails generate after_party:task task_name diff --git a/app/models/dossier.rb b/app/models/dossier.rb index aebc6a385..08d12bf3d 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -545,7 +545,7 @@ class Dossier < ApplicationRecord end def expirable? - [brouillon?, en_construction?, termine?].any? + [brouillon?, en_construction?, termine? && procedure.feature_enabled?(:procedure_process_expired_dossiers_termine)].any? end def approximative_expiration_date_reference diff --git a/app/views/shared/dossiers/_expiration_banner.html.haml b/app/views/shared/dossiers/_expiration_banner.html.haml index 5f55b4be9..8f4689117 100644 --- a/app/views/shared/dossiers/_expiration_banner.html.haml +++ b/app/views/shared/dossiers/_expiration_banner.html.haml @@ -1,14 +1,25 @@ -- if dossier.expirable? && dossier.close_to_expiration? - .card.warning.mt-2.mb-3 - .card-title= t('shared.dossiers.header.banner.title') - %p - - if dossier.brouillon? - = t('shared.dossiers.header.banner.states.brouillon') - - elsif dossier.en_construction? - = t('shared.dossiers.header.banner.states.en_construction') - - elsif dossier.termine? - = t('shared.dossiers.header.banner.states.termine') +-# small expires mention +- if dossier.expirable? + %p.expires_at + %small= t("shared.dossiers.header.expires_at.#{dossier.state}", date: safe_expiration_date(dossier)) + -# big banner warning + - if dossier.close_to_expiration? + .card.warning.mt-2.mb-3 + .card-title= t('shared.dossiers.header.banner.title') + %p + - if dossier.brouillon? + = t('shared.dossiers.header.banner.states.brouillon') + - elsif dossier.en_construction? + = t('shared.dossiers.header.banner.states.en_construction') + - elsif dossier.termine? + = t('shared.dossiers.header.banner.states.termine') + + - if dossier.expiration_can_be_extended? + %br + = button_to t('shared.dossiers.header.banner.button_delay_expiration'), users_dossier_repousser_expiration_path(dossier), class: 'button secondary mt-2' + + +- else + %p.expires_at_en_instruction + %small= t("shared.dossiers.header.expires_at.en_instruction") - - if dossier.expiration_can_be_extended? - %br - = button_to t('shared.dossiers.header.banner.button_delay_expiration'), users_dossier_repousser_expiration_path(dossier), class: 'button secondary mt-2' diff --git a/app/views/shared/dossiers/_header.html.haml b/app/views/shared/dossiers/_header.html.haml index 056dceff1..c34c17f10 100644 --- a/app/views/shared/dossiers/_header.html.haml +++ b/app/views/shared/dossiers/_header.html.haml @@ -6,7 +6,7 @@ = t('views.users.dossiers.show.header.dossier_number', dossier_id: dossier.id) = t('views.users.dossiers.show.header.created_date', date_du_dossier: I18n.l(dossier.created_at)) - = render(partial: 'shared/dossiers/short_expires_message', locals: {dossier: dossier}) + = render(partial: 'shared/dossiers/expiration_banner', locals: {dossier: dossier}) .header-actions - if current_user.owns?(dossier) diff --git a/app/views/shared/dossiers/_short_expires_message.html.haml b/app/views/shared/dossiers/_short_expires_message.html.haml deleted file mode 100644 index 466c3f880..000000000 --- a/app/views/shared/dossiers/_short_expires_message.html.haml +++ /dev/null @@ -1,9 +0,0 @@ -- if dossier.expirable? - %p.expires_at - %small= t("shared.dossiers.header.expires_at.#{dossier.state}", date: safe_expiration_date(dossier)) -- else - %p.expires_at_en_instruction - %small= t("shared.dossiers.header.expires_at.en_instruction") - - -= render(partial: 'shared/dossiers/expiration_banner', locals: {dossier: dossier}) diff --git a/app/views/users/dossiers/show/_header.html.haml b/app/views/users/dossiers/show/_header.html.haml index 2985d024f..31f4bf110 100644 --- a/app/views/users/dossiers/show/_header.html.haml +++ b/app/views/users/dossiers/show/_header.html.haml @@ -10,7 +10,7 @@ - if dossier.en_construction_at.present? = t('views.users.dossiers.show.header.submit_date', date_du_dossier: I18n.l(dossier.en_construction_at)) - = render(partial: 'shared/dossiers/short_expires_message', locals: {dossier: dossier}) + = render(partial: 'shared/dossiers/expiration_banner', locals: {dossier: dossier}) - if current_user.owns?(dossier) diff --git a/spec/system/users/brouillon_spec.rb b/spec/system/users/brouillon_spec.rb index bc4c3f1b3..e0d6402f4 100644 --- a/spec/system/users/brouillon_spec.rb +++ b/spec/system/users/brouillon_spec.rb @@ -166,6 +166,8 @@ describe 'The user' do end scenario 'extends dossier experation date more than one time, ', js: true do + Flipper.enable(:procedure_process_expired_dossiers_termine) + allow(simple_procedure).to receive(:feature_enabled?).with(:procedure_process_expired_dossiers_termine).and_return(true) user_old_dossier = create(:dossier, procedure: simple_procedure, created_at: simple_procedure.duree_conservation_dossiers_dans_ds.month.ago, diff --git a/spec/views/shared/dossiers/_expiration_banner.html.haml_spec.rb b/spec/views/shared/dossiers/_expiration_banner.html.haml_spec.rb new file mode 100644 index 000000000..2f758db4e --- /dev/null +++ b/spec/views/shared/dossiers/_expiration_banner.html.haml_spec.rb @@ -0,0 +1,68 @@ +describe 'shared/dossiers/expiration_banner.html.haml', type: :view do + include DossierHelper + let(:dossier) { build(:dossier, state, attributes.merge(id: 1, state: state)) } + let(:i18n_key_state) { state } + subject do + render('shared/dossiers/expiration_banner.html.haml', + dossier: dossier, + current_user: build(:user)) + end + + context 'with procedure having procedure_process_expired_dossiers_termine not enabled' do + before { allow(dossier.procedure).to receive(:feature_enabled?).with(:procedure_process_expired_dossiers_termine).and_return(false) } + let(:attributes) { { processed_at: 6.months.ago } } + let(:state) { :accepte } + + it 'render estimated expiration date' do + expect(subject).not_to have_selector('.expires_at') + end + end + + context 'with procedure having procedure_process_expired_dossiers_termine enabled' do + before { allow(dossier.procedure).to receive(:feature_enabled?).with(:procedure_process_expired_dossiers_termine).and_return(true) } + + context 'with dossier.brouillon?' do + let(:attributes) { { created_at: 6.months.ago } } + let(:state) { :brouillon } + + it 'render estimated expiration date' do + expect(subject).to have_selector('.expires_at', + text: I18n.t("shared.dossiers.header.expires_at.#{i18n_key_state}", + date: safe_expiration_date(dossier))) + end + end + + context 'with dossier.en_construction?' do + let(:attributes) { { en_construction_at: 6.months.ago } } + let(:state) { :en_construction } + + it 'render estimated expiration date' do + expect(subject).to have_selector('.expires_at', + text: I18n.t("shared.dossiers.header.expires_at.#{i18n_key_state}", + date: safe_expiration_date(dossier))) + end + end + + context 'with dossier.en_instruction?' do + let(:state) { :en_instruction } + let(:attributes) { {} } + + it 'render estimated expiration date' do + expect(subject).to have_selector('p.expires_at_en_instruction', + text: I18n.t("shared.dossiers.header.expires_at.#{i18n_key_state}")) + end + end + + context 'with dossier.en_processed_at?' do + let(:state) { :accepte } + let(:attributes) { {} } + + it 'render estimated expiration date' do + allow(dossier).to receive(:processed_at).and_return(6.months.ago) + expect(subject).to have_selector('.expires_at', + text: I18n.t("shared.dossiers.header.expires_at.#{i18n_key_state}", + date: safe_expiration_date(dossier))) + end + end + end +end diff --git a/spec/views/shared/dossiers/_header.html.haml_spec.rb b/spec/views/shared/dossiers/_header.html.haml_spec.rb deleted file mode 100644 index 25567efea..000000000 --- a/spec/views/shared/dossiers/_header.html.haml_spec.rb +++ /dev/null @@ -1,56 +0,0 @@ -describe 'shared/dossiers/short_expires_message.html.haml', type: :view do - include DossierHelper - let(:dossier) do - build(:dossier, state, attributes.merge(id: 1, state: state)) - end - let(:i18n_key_state) { state } - subject do - render('shared/dossiers/short_expires_message.html.haml', - dossier: dossier, - current_user: build(:user)) - end - - context 'with dossier.brouillon?' do - let(:attributes) { { created_at: 6.months.ago } } - let(:state) { :brouillon } - - it 'render estimated expiration date' do - expect(subject).to have_selector('.expires_at', - text: I18n.t("shared.dossiers.header.expires_at.#{i18n_key_state}", - date: safe_expiration_date(dossier))) - end - end - - context 'with dossier.en_construction?' do - let(:attributes) { { en_construction_at: 6.months.ago } } - let(:state) { :en_construction } - - it 'render estimated expiration date' do - expect(subject).to have_selector('.expires_at', - text: I18n.t("shared.dossiers.header.expires_at.#{i18n_key_state}", - date: safe_expiration_date(dossier))) - end - end - - context 'with dossier.en_instruction?' do - let(:state) { :en_instruction } - let(:attributes) { {} } - - it 'render estimated expiration date' do - expect(subject).to have_selector('p.expires_at_en_instruction', - text: I18n.t("shared.dossiers.header.expires_at.#{i18n_key_state}")) - end - end - - context 'with dossier.en_processed_at?' do - let(:state) { :accepte } - let(:attributes) { {} } - - it 'render estimated expiration date' do - allow(dossier).to receive(:processed_at).and_return(6.months.ago) - expect(subject).to have_selector('.expires_at', - text: I18n.t("shared.dossiers.header.expires_at.#{i18n_key_state}", - date: safe_expiration_date(dossier))) - end - end -end