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
|
# frozen_string_literal: true
require "test_helper"
class TestTasklists < Minitest::Test
def setup
text = <<-MD
- [x] Add task list
- [ ] Define task list
MD
@doc = CommonMarker.render_doc(text, :DEFAULT, [:tasklist])
@expected = <<~HTML
<ul>
<li><input type="checkbox" checked="" disabled="" /> Add task list</li>
<li><input type="checkbox" disabled="" /> Define task list</li>
</ul>
HTML
end
def test_to_html
assert_equal(@expected, @doc.to_html)
end
def test_html_renderer
assert_equal(@expected, CommonMarker::HtmlRenderer.new.render(@doc))
end
def test_tasklist_state
list = @doc.first_child
assert_equal("checked", list.first_child.tasklist_state)
assert_predicate(list.first_child, :tasklist_item_checked?)
assert_equal("unchecked", list.first_child.next.tasklist_state)
refute_predicate(list.first_child.next, :tasklist_item_checked?)
end
def test_set_tasklist_state
list = @doc.first_child
list.first_child.tasklist_item_checked = false
refute_predicate(list.first_child, :tasklist_item_checked?)
list.first_child.next.tasklist_item_checked = true
assert_predicate(list.first_child.next, :tasklist_item_checked?)
end
end
|