Merge pull request #10584 from colinux/attestation-render-list

ETQ admin, améliore l'affichage de champ choix multiple et répétitions dans les attestations v2
This commit is contained in:
Colin Darie 2024-09-12 14:40:32 +00:00 committed by GitHub
commit 8dfddba433
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 389 additions and 18 deletions

View file

@ -0,0 +1,27 @@
# frozen_string_literal: true
describe ChampPresentations::MultipleDropDownListPresentation do
let(:options) { ["Option 1", "Option 2", "Option 3"] }
let(:representation) { described_class.new(options) }
describe '#to_s' do
it 'returns a comma-separated string of options' do
expect(representation.to_s).to eq("Option 1, Option 2, Option 3")
end
end
describe '#to_tiptap_node' do
it 'returns the correct node structure' do
expected_node = {
type: "bulletList",
content: [
{ content: [{ content: [{ :text => "Option 1", type: "text" }], type: "paragraph" }], type: "listItem" },
{ content: [{ content: [{ :text => "Option 2", type: "text" }], type: "paragraph" }], type: "listItem" },
{ content: [{ content: [{ :text => "Option 3", type: "text" }], type: "paragraph" }], type: "listItem" }
]
}
expect(representation.to_tiptap_node).to eq(expected_node)
end
end
end

View file

@ -0,0 +1,107 @@
# frozen_string_literal: true
describe ChampPresentations::RepetitionPresentation do
let(:libelle) { "Langages de programmation" }
let(:procedure) {
create(:procedure, types_de_champ_public: [
{
type: :repetition,
children: [
{ type: :text, libelle: "nom" },
{ type: :integer_number, libelle: "stars" }
]
}
])
}
let(:dossier) { create(:dossier, procedure:) }
before do
nom, stars = dossier.champs[0].rows.first
nom.update(value: "ruby")
stars.update(value: 5)
nom, stars = dossier.champs[0].add_row(dossier.procedure.active_revision)
nom.update(value: "js")
nom, stars = dossier.champs[0].add_row(dossier.procedure.active_revision)
nom.update(value: "rust")
stars.update(value: 4)
end
let(:representation) { described_class.new(libelle, dossier.champs[0].reload.rows) }
describe '#to_s' do
it 'returns a key-value representation' do
expect(representation.to_s).to eq(
<<~TXT.strip
Langages de programmation
nom : ruby
stars : 5
nom : js
stars :#{' '}
nom : rust
stars : 4
TXT
)
end
end
describe '#to_tiptap_node' do
it 'returns the correct HTML structure, without libelle' do
expected_node = {
type: "orderedList",
attrs: { class: "tdc-repetition" },
content: [
{
type: "listItem",
content: [
{
type: "descriptionList",
content: [
{ content: [{ text: "nom", type: "text" }], type: "descriptionTerm" },
{ content: [{ text: "ruby", type: "text" }], type: "descriptionDetails" },
{ content: [{ text: "stars", type: "text" }], type: "descriptionTerm" },
{ content: [{ text: "5", type: "text" }], type: "descriptionDetails" }
]
}
]
},
{
type: "listItem",
content: [
{
type: "descriptionList",
content: [
{ content: [{ text: "nom", type: "text" }], type: "descriptionTerm" },
{ content: [{ text: "js", type: "text" }], type: "descriptionDetails" },
{ content: [{ text: "stars", type: "text" }], type: "descriptionTerm", attrs: { class: "invisible" } },
{ content: [{ text: "", type: "text" }], type: "descriptionDetails" }
]
}
]
},
{
type: "listItem",
content: [
{
type: "descriptionList",
content: [
{ content: [{ text: "nom", type: "text" }], type: "descriptionTerm" },
{ content: [{ text: "rust", type: "text" }], type: "descriptionDetails" },
{ content: [{ text: "stars", type: "text" }], type: "descriptionTerm" },
{ content: [{ text: "4", type: "text" }], type: "descriptionDetails" }
]
}
]
}
]
}
expect(representation.to_tiptap_node).to eq(expected_node)
end
end
end

View file

@ -84,4 +84,9 @@ describe Champs::MultipleDropDownListChamp do
it { expect(champ.next_checkbox_id("val1")).to eq(nil) }
end
end
describe "#for_tag" do
let(:value) { ["val1", "val2"] }
it { expect(champ.for_tag.to_s).to eq("val1, val2") }
end
end

View file

@ -0,0 +1,35 @@
# frozen_string_literal: true
describe Champs::RepetitionChamp do
let(:procedure) {
create(:procedure,
types_de_champ_public: [
{
type: :repetition,
children: [{ type: :text, libelle: "Ext" }], libelle: "Languages"
}
])
}
let(:dossier) { create(:dossier, procedure:) }
let(:champ) { dossier.champs.first }
describe "#for_tag" do
before do
champ.rows[0][0].update(value: "rb")
end
it "can render as string" do
expect(champ.for_tag.to_s).to eq(
<<~TXT.strip
Languages
Ext : rb
TXT
)
end
it "as tiptap node" do
expect(champ.for_tag.to_tiptap_node).to include(type: 'orderedList')
end
end
end