summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2016-03-01 16:06:40 +0000
committerDouwe Maan <douwe@gitlab.com>2016-03-01 16:06:40 +0000
commit3d1de5ba35215e7aa3b4fb5ea3d454e082d667e0 (patch)
tree6ff513193adf9c28f2bf27fdc73e5e66fe9bca68 /spec
parentad9137a785910e825067182409db040f67f5a63c (diff)
parentbc43ad71ef2c1ab6cf56d94ac93df0bdc0e2b741 (diff)
downloadgitlab-ce-3d1de5ba35215e7aa3b4fb5ea3d454e082d667e0.tar.gz
Merge branch 'rs-wiki-toc' into 'master'
Replace Gollum `[[_TOC_]]` tag with result of TableOfContentsFilter Closes #2494 See merge request !2952
Diffstat (limited to 'spec')
-rw-r--r--spec/lib/banzai/filter/gollum_tags_filter_spec.rb52
1 files changed, 52 insertions, 0 deletions
diff --git a/spec/lib/banzai/filter/gollum_tags_filter_spec.rb b/spec/lib/banzai/filter/gollum_tags_filter_spec.rb
index 38baa819957..11cc290d6d0 100644
--- a/spec/lib/banzai/filter/gollum_tags_filter_spec.rb
+++ b/spec/lib/banzai/filter/gollum_tags_filter_spec.rb
@@ -86,4 +86,56 @@ describe Banzai::Filter::GollumTagsFilter, lib: true do
expect(doc.at_css('a')['href']).to eq 'wiki-slug'
end
end
+
+ context 'table of contents' do
+ let(:pipeline) { Banzai::Pipeline[:wiki] }
+
+ it 'replaces the tag with the TableOfContentsFilter result' do
+ markdown = <<-MD.strip_heredoc
+ [[_TOC_]]
+
+ ## Header
+
+ Foo
+ MD
+
+ result = pipeline.call(markdown, project_wiki: project_wiki, project: project)
+
+ aggregate_failures do
+ expect(result[:output].text).not_to include '[[_TOC_]]'
+ expect(result[:output].text).not_to include '[['
+ 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
+
+ output = pipeline.to_html(markdown, project_wiki: project_wiki, project: project)
+
+ 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
+
+ output = pipeline.to_html(markdown, project_wiki: project_wiki, project: project)
+
+ aggregate_failures do
+ expect(output).not_to include('<ul>')
+ expect(output).to include('[[<em>TOC</em>]]')
+ end
+ end
+ end
end