summaryrefslogtreecommitdiff
path: root/spec/lib/banzai/filter/plantuml_filter_spec.rb
blob: f85a5dcbd8bd74d2509fd8f958d5e3b7691a7bce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
require 'spec_helper'

describe Banzai::Filter::PlantumlFilter, lib: true do
  include FilterSpecHelper

  it 'should replace plantuml pre tag with img tag' do
    stub_application_setting(plantuml_enabled: true, plantuml_url: "http://localhost:8080")
    input = '<pre class="plantuml"><code>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

  it 'should not replace plantuml pre tag with img tag if disabled' do
    stub_application_setting(plantuml_enabled: false)
    input = '<pre class="plantuml"><code>Bob -> Sara : Hello</code><pre>'
    output = '<pre class="plantuml"><code>Bob -&gt; Sara : Hello</code><pre></pre></pre>'
    doc = filter(input)

    expect(doc.to_s).to eq output
  end

  it 'should not replace plantuml pre tag with img tag if url is invalid' do
    stub_application_setting(plantuml_enabled: true, plantuml_url: "invalid")
    input = '<pre class="plantuml"><code>Bob -> Sara : Hello</code><pre>'
    output = '<div class="listingblock"><div class="content"><pre class="plantuml plantuml-error"> PlantUML Error: cannot connect to PlantUML server at "invalid"</pre></div></div>'
    doc = filter(input)

    expect(doc.to_s).to eq output
  end
end