2023-10-20 22:50:39 +02:00
|
|
|
RSpec.describe TiptapService do
|
|
|
|
describe '.to_html' do
|
|
|
|
let(:json) do
|
|
|
|
{
|
|
|
|
type: 'doc',
|
|
|
|
content: [
|
2023-11-21 16:49:50 +01:00
|
|
|
{
|
|
|
|
type: 'header',
|
|
|
|
content: [
|
|
|
|
{
|
|
|
|
type: 'headerColumn',
|
|
|
|
content: [{ type: 'text', text: 'Left' }]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'headerColumn',
|
|
|
|
content: [{ type: 'text', text: 'Right' }]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'title',
|
|
|
|
content: [{ type: 'text', text: 'Title' }]
|
|
|
|
},
|
2023-10-20 22:50:39 +02:00
|
|
|
{
|
|
|
|
type: 'paragraph',
|
|
|
|
attrs: { textAlign: 'right' },
|
|
|
|
content: [
|
|
|
|
{
|
|
|
|
type: 'text',
|
|
|
|
text: 'Hello world!'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'paragraph',
|
|
|
|
content: [
|
|
|
|
{
|
|
|
|
type: 'text',
|
|
|
|
text: 'Bonjour ',
|
|
|
|
marks: [{ type: 'italic' }, { type: 'strike' }]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'mention',
|
|
|
|
attrs: { id: 'name' },
|
|
|
|
marks: [{ type: 'bold' }, { type: 'underline' }]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'text',
|
|
|
|
text: ' '
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'text',
|
|
|
|
text: '!',
|
|
|
|
marks: [{ type: 'highlight' }]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'heading',
|
|
|
|
attrs: { level: 1 },
|
|
|
|
content: [{ type: 'text', text: 'Heading 1' }]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'heading',
|
|
|
|
attrs: { level: 2, textAlign: 'center' },
|
|
|
|
content: [{ type: 'text', text: 'Heading 2' }]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'heading',
|
|
|
|
attrs: { level: 3 },
|
|
|
|
content: [{ type: 'text', text: 'Heading 3' }]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'bulletList',
|
|
|
|
content: [
|
|
|
|
{
|
|
|
|
type: 'listItem',
|
|
|
|
content: [
|
|
|
|
{
|
|
|
|
type: 'paragraph',
|
|
|
|
content: [
|
|
|
|
{
|
|
|
|
type: 'text',
|
|
|
|
text: 'Item 1'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'listItem',
|
|
|
|
content: [
|
|
|
|
{
|
|
|
|
type: 'paragraph',
|
|
|
|
content: [
|
|
|
|
{
|
|
|
|
type: 'text',
|
|
|
|
text: 'Item 2'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'orderedList',
|
|
|
|
content: [
|
|
|
|
{
|
|
|
|
type: 'listItem',
|
|
|
|
content: [
|
|
|
|
{
|
|
|
|
type: 'paragraph',
|
|
|
|
content: [
|
|
|
|
{
|
|
|
|
type: 'text',
|
|
|
|
text: 'Item 1'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'listItem',
|
|
|
|
content: [
|
|
|
|
{
|
|
|
|
type: 'paragraph',
|
|
|
|
content: [
|
|
|
|
{
|
|
|
|
type: 'text',
|
|
|
|
text: 'Item 2'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
2023-11-21 16:49:50 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'footer',
|
|
|
|
content: [{ type: 'text', text: 'Footer' }]
|
2023-10-20 22:50:39 +02:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
end
|
|
|
|
let(:tags) { { 'name' => 'Paul' } }
|
|
|
|
let(:html) do
|
|
|
|
[
|
2023-11-21 16:49:50 +01:00
|
|
|
'<header><div class="column">Left</div><div class="column">Right</div></header>',
|
|
|
|
'<h1>Title</h1>',
|
2023-10-20 22:50:39 +02:00
|
|
|
'<p style="text-align: right">Hello world!</p>',
|
|
|
|
'<p><s><em>Bonjour </em></s><u><strong>Paul</strong></u> <mark>!</mark></p>',
|
|
|
|
'<h1>Heading 1</h1>',
|
|
|
|
'<h2 style="text-align: center">Heading 2</h2>',
|
|
|
|
'<h3>Heading 3</h3>',
|
|
|
|
'<ul><li><p>Item 1</p></li><li><p>Item 2</p></li></ul>',
|
2023-11-21 16:49:50 +01:00
|
|
|
'<ol><li><p>Item 1</p></li><li><p>Item 2</p></li></ol>',
|
|
|
|
'<footer>Footer</footer>'
|
2023-10-20 22:50:39 +02:00
|
|
|
].join
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns html' do
|
|
|
|
expect(described_class.to_html(json, tags)).to eq(html)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|