require 'spec_helper'
describe Mastalk::Document do
context 'Without mastalk syntax' do
let(:context) { "###test\nwith markdown" }
let(:expected) { "
test
\n
with markdown
\n" }
subject { Mastalk::Document.new(context) }
it 'kramdown behaviour with no tags' do
expect(Mastalk::Document.new('test').to_html).to eq("
test
\n")
end
it 'converts to html' do
expect(subject.to_html).to eq(expected)
end
context 'multiline' do
let(:expected) { "
TEST
\n\n
with other stuff
\n\n" }
let(:context) { "### TEST\r\n\r\nwith other stuff\r\n\r\n " }
it 'converts to html' do
expect(subject.to_html).to eq(expected)
end
end
end
subject { Mastalk::Document.new(source) }
let(:expected) { "
test
\n" }
context 'custom extension' do
let(:source) { '$Etest$E' }
it 'pre-processes custom tags' do
subject.extension('$E') { |body| "
#{body}
" }
expect(subject.to_html).to eq(expected)
end
context 'multi line' do
let(:source) { '$Etest$E$Shello$FIN' }
let(:expected) { "
test
\n
hello
\n" }
it 'processes multi line' do
subject.extension('$E') { |body| "
#{body}
" }
subject.extension('$S', '$FIN') { |body| "
#{body}
" }
expect(subject.to_html).to eq(expected)
end
end
end
context 'extension with start and stop' do
let(:source) { '$STARTtest$END' }
it 'pre-processes custom tags' do
subject.extension('$START', '$END') { |body| "
#{body}
" }
expect(subject.to_html).to eq(expected)
end
end
context 'extension with other extensions inside' do
let(:source) { "$why\n###header\nbody\n$why" }
let(:expected) { "
\n
header
\n
body
\n\n
\n" }
it 'parses nested structures' do
expect(subject.to_html).to eq(expected)
end
end
context 'with newline as end' do
let(:source) { "$yes-no\n [y] yes [/y] \n [n] no [/n] \n $end $why\n###header\nbody\n$why" }
let(:expected) do
"
yes
no
\n
header
\n
body
\n\n
\n"
end
it 'pre-processes custom tags' do
expect(subject.to_html).to eq(expected)
end
end
context 'two matches after each other' do
let(:source) { "$yes-no\n [y] **yes** [/y] \n $end $yes-no\ [n] **no** [/n] \n $end" }
let(:expected) do
"
yes
no
"
end
it 'pre-processes correctly' do
expect(subject.to_html.gsub("\n", '')).to eq(expected)
end
end
context 'two callouts after each other' do
let(:source) { "$~callout\n ##yes ~$ $~callout\n ##yes ~$" }
let(:expected) do
"
\n
yes
\n\n
\n
\n
yes
\n\n
\n"
end
it 'pre-processes correctly' do
expect(subject.to_html).to eq(expected)
end
end
context 'ticks inside table' do
let(:source) { "|table|header|\n|$yes-no [y] yes [/y] $end|here|" }
let(:expected) do
"
\n \n
\n
table
\n
header
\n
\n
\n
yes
\n
here
\n
\n \n
\n"
end
it 'outputs ticks inside a table' do
expect(subject.to_html).to eq(expected)
end
end
context 'bullets inside table' do
let(:source) { "|table|header|\n|$bullet [%] yes [/%] $point|here|" }
let(:expected) do
"
\n \n
\n
table
\n
header
\n
\n
\n
yes
\n
here
\n
\n \n
\n"
end
it 'outputs a bullet list inside a table' do
expect(subject.to_html).to eq(expected)
end
end
context 'line breaks' do
let(:source) { "@~ @~" }
let(:expected) do
"
\n"
end
it 'outputs a line break' do
expect(subject.to_html).to eq(expected)
end
end
context 'when brightcove video' do
let(:video_id) { '3739688349001' }
context 'without a title' do
let(:source) { "$~brightcove_video#{video_id}~$" }
it 'outputs the brightcove embed video' do
expect(subject.to_html).to include("src=\"//players.brightcove.net/3608769895001/b15c0e6a-51da-4bb1-b717-bccae778670d_default/index.html?videoId=#{video_id}\"")
end
it 'outputs sets a default title on the iframe' do
expect(subject.to_html).to include('title="Video"')
end
end
context 'without a custom title' do
let(:title) { 'a custom video title'}
let(:source) { "$~brightcove_video#{video_id}\n#{title}~$" }
it 'outputs the brightcove embed video' do
expect(subject.to_html).to include("src=\"//players.brightcove.net/3608769895001/b15c0e6a-51da-4bb1-b717-bccae778670d_default/index.html?videoId=#{video_id}\"")
end
it 'outputs sets a default title on the iframe' do
expect(subject.to_html).to include("title=\"#{title}\"")
end
end
end
context 'cost calculator' do
let(:source) {"$~cost-calc1~$"}
it 'pre-processes correctly' do
expect(subject.to_html).to include('https://www.moneyadviceservice.org.uk/en/cost-calculator-builder/embed/calculators/1')
end
end
context 'when youtube video (legacy format)' do
let(:source) { '({oZ0_U108aZw})' }
it 'outputs the youtube embed video' do
expect(subject.to_html).to include('https://www.youtube.com/embed/oZ0_U108aZw?rel=0')
end
end
context 'when youtube video (new format)' do
let(:video_id) { 'oZ0_U108aZw' }
context 'without a title' do
let(:source) { "$~youtube_video#{video_id}~$" }
it 'outputs the youtube embed video' do
expect(subject.to_html).to include("src=\"https://www.youtube.com/embed/#{video_id}?rel=0\"")
end
it 'outputs sets a default title on the iframe' do
expect(subject.to_html).to include('title="Video"')
end
end
context 'without a custom title' do
let(:title) { 'a custom video title' }
let(:source) { "$~youtube_video#{video_id}\n#{title}~$" }
it 'outputs the youtube embed video' do
expect(subject.to_html).to include("src=\"https://www.youtube.com/embed/#{video_id}?rel=0\"")
end
it 'outputs sets a default title on the iframe' do
expect(subject.to_html).to include("title=\"#{title}\"")
end
end
end
context 'when vimeo video' do
let(:video_id) { '145743834' }
context 'without a title' do
let(:source) { "$~vimeo_video#{video_id}~$" }
it 'outputs the vimeo embed video' do
expect(subject.to_html).to include("src=\"https://player.vimeo.com/video/#{video_id}?portrait=0&title=0&byline=0\"")
end
it 'outputs sets a default title on the iframe' do
expect(subject.to_html).to include('title="Video"')
end
end
context 'without a custom title' do
let(:title) { 'a custom video title' }
let(:source) { "$~vimeo_video#{video_id}\n#{title}~$" }
it 'outputs the vimeo embed video' do
expect(subject.to_html).to include("src=\"https://player.vimeo.com/video/#{video_id}?portrait=0&title=0&byline=0\"")
end
it 'outputs sets a default title on the iframe' do
expect(subject.to_html).to include("title=\"#{title}\"")
end
end
end
context 'block with media and content' do
let(:source) { '$bl $bl_c Content bl_c$ $bl_m bl_m$ bl$' }
let(:expected) do
%(
\n
Content
\n
\n)
end
it 'outputs a block layout with media and content container blocks' do
expect(subject.to_html).to eq(expected)
end
end
context 'collapsable section' do
let(:source) { '$- -$' }
let(:expected) do
%(
\n \n\n
\n)
end
it 'outputs a collapsible section block' do
expect(subject.to_html).to eq(expected)
end
end
context 'collapsable header' do
let(:source) { '$= Content =$' }
let(:expected) do
%(
\n \n
\n)
end
it 'outputs a collapsible header' do
expect(subject.to_html).to eq(expected)
end
end
end