2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
require 'spec_helper'
2017-09-10 17:25:29 +05:30
describe Banzai :: Filter :: PlantumlFilter do
2017-08-17 22:00:37 +05:30
include FilterSpecHelper
2019-07-07 11:18:12 +05:30
it 'replaces plantuml pre tag with img tag' do
2017-08-17 22:00:37 +05:30
stub_application_setting ( plantuml_enabled : true , plantuml_url : " http://localhost:8080 " )
input = '<pre><code lang="plantuml">Bob -> Sara : Hello</code></pre>'
output = '<div class="imageblock"><div class="content"><img class="plantuml" src="http://localhost:8080/png/U9npoazIqBLJ24uiIbImKl18pSd91m0rkGMq"></div></div>'
doc = filter ( input )
expect ( doc . to_s ) . to eq output
end
2019-07-07 11:18:12 +05:30
it 'does not replace plantuml pre tag with img tag if disabled' do
2017-08-17 22:00:37 +05:30
stub_application_setting ( plantuml_enabled : false )
input = '<pre><code lang="plantuml">Bob -> Sara : Hello</code></pre>'
output = '<pre><code lang="plantuml">Bob -> Sara : Hello</code></pre>'
doc = filter ( input )
expect ( doc . to_s ) . to eq output
end
2019-07-07 11:18:12 +05:30
it 'does not replace plantuml pre tag with img tag if url is invalid' do
2017-08-17 22:00:37 +05:30
stub_application_setting ( plantuml_enabled : true , plantuml_url : " invalid " )
input = '<pre><code lang="plantuml">Bob -> Sara : Hello</code></pre>'
2020-03-13 15:44:24 +05:30
output = '<div class="listingblock"><div class="content"><pre class="plantuml plantuml-error"> Error: cannot connect to PlantUML server at "invalid"</pre></div></div>'
2017-08-17 22:00:37 +05:30
doc = filter ( input )
expect ( doc . to_s ) . to eq output
end
end