summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorSean McGivern <sean@mcgivern.me.uk>2017-09-06 18:23:24 +0000
committerSean McGivern <sean@mcgivern.me.uk>2017-09-06 18:23:24 +0000
commitcc6f7b0b34d5d2be8445068a0620d0872003d85e (patch)
treeec1ba7e3e7a7015d596301a8dc30926677fa2bb1 /spec
parent86cbf60cbb77d15ac01d86cec2e387974426f898 (diff)
parent056158efbacf2f9d1b72402d56a0ebbe92cb71db (diff)
downloadgitlab-ce-cc6f7b0b34d5d2be8445068a0620d0872003d85e.tar.gz
Merge branch 'anakashima/gitlab-ce-fix_wiki_toc_indent' into 'master'
Wiki table of contents are now properly nested to reflect header level See merge request !13909
Diffstat (limited to 'spec')
-rw-r--r--spec/lib/banzai/filter/table_of_contents_filter_spec.rb36
1 files changed, 36 insertions, 0 deletions
diff --git a/spec/lib/banzai/filter/table_of_contents_filter_spec.rb b/spec/lib/banzai/filter/table_of_contents_filter_spec.rb
index ff6b19459bb..85eddde732e 100644
--- a/spec/lib/banzai/filter/table_of_contents_filter_spec.rb
+++ b/spec/lib/banzai/filter/table_of_contents_filter_spec.rb
@@ -96,5 +96,41 @@ describe Banzai::Filter::TableOfContentsFilter do
expect(links.last.attr('href')).to eq '#header-2'
expect(links.last.text).to eq 'Header 2'
end
+
+ context 'table of contents nesting' do
+ let(:results) do
+ result(
+ header(1, 'Header 1') <<
+ header(2, 'Header 1-1') <<
+ header(3, 'Header 1-1-1') <<
+ header(2, 'Header 1-2') <<
+ header(1, 'Header 2') <<
+ header(2, 'Header 2-1')
+ )
+ end
+
+ it 'keeps list levels regarding header levels' do
+ items = doc.css('li')
+
+ # Header 1
+ expect(items[0].ancestors).to satisfy_none { |node| node.name == 'li' }
+
+ # Header 1-1
+ expect(items[1].ancestors).to include(items[0])
+
+ # Header 1-1-1
+ expect(items[2].ancestors).to include(items[0], items[1])
+
+ # Header 1-2
+ expect(items[3].ancestors).to include(items[0])
+ expect(items[3].ancestors).not_to include(items[1])
+
+ # Header 2
+ expect(items[4].ancestors).to satisfy_none { |node| node.name == 'li' }
+
+ # Header 2-1
+ expect(items[5].ancestors).to include(items[4])
+ end
+ end
end
end