Merge pull request #11094 from colinux/fix-procedure-errors-summary-attestation
ETQ admin, corrige l'affichage dans le récap de modifications d'une erreur existant dans l'attestation v2
This commit is contained in:
commit
467630c9d4
5 changed files with 55 additions and 53 deletions
|
@ -8,11 +8,7 @@ class Procedure::Card::AttestationComponent < ApplicationComponent
|
|||
private
|
||||
|
||||
def edit_attestation_path
|
||||
if @procedure.attestation_templates_v2.any? || @procedure.feature_enabled?(:attestation_v2)
|
||||
helpers.edit_admin_procedure_attestation_template_v2_path(@procedure)
|
||||
else
|
||||
helpers.edit_admin_procedure_attestation_template_path(@procedure)
|
||||
end
|
||||
helpers.edit_admin_procedure_attestation_template_v2_path(@procedure)
|
||||
end
|
||||
|
||||
def error_messages
|
||||
|
|
|
@ -43,7 +43,11 @@ class Procedure::ErrorsSummary < ApplicationComponent
|
|||
tdc = error.options[:type_de_champ]
|
||||
annotations_admin_procedure_path(@procedure, anchor: dom_id(tdc.stable_self, :editor_error))
|
||||
when :attestation_template
|
||||
edit_admin_procedure_attestation_template_path(@procedure)
|
||||
if error.detail[:value].version == 1
|
||||
edit_admin_procedure_attestation_template_path(@procedure)
|
||||
else
|
||||
edit_admin_procedure_attestation_template_v2_path(@procedure)
|
||||
end
|
||||
when :initiated_mail, :received_mail, :closed_mail, :refused_mail, :without_continuation_mail, :re_instructed_mail
|
||||
klass = "Mails::#{error.attribute.to_s.classify}".constantize
|
||||
edit_admin_procedure_mail_template_path(@procedure, klass.const_get(:SLUG))
|
||||
|
|
|
@ -76,8 +76,7 @@ module Administrateurs
|
|||
types_de_champ: [],
|
||||
revision_types_de_champ: { type_de_champ: { piece_justificative_template_attachment: :blob } }
|
||||
},
|
||||
attestation_template_v1: [],
|
||||
attestation_templates_v2: [],
|
||||
attestation_template: [],
|
||||
initiated_mail: [],
|
||||
received_mail: [],
|
||||
closed_mail: [],
|
||||
|
|
|
@ -88,20 +88,38 @@ describe Procedure::ErrorsSummary, type: :component do
|
|||
|
||||
let(:validation_context) { :publication }
|
||||
let(:procedure) { create(:procedure, attestation_template:, initiated_mail:) }
|
||||
let(:attestation_template) { build(:attestation_template) }
|
||||
let(:attestation_template) { build(:attestation_template, :v2) }
|
||||
let(:initiated_mail) { build(:initiated_mail) }
|
||||
|
||||
before do
|
||||
[:attestation_template, :initiated_mail].map { procedure.send(_1).update_column(:body, '--invalidtag--') }
|
||||
procedure.initiated_mail.update_column(:body, '--invalidtag--')
|
||||
procedure.draft_revision.update(ineligibilite_enabled: true, ineligibilite_rules: ds_eq(constant(true), constant(1)), ineligibilite_message: 'ko')
|
||||
|
||||
procedure.attestation_template.update_column(:json_body, { type: :doc, content: [{ type: :mention, attrs: { id: "tdc123", label: "oops" } }] })
|
||||
subject
|
||||
end
|
||||
|
||||
it 'render error nicely' do
|
||||
expect(page).to have_selector("a", text: "Les règles d’inéligibilité")
|
||||
expect(page).to have_selector("a", text: "Le modèle d’attestation")
|
||||
expect(page).to have_selector("a[href*='v2']", text: "Le modèle d’attestation")
|
||||
expect(page).to have_selector("a", text: "L’email de notification de passage de dossier en instruction")
|
||||
expect(page).to have_text("n'est pas valide", count: 2)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'render error for attestation v1' do
|
||||
let(:validation_context) { :publication }
|
||||
let(:procedure) { create(:procedure, attestation_template:) }
|
||||
let(:attestation_template) { build(:attestation_template) }
|
||||
|
||||
before do
|
||||
procedure.attestation_template.update_column(:body, '--invalidtag--')
|
||||
subject
|
||||
end
|
||||
|
||||
it 'render error nicely' do
|
||||
expect(page).to have_selector("a:not([href*='v2'])", text: "Le modèle d’attestation")
|
||||
expect(page).to have_text("n'est pas valide", count: 1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,21 +6,17 @@ describe 'As an administrateur, I want to manage the procedure’s attestation',
|
|||
include ProcedureSpecHelper
|
||||
|
||||
let(:administrateur) { administrateurs(:default_admin) }
|
||||
let(:procedure) do
|
||||
create(:procedure, :with_service, :with_instructeur, :with_zone,
|
||||
aasm_state: :brouillon,
|
||||
administrateurs: [administrateur],
|
||||
libelle: 'libellé de la procédure',
|
||||
path: 'libelle-de-la-procedure')
|
||||
|
||||
before do
|
||||
login_as(administrateur.user, scope: :user)
|
||||
Flipper.enable(:attestation_v2) # fully enabled on prod, pending removal in code
|
||||
|
||||
response = Typhoeus::Response.new(code: 200, body: 'Hello world')
|
||||
Typhoeus.stub(WEASYPRINT_URL).and_return(response)
|
||||
end
|
||||
before { login_as(administrateur.user, scope: :user) }
|
||||
|
||||
def find_attestation_card(with_nested_selector: nil)
|
||||
attestation_path = if procedure.attestation_template&.version == 2 || procedure.feature_enabled?(:attestation_v2)
|
||||
edit_admin_procedure_attestation_template_v2_path(procedure)
|
||||
else
|
||||
edit_admin_procedure_attestation_template_path(procedure)
|
||||
end
|
||||
attestation_path = edit_admin_procedure_attestation_template_v2_path(procedure)
|
||||
|
||||
full_selector = [
|
||||
"a[href=\"#{attestation_path}\"]",
|
||||
|
@ -29,46 +25,42 @@ describe 'As an administrateur, I want to manage the procedure’s attestation',
|
|||
page.find(full_selector)
|
||||
end
|
||||
|
||||
context 'Enable, publish, Disable' do
|
||||
context 'Update or disable v1' do
|
||||
let(:procedure) do
|
||||
create(:procedure, :published,
|
||||
administrateurs: [administrateur],
|
||||
attestation_template: build(:attestation_template))
|
||||
end
|
||||
|
||||
scenario do
|
||||
visit admin_procedure_path(procedure)
|
||||
# start with no attestation
|
||||
expect(page).to have_content('Désactivée')
|
||||
find_attestation_card(with_nested_selector: ".fr-badge")
|
||||
|
||||
expect(page).not_to have_content("Nouvel éditeur d’attestation")
|
||||
within find_attestation_card do
|
||||
expect(page).to have_content('Activée')
|
||||
click
|
||||
end
|
||||
|
||||
within('.fr-alert--info') do
|
||||
expect(page).to have_content("Nouvel éditeur d’attestation")
|
||||
click_on 'cliquez ici'
|
||||
end
|
||||
|
||||
# now process to enable attestation
|
||||
find_attestation_card.click
|
||||
fill_in "Titre de l’attestation", with: 'BOOM'
|
||||
fill_in "Contenu de l’attestation", with: 'BOOM'
|
||||
find('.toggle-switch-control').click
|
||||
click_on 'Enregistrer'
|
||||
|
||||
page.find(".alert-success", text: "Le modèle de l’attestation a bien été enregistré")
|
||||
|
||||
# check attestation
|
||||
visit admin_procedure_path(procedure)
|
||||
expect(page).to have_content('Activée')
|
||||
find_attestation_card(with_nested_selector: ".fr-badge--success")
|
||||
|
||||
# publish procedure
|
||||
# click CTA for publication screen
|
||||
click_on("Publier")
|
||||
# validate publication
|
||||
within('form') { click_on 'Publier' }
|
||||
click_on("Revenir à la page de la démarche")
|
||||
page.find(".alert-success", text: "Le modèle de l’attestation a bien été modifié")
|
||||
|
||||
# now process to disable attestation
|
||||
find_attestation_card.click
|
||||
find('.toggle-switch-control').click
|
||||
click_on 'Enregistrer'
|
||||
page.find(".alert-success", text: "Le modèle de l’attestation a bien été modifié")
|
||||
|
||||
# check attestation is now disabled
|
||||
visit admin_procedure_path(procedure)
|
||||
expect(page).to have_content('Désactivée')
|
||||
|
||||
find_attestation_card(with_nested_selector: ".fr-badge")
|
||||
expect(page).to have_content('Désactivée')
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -80,13 +72,6 @@ describe 'As an administrateur, I want to manage the procedure’s attestation',
|
|||
path: 'libelle-de-la-procedure')
|
||||
end
|
||||
|
||||
before do
|
||||
Flipper.enable(:attestation_v2)
|
||||
|
||||
response = Typhoeus::Response.new(code: 200, body: 'Hello world')
|
||||
Typhoeus.stub(WEASYPRINT_URL).and_return(response)
|
||||
end
|
||||
|
||||
scenario do
|
||||
visit admin_procedure_path(procedure)
|
||||
find_attestation_card(with_nested_selector: ".fr-badge")
|
||||
|
|
Loading…
Add table
Reference in a new issue