File: test_toc_filter.rb

package info (click to toggle)
ruby-jekyll-toc 0.18.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 244 kB
  • sloc: ruby: 912; makefile: 9
file content (37 lines) | stat: -rw-r--r-- 902 bytes parent folder | download
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
33
34
35
36
37
# frozen_string_literal: true

require 'test_helper'

class TestTOCFilter < Minitest::Test
  include TestHelpers

  def setup
    read_html_and_create_parser
  end

  def test_injects_anchors
    html = @parser.toc

    assert_match(%r{<a class="anchor" href="#simple-h1" aria-hidden="true"><span.*span></a>Simple H1}, html)
  end

  def test_nested_toc
    doc = Nokogiri::HTML(@parser.toc)
    nested_h6_text = doc.css('ul.section-nav')
                        .css('li.toc-h1')
                        .css('li.toc-h2')
                        .css('li.toc-h3')
                        .css('li.toc-h4')
                        .css('li.toc-h5')
                        .css('li.toc-h6')
                        .text

    assert_equal('Simple H6', nested_h6_text)
  end

  def test_injects_toc_container
    html = @parser.toc

    assert_match(/<ul id="toc" class="section-nav">/, html)
  end
end