diff options
Diffstat (limited to 'spec/lib/banzai/filter/plantuml_filter_spec.rb')
-rw-r--r-- | spec/lib/banzai/filter/plantuml_filter_spec.rb | 73 |
1 files changed, 55 insertions, 18 deletions
diff --git a/spec/lib/banzai/filter/plantuml_filter_spec.rb b/spec/lib/banzai/filter/plantuml_filter_spec.rb index 5ad94c74514..d1a3b5689a8 100644 --- a/spec/lib/banzai/filter/plantuml_filter_spec.rb +++ b/spec/lib/banzai/filter/plantuml_filter_spec.rb @@ -5,30 +5,67 @@ require 'spec_helper' RSpec.describe Banzai::Filter::PlantumlFilter do include FilterSpecHelper - it 'replaces plantuml pre tag with img tag' do - 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) + shared_examples_for 'renders correct markdown' do + it 'replaces plantuml pre tag with img tag' do + stub_application_setting(plantuml_enabled: true, plantuml_url: "http://localhost:8080") - expect(doc.to_s).to eq output + input = if Feature.enabled?(:use_cmark_renderer) + '<pre lang="plantuml"><code>Bob -> Sara : Hello</code></pre>' + else + '<pre><code lang="plantuml">Bob -> Sara : Hello</code></pre>' + end + + 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 + + it 'does not replace plantuml pre tag with img tag if disabled' do + stub_application_setting(plantuml_enabled: false) + + if Feature.enabled?(:use_cmark_renderer) + input = '<pre lang="plantuml"><code>Bob -> Sara : Hello</code></pre>' + output = '<pre lang="plantuml"><code>Bob -> Sara : Hello</code></pre>' + else + input = '<pre><code lang="plantuml">Bob -> Sara : Hello</code></pre>' + output = '<pre><code lang="plantuml">Bob -> Sara : Hello</code></pre>' + end + + doc = filter(input) + + expect(doc.to_s).to eq output + end + + it 'does not replace plantuml pre tag with img tag if url is invalid' do + stub_application_setting(plantuml_enabled: true, plantuml_url: "invalid") + + input = if Feature.enabled?(:use_cmark_renderer) + '<pre lang="plantuml"><code>Bob -> Sara : Hello</code></pre>' + else + '<pre><code lang="plantuml">Bob -> Sara : Hello</code></pre>' + end + + output = '<div class="listingblock"><div class="content"><pre class="plantuml plantuml-error"> Error: cannot connect to PlantUML server at "invalid"</pre></div></div>' + doc = filter(input) + + expect(doc.to_s).to eq output + end end - it 'does not replace plantuml pre tag with img tag if disabled' do - 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) + context 'using ruby-based HTML renderer' do + before do + stub_feature_flags(use_cmark_renderer: false) + end - expect(doc.to_s).to eq output + it_behaves_like 'renders correct markdown' end - it 'does not replace plantuml pre tag with img tag if url is invalid' do - stub_application_setting(plantuml_enabled: true, plantuml_url: "invalid") - input = '<pre><code lang="plantuml">Bob -> Sara : Hello</code></pre>' - output = '<div class="listingblock"><div class="content"><pre class="plantuml plantuml-error"> Error: cannot connect to PlantUML server at "invalid"</pre></div></div>' - doc = filter(input) + context 'using c-based HTML renderer' do + before do + stub_feature_flags(use_cmark_renderer: true) + end - expect(doc.to_s).to eq output + it_behaves_like 'renders correct markdown' end end |