159 lines
3.8 KiB
Ruby
159 lines
3.8 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require "test_helper"
|
|
|
|
class IntegrationTest < Minitest::Test
|
|
include NotareTestHelpers
|
|
|
|
def test_complex_document_with_all_features
|
|
xml_files = create_doc_and_read_all_xml do |doc|
|
|
doc.p "Introduction paragraph"
|
|
|
|
doc.p do
|
|
doc.text "This has "
|
|
doc.b { doc.text "bold" }
|
|
doc.text " and "
|
|
doc.i { doc.text "italic" }
|
|
doc.text " text."
|
|
end
|
|
|
|
doc.ul do
|
|
doc.li "Bullet point 1"
|
|
doc.li { doc.b { doc.text "Bold bullet" } }
|
|
end
|
|
|
|
doc.ol do
|
|
doc.li "Numbered item 1"
|
|
doc.li "Numbered item 2"
|
|
end
|
|
|
|
doc.table do
|
|
doc.tr do
|
|
doc.td "Header 1"
|
|
doc.td "Header 2"
|
|
end
|
|
doc.tr do
|
|
doc.td { doc.i { doc.text "Italic cell" } }
|
|
doc.td "Normal cell"
|
|
end
|
|
end
|
|
|
|
doc.p "Conclusion paragraph"
|
|
end
|
|
|
|
doc_xml = xml_files["word/document.xml"]
|
|
|
|
# Verify all content types are present
|
|
assert_includes doc_xml, "Introduction paragraph"
|
|
assert_includes doc_xml, "Conclusion paragraph"
|
|
assert_includes doc_xml, "<w:b/>"
|
|
assert_includes doc_xml, "<w:i/>"
|
|
assert_includes doc_xml, "<w:tbl>"
|
|
assert_includes doc_xml, "<w:numId"
|
|
|
|
# Verify numbering exists
|
|
assert xml_files.key?("word/numbering.xml")
|
|
end
|
|
|
|
def test_paragraph_between_lists
|
|
xml = create_doc_and_read_xml do |doc|
|
|
doc.ul { doc.li "Before" }
|
|
doc.p "Middle paragraph"
|
|
doc.ol { doc.li "After" }
|
|
end
|
|
|
|
# Verify order by checking relative positions
|
|
before_pos = xml.index("Before")
|
|
middle_pos = xml.index("Middle paragraph")
|
|
after_pos = xml.index("After")
|
|
|
|
assert before_pos < middle_pos, "Before should come before Middle"
|
|
assert middle_pos < after_pos, "Middle should come before After"
|
|
end
|
|
|
|
def test_table_between_paragraphs
|
|
xml = create_doc_and_read_xml do |doc|
|
|
doc.p "Before table"
|
|
doc.table do
|
|
doc.tr { doc.td "In table" }
|
|
end
|
|
doc.p "After table"
|
|
end
|
|
|
|
before_pos = xml.index("Before table")
|
|
table_pos = xml.index("<w:tbl>")
|
|
after_pos = xml.index("After table")
|
|
|
|
assert before_pos < table_pos
|
|
assert table_pos < after_pos
|
|
end
|
|
|
|
def test_formatting_in_list_items
|
|
xml = create_doc_and_read_xml do |doc|
|
|
doc.ul do
|
|
doc.li do
|
|
doc.b do
|
|
doc.i { doc.text "Bold and italic in list" }
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
assert_includes xml, "<w:b/>"
|
|
assert_includes xml, "<w:i/>"
|
|
assert_includes xml, "Bold and italic in list"
|
|
end
|
|
|
|
def test_formatting_in_table_cells
|
|
xml = create_doc_and_read_xml do |doc|
|
|
doc.table do
|
|
doc.tr do
|
|
doc.td do
|
|
doc.b do
|
|
doc.i { doc.text "Bold and italic in table" }
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
assert_includes xml, "<w:b/>"
|
|
assert_includes xml, "<w:i/>"
|
|
assert_includes xml, "Bold and italic in table"
|
|
end
|
|
|
|
def test_multiple_features_interleaved
|
|
xml = create_doc_and_read_xml do |doc|
|
|
doc.p "Para 1"
|
|
doc.ul { doc.li "Bullet" }
|
|
doc.p "Para 2"
|
|
doc.table { doc.tr { doc.td "Cell" } }
|
|
doc.p "Para 3"
|
|
doc.ol { doc.li "Number" }
|
|
doc.p "Para 4"
|
|
end
|
|
|
|
# Verify all elements exist
|
|
assert_includes xml, "Para 1"
|
|
assert_includes xml, "Para 4"
|
|
assert_includes xml, "Bullet"
|
|
assert_includes xml, "Cell"
|
|
assert_includes xml, "Number"
|
|
|
|
# Verify correct ordering
|
|
positions = [
|
|
xml.index("Para 1"),
|
|
xml.index("Bullet"),
|
|
xml.index("Para 2"),
|
|
xml.index("<w:tbl>"),
|
|
xml.index("Para 3"),
|
|
xml.index("Number"),
|
|
xml.index("Para 4")
|
|
]
|
|
|
|
positions.each_cons(2) do |a, b|
|
|
assert a < b, "Elements should be in correct order"
|
|
end
|
|
end
|
|
end
|