# frozen_string_literal: true
require "test_helper"
class ListTest < Minitest::Test
include NotareTestHelpers
#
# Bullet List Tests
#
def test_bullet_list_basic
xml_files = create_doc_and_read_all_xml do |doc|
doc.ul do
doc.li "Item 1"
doc.li "Item 2"
end
end
doc_xml = xml_files["word/document.xml"]
assert_includes doc_xml, "Item 1"
assert_includes doc_xml, "Item 2"
assert_includes doc_xml, ""
assert_includes xml, ""
end
#
# Numbered List Tests
#
def test_numbered_list_basic
xml_files = create_doc_and_read_all_xml do |doc|
doc.ol do
doc.li "First"
doc.li "Second"
doc.li "Third"
end
end
doc_xml = xml_files["word/document.xml"]
assert_includes doc_xml, "First"
assert_includes doc_xml, "Second"
assert_includes doc_xml, "Third"
numbering_xml = xml_files["word/numbering.xml"]
assert_includes numbering_xml, "decimal"
end
def test_numbered_list_with_formatted_items
xml = create_doc_and_read_xml do |doc|
doc.ol do
doc.li { doc.b { doc.text "Bold numbered" } }
doc.li "Plain numbered"
end
end
assert_includes xml, "Bold numbered"
assert_includes xml, "Plain numbered"
assert_includes xml, ""
end
#
# Multiple Lists Tests
#
def test_multiple_bullet_lists
xml_files = create_doc_and_read_all_xml do |doc|
doc.ul do
doc.li "List 1 Item 1"
doc.li "List 1 Item 2"
end
doc.p "Separator paragraph"
doc.ul do
doc.li "List 2 Item 1"
doc.li "List 2 Item 2"
end
end
doc_xml = xml_files["word/document.xml"]
assert_includes doc_xml, "List 1 Item 1"
assert_includes doc_xml, "List 2 Item 1"
assert_includes doc_xml, "Separator paragraph"
end
def test_mixed_list_types
xml_files = create_doc_and_read_all_xml do |doc|
doc.ul do
doc.li "Bullet 1"
doc.li "Bullet 2"
end
doc.ol do
doc.li "Number 1"
doc.li "Number 2"
end
end
numbering_xml = xml_files["word/numbering.xml"]
assert_includes numbering_xml, "bullet"
assert_includes numbering_xml, "decimal"
end
def test_document_without_lists_has_no_numbering_xml
xml_files = create_doc_and_read_all_xml do |doc|
doc.p "Just a paragraph"
doc.table do
doc.tr { doc.td "Cell" }
end
end
refute xml_files.key?("word/numbering.xml"), "numbering.xml should not exist without lists"
end
end