2024-04-29 00:17:15 +02:00
|
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2022-01-04 14:44:17 +01:00
|
|
|
|
require 'system/administrateurs/procedure_spec_helper'
|
|
|
|
|
|
2023-11-06 15:15:51 +01:00
|
|
|
|
describe 'As an administrateur, I want to manage the procedure’s attestation', js: true do
|
2022-01-04 14:44:17 +01:00
|
|
|
|
include ProcedureSpecHelper
|
|
|
|
|
|
2024-06-01 22:50:48 +02:00
|
|
|
|
let(:administrateur) { administrateurs(:default_admin) }
|
2022-01-04 14:44:17 +01:00
|
|
|
|
let(:procedure) do
|
2022-12-20 11:21:52 +01:00
|
|
|
|
create(:procedure, :with_service, :with_instructeur, :with_zone,
|
2022-01-04 14:44:17 +01:00
|
|
|
|
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)
|
2024-05-29 21:47:09 +02:00
|
|
|
|
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
|
|
|
|
|
|
2022-01-04 14:44:17 +01:00
|
|
|
|
full_selector = [
|
2024-05-29 21:47:09 +02:00
|
|
|
|
"a[href=\"#{attestation_path}\"]",
|
2022-01-04 14:44:17 +01:00
|
|
|
|
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
|
2023-11-15 15:54:19 +01:00
|
|
|
|
expect(page).to have_content('Désactivée')
|
|
|
|
|
find_attestation_card(with_nested_selector: ".fr-badge")
|
2022-01-04 14:44:17 +01:00
|
|
|
|
|
2024-01-22 17:29:24 +01:00
|
|
|
|
expect(page).not_to have_content("Nouvel éditeur d’attestation")
|
|
|
|
|
|
2022-01-04 14:44:17 +01:00
|
|
|
|
# now process to enable attestation
|
|
|
|
|
find_attestation_card.click
|
2022-12-15 13:08:20 +01:00
|
|
|
|
fill_in "Titre de l’attestation", with: 'BOOM'
|
2022-12-16 14:56:46 +01:00
|
|
|
|
fill_in "Contenu de l’attestation", with: 'BOOM'
|
2022-01-04 14:44:17 +01:00
|
|
|
|
find('.toggle-switch-control').click
|
|
|
|
|
click_on 'Enregistrer'
|
2022-12-15 13:08:20 +01:00
|
|
|
|
|
|
|
|
|
page.find(".alert-success", text: "Le modèle de l’attestation a bien été enregistré")
|
2022-01-04 14:44:17 +01:00
|
|
|
|
|
|
|
|
|
# check attestation
|
|
|
|
|
visit admin_procedure_path(procedure)
|
2023-11-15 15:54:19 +01:00
|
|
|
|
expect(page).to have_content('Activée')
|
|
|
|
|
find_attestation_card(with_nested_selector: ".fr-badge--success")
|
2022-01-04 14:44:17 +01:00
|
|
|
|
|
|
|
|
|
# publish procedure
|
|
|
|
|
# click CTA for publication screen
|
|
|
|
|
click_on("Publier")
|
|
|
|
|
# validate publication
|
2023-10-10 16:51:06 +02:00
|
|
|
|
within('form') { click_on 'Publier' }
|
2023-11-06 17:46:22 +01:00
|
|
|
|
click_on("Revenir à la page de la démarche")
|
2022-01-04 14:44:17 +01:00
|
|
|
|
|
|
|
|
|
# now process to disable attestation
|
|
|
|
|
find_attestation_card.click
|
|
|
|
|
find('.toggle-switch-control').click
|
|
|
|
|
click_on 'Enregistrer'
|
2022-12-15 13:08:20 +01:00
|
|
|
|
page.find(".alert-success", text: "Le modèle de l’attestation a bien été modifié")
|
2022-01-04 14:44:17 +01:00
|
|
|
|
|
|
|
|
|
# check attestation is now disabled
|
|
|
|
|
visit admin_procedure_path(procedure)
|
2023-11-15 15:54:19 +01:00
|
|
|
|
expect(page).to have_content('Désactivée')
|
|
|
|
|
find_attestation_card(with_nested_selector: ".fr-badge")
|
2022-01-04 14:44:17 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
2024-01-22 17:29:24 +01:00
|
|
|
|
|
|
|
|
|
context 'Update attestation v2' do
|
2024-06-06 14:48:50 +02:00
|
|
|
|
let(:procedure) do
|
|
|
|
|
create(:procedure, :published,
|
|
|
|
|
administrateurs: [administrateur],
|
|
|
|
|
libelle: 'libellé de la procédure',
|
|
|
|
|
path: 'libelle-de-la-procedure')
|
|
|
|
|
end
|
|
|
|
|
|
2024-03-14 14:04:43 +01:00
|
|
|
|
before do
|
|
|
|
|
Flipper.enable(:attestation_v2)
|
|
|
|
|
|
|
|
|
|
response = Typhoeus::Response.new(code: 200, body: 'Hello world')
|
|
|
|
|
Typhoeus.stub(WEASYPRINT_URL).and_return(response)
|
|
|
|
|
end
|
2024-01-22 17:29:24 +01:00
|
|
|
|
|
|
|
|
|
scenario do
|
|
|
|
|
visit admin_procedure_path(procedure)
|
|
|
|
|
find_attestation_card(with_nested_selector: ".fr-badge")
|
|
|
|
|
|
|
|
|
|
find_attestation_card.click
|
|
|
|
|
|
2024-05-28 17:47:05 +02:00
|
|
|
|
expect(procedure.reload.attestation_templates.v2).to be_empty
|
2024-01-22 17:29:24 +01:00
|
|
|
|
|
|
|
|
|
expect(page).to have_css("label", text: "Logo additionnel")
|
|
|
|
|
|
2024-01-25 13:20:43 +01:00
|
|
|
|
fill_in "Intitulé de votre institution", with: "System Test"
|
2024-01-22 17:29:24 +01:00
|
|
|
|
fill_in "Intitulé de la direction", with: "The boss"
|
|
|
|
|
|
|
|
|
|
attestation = nil
|
|
|
|
|
wait_until {
|
2024-05-28 17:47:05 +02:00
|
|
|
|
attestation = procedure.reload.attestation_templates.v2.draft.first
|
2024-01-22 17:29:24 +01:00
|
|
|
|
attestation.present?
|
|
|
|
|
}
|
2024-06-07 10:22:01 +02:00
|
|
|
|
expect(page).to have_content("Attestation enregistrée")
|
2024-01-22 17:29:24 +01:00
|
|
|
|
expect(attestation.label_logo).to eq("System Test")
|
2024-06-06 14:48:50 +02:00
|
|
|
|
expect(attestation.activated?).to be_truthy
|
2024-01-22 17:29:24 +01:00
|
|
|
|
|
|
|
|
|
click_on "date de décision"
|
|
|
|
|
|
|
|
|
|
# TODO find a way to fill in tiptap
|
|
|
|
|
|
|
|
|
|
attach_file('Tampon ou signature', Rails.root + 'spec/fixtures/files/white.png')
|
|
|
|
|
wait_until { attestation.reload.signature.attached? }
|
|
|
|
|
|
|
|
|
|
fill_in "Contenu du pied de page", with: "Footer"
|
|
|
|
|
|
|
|
|
|
wait_until {
|
|
|
|
|
body = JSON.parse(attestation.reload.tiptap_body)
|
2024-01-29 16:38:14 +01:00
|
|
|
|
first_content = body.dig("content").first&.dig("content")&.first&.dig("content")&.first&.dig("content")
|
|
|
|
|
|
|
|
|
|
first_content == [
|
|
|
|
|
{ "type" => "mention", "attrs" => { "id" => "dossier_processed_at", "label" => "date de décision" } }, # added by click above
|
2024-01-31 17:02:02 +01:00
|
|
|
|
{ "type" => "text", "text" => " " },
|
2024-01-29 16:38:14 +01:00
|
|
|
|
{ "type" => "mention", "attrs" => { "id" => "dossier_service_name", "label" => "nom du service" } } # defaut initial content
|
|
|
|
|
]
|
2024-01-22 17:29:24 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
find("label", text: /à la charte de l’état/).click
|
|
|
|
|
|
|
|
|
|
expect(page).not_to have_css("label", text: "Logo additionnel", visible: true)
|
|
|
|
|
expect(page).not_to have_css("label", text: "Intitulé du logo", visible: true)
|
|
|
|
|
|
|
|
|
|
attach_file('Logo', Rails.root + 'spec/fixtures/files/black.png')
|
|
|
|
|
|
|
|
|
|
wait_until {
|
|
|
|
|
attestation.reload.logo.attached? && attestation.signature.attached? && !attestation.official_layout?
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fill_in "Contenu du pied de page", with: ["line1", "line2", "line3", "line4"].join("\n")
|
2024-09-11 11:32:49 +02:00
|
|
|
|
# FIXME we should get line1\nline2\nline3line4 instead of line1\nline2\nline3\nline4 because row is set to 3
|
|
|
|
|
expect(page).to have_field("Contenu du pied de page", with: "line1\nline2\nline3\nline4")
|
2024-05-28 17:47:05 +02:00
|
|
|
|
|
|
|
|
|
click_on "Publier"
|
|
|
|
|
expect(attestation.reload).to be_published
|
2024-06-06 14:48:50 +02:00
|
|
|
|
expect(page).to have_text("L’attestation a été publiée")
|
|
|
|
|
|
|
|
|
|
fill_in "Intitulé de la direction", with: "plop"
|
|
|
|
|
click_on "Publier les modifications"
|
|
|
|
|
expect(procedure.reload.attestation_template.label_direction).to eq("plop")
|
|
|
|
|
expect(page).to have_text(/La nouvelle version de l’attestation/)
|
2024-01-22 17:29:24 +01:00
|
|
|
|
end
|
2024-02-01 18:55:41 +01:00
|
|
|
|
|
|
|
|
|
context "tag in error" do
|
|
|
|
|
before do
|
|
|
|
|
tdc = procedure.active_revision.add_type_de_champ(type_champ: :integer_number, libelle: 'age')
|
|
|
|
|
procedure.publish_revision!
|
|
|
|
|
|
2024-05-28 17:47:05 +02:00
|
|
|
|
attestation = procedure.build_attestation_template(version: 2, json_body: AttestationTemplate::TIPTAP_BODY_DEFAULT, label_logo: "test")
|
2024-02-01 18:55:41 +01:00
|
|
|
|
attestation.json_body["content"] << { type: :mention, attrs: { id: "tdc#{tdc.stable_id}", label: tdc.libelle } }
|
|
|
|
|
attestation.save!
|
|
|
|
|
|
|
|
|
|
procedure.draft_revision.remove_type_de_champ(tdc)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
scenario do
|
|
|
|
|
visit edit_admin_procedure_attestation_template_v2_path(procedure)
|
|
|
|
|
expect(page).to have_content("Le champ « Contenu de l’attestation » contient la balise \"age\"")
|
|
|
|
|
|
|
|
|
|
click_on "date de décision"
|
|
|
|
|
|
2024-06-07 10:22:01 +02:00
|
|
|
|
expect(page).to have_content("Attestation en erreur")
|
2024-02-01 18:55:41 +01:00
|
|
|
|
expect(page).to have_content("Le champ « Contenu de l’attestation » contient la balise \"age\"")
|
|
|
|
|
|
|
|
|
|
page.execute_script("document.getElementById('attestation_template_tiptap_body').type = 'text'")
|
|
|
|
|
fill_in "attestation_template[tiptap_body]", with: AttestationTemplate::TIPTAP_BODY_DEFAULT.to_json
|
|
|
|
|
|
2024-06-07 10:22:01 +02:00
|
|
|
|
expect(page).to have_content("Attestation enregistrée")
|
|
|
|
|
expect(page).not_to have_content("Attestation en erreur")
|
2024-02-01 18:55:41 +01:00
|
|
|
|
expect(page).not_to have_content("Le champ « Contenu de l’attestation » contient la balise \"age\"")
|
|
|
|
|
end
|
|
|
|
|
end
|
2024-01-22 17:29:24 +01:00
|
|
|
|
end
|
2022-01-04 14:44:17 +01:00
|
|
|
|
end
|