feat(attestation): can enable/disable attestation no matter the state of the procedure

This commit is contained in:
Martin 2022-01-04 14:44:17 +01:00
parent 7eddbd5238
commit a9ffaf942e
2 changed files with 64 additions and 11 deletions

View file

@ -19,10 +19,6 @@
- else
%span.text-inactive désactivée
- if @attestation_template.activated && @procedure.locked?
.card.warning
%p Lattestation ne peut plus être désactivée car la démarche est publiée.
%p.notice
Lattestation, si elle est activée, est émise au moment où un dossier est accepté.
%br
@ -33,13 +29,11 @@
.procedure-form__actions.sticky--bottom
.actions-left
-# Admins cannot disactivate the Attestation if it is activated and the procedure is published
- if !(@attestation_template.activated && @procedure.locked?)
%label.toggle-switch
= f.check_box :activated, class: 'toggle-switch-checkbox'
%span.toggle-switch-control.round
%span.toggle-switch-label.on Attestation activée
%span.toggle-switch-label.off Attestation désactivée
%label.toggle-switch
= f.check_box :activated, class: 'toggle-switch-checkbox'
%span.toggle-switch-control.round
%span.toggle-switch-label.on Attestation activée
%span.toggle-switch-label.off Attestation désactivée
.actions-right
= link_to 'Annuler', edit_admin_procedure_attestation_template_path(id: @procedure), class: 'button', data: { confirm: 'Êtes-vous sûr de vouloir annuler les modifications effectuées ?'}

View file

@ -0,0 +1,59 @@
require 'system/administrateurs/procedure_spec_helper'
describe 'As an administrateur, I want to manage the procedures attestation', js: true do
include ProcedureSpecHelper
let(:administrateur) { create(:administrateur) }
let(:procedure) do
create(:procedure, :with_service, :with_instructeur,
aasm_state: :brouillon,
administrateurs: [administrateur],
libelle: 'libellé de la procédure',
path: 'libelle-de-la-procedure')
end
before { login_as(administrateur.user, scope: :user) }
def find_attestation_card(with_nested_selector: nil)
full_selector = [
".card-admin[href=\"#{edit_admin_procedure_attestation_template_path(procedure)}\"]",
with_nested_selector
].compact.join(" ")
page.find(full_selector)
end
context 'Enable, publish, Disable' do
scenario do
visit admin_procedure_path(procedure)
# start with no attestation
find_attestation_card(with_nested_selector: ".icon.clock")
# now process to enable attestation
find_attestation_card.click
fill_in "Titre de l'attestation", with: 'BOOM'
fill_in "Corps du document", with: 'BOOM'
find('.toggle-switch-control').click
click_on 'Enregistrer'
page.find(".alert-success", text: "L'attestation a bien été sauvegardée")
# check attestation
visit admin_procedure_path(procedure)
find_attestation_card(with_nested_selector: ".icon.accept")
# publish procedure
# click CTA for publication screen
click_on("Publier")
# validate publication
click_on("Publier")
# now process to disable attestation
find_attestation_card.click
find('.toggle-switch-control').click
click_on 'Enregistrer'
page.find(".alert-success", text: "L'attestation a bien été modifiée")
# check attestation is now disabled
visit admin_procedure_path(procedure)
find_attestation_card(with_nested_selector: ".icon.clock")
end
end
end