Add builder pattern for paragraph, lists, tables
This commit is contained in:
147
test/list_test.rb
Normal file
147
test/list_test.rb
Normal file
@@ -0,0 +1,147 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "test_helper"
|
||||
|
||||
class ListTest < Minitest::Test
|
||||
include EzdocTestHelpers
|
||||
|
||||
#
|
||||
# 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, "<w:numId"
|
||||
|
||||
numbering_xml = xml_files["word/numbering.xml"]
|
||||
assert numbering_xml, "numbering.xml should exist"
|
||||
assert_includes numbering_xml, "bullet"
|
||||
end
|
||||
|
||||
def test_bullet_list_with_many_items
|
||||
xml = create_doc_and_read_xml do |doc|
|
||||
doc.ul do
|
||||
10.times { |i| doc.li "Item #{i + 1}" }
|
||||
end
|
||||
end
|
||||
|
||||
10.times do |i|
|
||||
assert_includes xml, "Item #{i + 1}"
|
||||
end
|
||||
end
|
||||
|
||||
def test_bullet_list_with_formatted_items
|
||||
xml = create_doc_and_read_xml do |doc|
|
||||
doc.ul do
|
||||
doc.li { doc.b { doc.text "Bold item" } }
|
||||
doc.li { doc.i { doc.text "Italic item" } }
|
||||
doc.li do
|
||||
doc.text "Mixed: "
|
||||
doc.b { doc.text "bold" }
|
||||
doc.text " and "
|
||||
doc.i { doc.text "italic" }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
assert_includes xml, "Bold item"
|
||||
assert_includes xml, "Italic item"
|
||||
assert_includes xml, "<w:b/>"
|
||||
assert_includes xml, "<w:i/>"
|
||||
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, "<w:b/>"
|
||||
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
|
||||
Reference in New Issue
Block a user