refactor(admin): attestation v2 fully enabled, remove useless extra query
This commit is contained in:
parent
4eeaba5e60
commit
55c7eb422f
2 changed files with 28 additions and 47 deletions
|
@ -8,11 +8,7 @@ class Procedure::Card::AttestationComponent < ApplicationComponent
|
||||||
private
|
private
|
||||||
|
|
||||||
def edit_attestation_path
|
def edit_attestation_path
|
||||||
if @procedure.attestation_templates_v2.any? || @procedure.feature_enabled?(:attestation_v2)
|
helpers.edit_admin_procedure_attestation_template_v2_path(@procedure)
|
||||||
helpers.edit_admin_procedure_attestation_template_v2_path(@procedure)
|
|
||||||
else
|
|
||||||
helpers.edit_admin_procedure_attestation_template_path(@procedure)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def error_messages
|
def error_messages
|
||||||
|
|
|
@ -6,21 +6,17 @@ describe 'As an administrateur, I want to manage the procedure’s attestation',
|
||||||
include ProcedureSpecHelper
|
include ProcedureSpecHelper
|
||||||
|
|
||||||
let(:administrateur) { administrateurs(:default_admin) }
|
let(:administrateur) { administrateurs(:default_admin) }
|
||||||
let(:procedure) do
|
|
||||||
create(:procedure, :with_service, :with_instructeur, :with_zone,
|
before do
|
||||||
aasm_state: :brouillon,
|
login_as(administrateur.user, scope: :user)
|
||||||
administrateurs: [administrateur],
|
Flipper.enable(:attestation_v2) # fully enabled on prod, pending removal in code
|
||||||
libelle: 'libellé de la procédure',
|
|
||||||
path: 'libelle-de-la-procedure')
|
response = Typhoeus::Response.new(code: 200, body: 'Hello world')
|
||||||
|
Typhoeus.stub(WEASYPRINT_URL).and_return(response)
|
||||||
end
|
end
|
||||||
before { login_as(administrateur.user, scope: :user) }
|
|
||||||
|
|
||||||
def find_attestation_card(with_nested_selector: nil)
|
def find_attestation_card(with_nested_selector: nil)
|
||||||
attestation_path = if procedure.attestation_template&.version == 2 || procedure.feature_enabled?(:attestation_v2)
|
attestation_path = edit_admin_procedure_attestation_template_v2_path(procedure)
|
||||||
edit_admin_procedure_attestation_template_v2_path(procedure)
|
|
||||||
else
|
|
||||||
edit_admin_procedure_attestation_template_path(procedure)
|
|
||||||
end
|
|
||||||
|
|
||||||
full_selector = [
|
full_selector = [
|
||||||
"a[href=\"#{attestation_path}\"]",
|
"a[href=\"#{attestation_path}\"]",
|
||||||
|
@ -29,46 +25,42 @@ describe 'As an administrateur, I want to manage the procedure’s attestation',
|
||||||
page.find(full_selector)
|
page.find(full_selector)
|
||||||
end
|
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
|
scenario do
|
||||||
visit admin_procedure_path(procedure)
|
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 "Titre de l’attestation", with: 'BOOM'
|
||||||
fill_in "Contenu de l’attestation", with: 'BOOM'
|
fill_in "Contenu de l’attestation", with: 'BOOM'
|
||||||
find('.toggle-switch-control').click
|
|
||||||
click_on 'Enregistrer'
|
click_on 'Enregistrer'
|
||||||
|
|
||||||
page.find(".alert-success", text: "Le modèle de l’attestation a bien été enregistré")
|
page.find(".alert-success", text: "Le modèle de l’attestation a bien été modifié")
|
||||||
|
|
||||||
# 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")
|
|
||||||
|
|
||||||
# now process to disable attestation
|
# now process to disable attestation
|
||||||
find_attestation_card.click
|
|
||||||
find('.toggle-switch-control').click
|
find('.toggle-switch-control').click
|
||||||
click_on 'Enregistrer'
|
click_on 'Enregistrer'
|
||||||
page.find(".alert-success", text: "Le modèle de l’attestation a bien été modifié")
|
page.find(".alert-success", text: "Le modèle de l’attestation a bien été modifié")
|
||||||
|
|
||||||
# check attestation is now disabled
|
# check attestation is now disabled
|
||||||
visit admin_procedure_path(procedure)
|
visit admin_procedure_path(procedure)
|
||||||
expect(page).to have_content('Désactivée')
|
|
||||||
find_attestation_card(with_nested_selector: ".fr-badge")
|
find_attestation_card(with_nested_selector: ".fr-badge")
|
||||||
|
expect(page).to have_content('Désactivée')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -80,13 +72,6 @@ describe 'As an administrateur, I want to manage the procedure’s attestation',
|
||||||
path: 'libelle-de-la-procedure')
|
path: 'libelle-de-la-procedure')
|
||||||
end
|
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
|
scenario do
|
||||||
visit admin_procedure_path(procedure)
|
visit admin_procedure_path(procedure)
|
||||||
find_attestation_card(with_nested_selector: ".fr-badge")
|
find_attestation_card(with_nested_selector: ".fr-badge")
|
||||||
|
|
Loading…
Add table
Reference in a new issue