diff options
author | Akihiro Nakashima <shibamu@gmail.com> | 2017-08-18 10:09:10 +0300 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2017-09-06 19:48:25 +0300 |
commit | 2a055c23c27f85db4bc56f07dccca642fc264d57 (patch) | |
tree | 576331a4f422299dcc7dcf7219356e60883b2f3f /spec/lib/banzai/filter | |
parent | 10fd3542225e161de0c82442304a0881ccecc774 (diff) |
Fix indentation level in Wiki's TOC items to regard header level
Diffstat (limited to 'spec/lib/banzai/filter')
-rw-r--r-- | spec/lib/banzai/filter/table_of_contents_filter_spec.rb | 44 |
1 files changed, 38 insertions, 6 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..f28022f61b7 100644 --- a/spec/lib/banzai/filter/table_of_contents_filter_spec.rb +++ b/spec/lib/banzai/filter/table_of_contents_filter_spec.rb @@ -78,7 +78,7 @@ describe Banzai::Filter::TableOfContentsFilter do HTML::Pipeline.new([described_class]).call(html) end - let(:results) { result(header(1, 'Header 1') + header(2, 'Header 2')) } + let(:results) { 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')) } let(:doc) { Nokogiri::XML::DocumentFragment.parse(results[:toc]) } it 'is contained within a `ul` element' do @@ -87,14 +87,46 @@ describe Banzai::Filter::TableOfContentsFilter do end it 'contains an `li` element for each header' do - expect(doc.css('li').length).to eq 2 + expect(doc.css('li').length).to eq 6 links = doc.css('li a') - expect(links.first.attr('href')).to eq '#header-1' - expect(links.first.text).to eq 'Header 1' - expect(links.last.attr('href')).to eq '#header-2' - expect(links.last.text).to eq 'Header 2' + expect(links[0].attr('href')).to eq '#header-1' + expect(links[0].text).to eq 'Header 1' + expect(links[1].attr('href')).to eq '#header-1-1' + expect(links[1].text).to eq 'Header 1-1' + expect(links[2].attr('href')).to eq '#header-1-1-1' + expect(links[2].text).to eq 'Header 1-1-1' + expect(links[3].attr('href')).to eq '#header-1-2' + expect(links[3].text).to eq 'Header 1-2' + expect(links[4].attr('href')).to eq '#header-2' + expect(links[4].text).to eq 'Header 2' + expect(links[5].attr('href')).to eq '#header-2-1' + expect(links[5].text).to eq 'Header 2-1' + end + + it 'keeps list levels regarding header levels' do + items = doc.css('li') + + # Header 1 + expect(items[0].ancestors.any? {|node| node.name == 'li'}).to eq false + + # Header 1-1 + expect(items[1].ancestors.include?(items[0])).to eq true + + # Header 1-1-1 + expect(items[2].ancestors.include?(items[0])).to eq true + expect(items[2].ancestors.include?(items[1])).to eq true + + # Header 1-2 + expect(items[3].ancestors.include?(items[0])).to eq true + expect(items[3].ancestors.include?(items[1])).to eq false + + # Header 2 + expect(items[4].ancestors.any? {|node| node.name == 'li'}).to eq false + + # Header 2-1 + expect(items[5].ancestors.include?(items[4])).to eq true end end end |