BigW Consortium Gitlab

wiki_pipeline_spec.rb 1.27 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
require 'rails_helper'

describe Banzai::Pipeline::WikiPipeline do
  describe 'TableOfContents' do
    it 'replaces the tag with the TableOfContentsFilter result' do
      markdown = <<-MD.strip_heredoc
          [[_TOC_]]

          ## Header

          Foo
      MD

14
      result = described_class.call(markdown, project: spy, project_wiki: spy)
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

      aggregate_failures do
        expect(result[:output].text).not_to include '[['
        expect(result[:output].text).not_to include 'TOC'
        expect(result[:output].to_html).to include(result[:toc])
      end
    end

    it 'is case-sensitive' do
      markdown = <<-MD.strip_heredoc
          [[_toc_]]

          # Header 1

          Foo
      MD

32
      output = described_class.to_html(markdown, project: spy, project_wiki: spy)
33 34 35 36 37 38 39 40 41 42 43 44

      expect(output).to include('[[<em>toc</em>]]')
    end

    it 'handles an empty pipeline result' do
      # No Markdown headers in this doc, so `result[:toc]` will be empty
      markdown = <<-MD.strip_heredoc
          [[_TOC_]]

          Foo
      MD

45
      output = described_class.to_html(markdown, project: spy, project_wiki: spy)
46 47 48

      aggregate_failures do
        expect(output).not_to include('<ul>')
49
        expect(output).not_to include('[[<em>TOC</em>]]')
50 51 52 53
      end
    end
  end
end