feat(attestation): tiptap default attestation

This commit is contained in:
Colin Darie 2024-01-29 16:38:14 +01:00
parent ce2ae53def
commit 7e02342518
No known key found for this signature in database
GPG key ID: 8C76CADD40253590
3 changed files with 52 additions and 2 deletions

View file

@ -87,7 +87,7 @@ module Administrateurs
end
def retrieve_attestation_template
@attestation_template = @procedure.attestation_template_v2 || @procedure.build_attestation_template_v2
@attestation_template = @procedure.attestation_template_v2 || @procedure.build_attestation_template_v2(json_body: AttestationTemplate::TIPTAP_BODY_DEFAULT)
end
def editor_params

View file

@ -21,6 +21,51 @@ class AttestationTemplate < ApplicationRecord
scope :v1, -> { where(version: 1) }
scope :v2, -> { where(version: 2) }
TIPTAP_BODY_DEFAULT = {
"type" => "doc",
"content" => [
{
"type" => "header",
"content" => [
{
"type" => "headerColumn",
"content" => [
{
"type" => "paragraph",
"attrs" => { "textAlign" => "left" },
"content" => [{ "type" => "mention", "attrs" => { "id" => "dossier_service_name", "label" => "nom du service" } }]
}
]
},
{
"type" => "headerColumn",
"content" => [
{
"type" => "paragraph",
"attrs" => { "textAlign" => "left" },
"content" => [
{ "text" => "Fait le ", "type" => "text" },
{ "type" => "mention", "attrs" => { "id" => "dossier_processed_at", "label" => "date de décision" } }
]
}
]
}
]
},
{ "type" => "title", "attrs" => { "textAlign" => "center" }, "content" => [{ "text" => "Titre de lattestation", "type" => "text" }] },
{
"type" => "paragraph",
"attrs" => { "textAlign" => "left" },
"content" => [
{
"text" => "Vous pouvez éditer ce texte pour personnaliser votre attestation. Pour ajouter du contenu issu du dossier, utilisez les balises situées sous cette zone de saisie.",
"type" => "text"
}
]
}
]
}.freeze
def attestation_for(dossier)
attestation = Attestation.new(title: replace_tags(title, dossier, escape: false))
attestation.pdf.attach(

View file

@ -102,7 +102,12 @@ describe 'As an administrateur, I want to manage the procedures attestation',
wait_until {
body = JSON.parse(attestation.reload.tiptap_body)
body.dig("content").first&.dig("content")&.first&.dig("content")&.first&.dig("content") == [{ "type" => "mention", "attrs" => { "id" => "dossier_processed_at", "label" => "date de décision" } }]
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
{ "type" => "mention", "attrs" => { "id" => "dossier_service_name", "label" => "nom du service" } } # defaut initial content
]
}
find("label", text: /à la charte de létat/).click