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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
# frozen_string_literal: true
require 'test_helper'
class TestOrderedList < Minitest::Test
include TestHelpers
def test_default_configuration
configuration = Jekyll::TableOfContents::Configuration.new({})
refute(configuration.ordered_list)
end
def test_disabled_ordered_list
configuration = Jekyll::TableOfContents::Configuration.new('ordered_list' => false)
refute(configuration.ordered_list)
end
def test_enabled_ordered_list
configuration = Jekyll::TableOfContents::Configuration.new('ordered_list' => true)
assert(configuration.ordered_list)
end
def test_basic_ordered_list_top_heading
parse_with_ordered_list
html = @parser.toc
assert_match(/^<ol id="toc" class="section-nav">/, html)
end
def test_ordered_list_sub_headings
parse_with_ordered_list
html = @parser.toc
assert_match(/<ol>\n<li class="toc-entry/, html)
end
def test_ordered_list_top_heading_with_classes
parse_with_ordered_list_and_classes
html = @parser.toc
assert_match(/^<ol id="toc" class="top-list-class">/, html)
end
def test_ordered_list_sub_headings_with_classes
parse_with_ordered_list_and_classes
html = @parser.toc
assert_match(/<ol class="sublist-class">/, html)
end
def test_ordered_list_subheadings_with_classes_nested_structure
parse_with_ordered_list_and_classes
html = @parser.toc
occurrences = html.scan(/<ol class="sublist-class">/).count
assert_equal(5, occurrences)
end
private
def parse_with_ordered_list
read_html_and_create_parser('ordered_list' => true)
end
def parse_with_ordered_list_and_classes
read_html_and_create_parser(
'ordered_list' => true,
'list_class' => 'top-list-class',
'sublist_class' => 'sublist-class'
)
end
end
|