2024-07-25 11:42:50 +02:00
|
|
|
# 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:) }
|
2024-08-27 10:29:10 +02:00
|
|
|
let(:champ_repetition) { dossier.champs.find(&:repetition?) }
|
2024-07-25 11:42:50 +02:00
|
|
|
|
|
|
|
before do
|
2024-08-27 10:29:10 +02:00
|
|
|
champ_repetition.add_row(updated_by: 'test')
|
|
|
|
champ_repetition.add_row(updated_by: 'test')
|
|
|
|
row1, row2, row3 = champ_repetition.rows
|
|
|
|
|
|
|
|
nom, stars = row1
|
2024-07-25 11:42:50 +02:00
|
|
|
nom.update(value: "ruby")
|
|
|
|
stars.update(value: 5)
|
|
|
|
|
2024-08-27 10:29:10 +02:00
|
|
|
nom = row2.first
|
2024-09-04 17:32:21 +02:00
|
|
|
nom.update(value: "js")
|
|
|
|
|
2024-08-27 10:29:10 +02:00
|
|
|
nom, stars = row3
|
2024-07-25 11:42:50 +02:00
|
|
|
nom.update(value: "rust")
|
|
|
|
stars.update(value: 4)
|
|
|
|
end
|
|
|
|
|
2024-09-27 15:44:57 +02:00
|
|
|
let(:representation) { described_class.new(libelle, champ_repetition.rows) }
|
2024-07-25 11:42:50 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2024-09-04 17:32:21 +02:00
|
|
|
nom : js
|
|
|
|
stars :#{' '}
|
|
|
|
|
2024-07-25 11:42:50 +02:00
|
|
|
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" }
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
2024-09-04 17:32:21 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
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" }
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
2024-07-25 11:42:50 +02:00
|
|
|
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
|