feat(attestation): render multiple drop down list as list
This commit is contained in:
parent
ae207ac2e6
commit
09581ad028
6 changed files with 90 additions and 4 deletions
|
@ -0,0 +1,35 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class ChampPresentations::MultipleDropDownListPresentation
|
||||
attr_reader :selected_options
|
||||
|
||||
def initialize(selected_options)
|
||||
@selected_options = selected_options
|
||||
end
|
||||
|
||||
def to_s
|
||||
selected_options.join(', ')
|
||||
end
|
||||
|
||||
def to_tiptap_node
|
||||
{
|
||||
type: 'bulletList',
|
||||
content: selected_options.map do |text|
|
||||
{
|
||||
type: 'listItem',
|
||||
content: [
|
||||
{
|
||||
type: 'paragraph',
|
||||
content: [
|
||||
{
|
||||
type: 'text',
|
||||
text: text
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
end
|
||||
}
|
||||
end
|
||||
end
|
|
@ -7,7 +7,7 @@ class TypesDeChamp::MultipleDropDownListTypeDeChamp < TypesDeChamp::TypeDeChampB
|
|||
end
|
||||
|
||||
def champ_value_for_tag(champ, path = :value)
|
||||
champ.selected_options.join(', ')
|
||||
ChampPresentations::MultipleDropDownListPresentation.new(champ.selected_options)
|
||||
end
|
||||
|
||||
def champ_value_for_export(champ, path = :value)
|
||||
|
|
|
@ -90,7 +90,12 @@ class TiptapService
|
|||
text
|
||||
end
|
||||
in type: 'mention', attrs: { id: }, **rest
|
||||
text = substitutions.fetch(id) { "--#{id}--" }
|
||||
text_or_representation = substitutions.fetch(id) { "--#{id}--" }
|
||||
text = if text_or_representation.respond_to?(:to_tiptap_node)
|
||||
node_to_html(text_or_representation.to_tiptap_node, substitutions, level + 1)
|
||||
else
|
||||
text_or_representation
|
||||
end
|
||||
|
||||
if rest[:marks].present?
|
||||
apply_marks(text, rest[:marks])
|
||||
|
|
|
@ -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
|
|
@ -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
|
||||
|
|
|
@ -138,6 +138,19 @@ RSpec.describe TiptapService do
|
|||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
type: 'paragraph',
|
||||
content: [
|
||||
{
|
||||
type: 'text',
|
||||
text: 'Langages de prédilection:'
|
||||
},
|
||||
{
|
||||
type: 'mention',
|
||||
attrs: { id: 'languages', label: 'Langages' }
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
type: 'footer',
|
||||
content: [{ type: 'text', text: 'Footer' }]
|
||||
|
@ -147,7 +160,7 @@ RSpec.describe TiptapService do
|
|||
end
|
||||
|
||||
describe '.to_html' do
|
||||
let(:substitutions) { { 'name' => 'Paul' } }
|
||||
let(:substitutions) { { 'name' => 'Paul', 'languages' => ChampPresentations::MultipleDropDownListPresentation.new(['ruby', 'rust']) } }
|
||||
let(:html) do
|
||||
[
|
||||
'<header><div>Left</div><div>Right</div></header>',
|
||||
|
@ -158,6 +171,7 @@ RSpec.describe TiptapService do
|
|||
'<p><s><em>Bonjour </em></s><u><strong>Paul</strong></u> <mark>!</mark></p>',
|
||||
'<ul><li><p>Item 1</p></li><li><p>Item 2</p></li></ul>',
|
||||
'<ol><li><p>Item 1</p></li><li><p>Item 2</p></li></ol>',
|
||||
'<p>Langages de prédilection:<ul><li><p>ruby</p></li><li><p>rust</p></li></ul></p>', # TODO: fix this markup, <ul> should not be under <p>
|
||||
'<footer>Footer</footer>'
|
||||
].join
|
||||
end
|
||||
|
@ -191,7 +205,7 @@ RSpec.describe TiptapService do
|
|||
|
||||
describe '#used_tags' do
|
||||
it 'returns used tags' do
|
||||
expect(described_class.used_tags_and_libelle_for(json)).to eq(Set.new([['name', 'Nom']]))
|
||||
expect(described_class.used_tags_and_libelle_for(json)).to eq(Set.new([['name', 'Nom'], ['languages', 'Langages']]))
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue