Implement styles
All checks were successful
CI Pipeline / build (pull_request) Successful in 12s

This commit is contained in:
2025-12-02 12:02:51 +01:00
parent 1fffecf0eb
commit 58492e9ef6
16 changed files with 786 additions and 23 deletions

87
test/heading_test.rb Normal file
View File

@@ -0,0 +1,87 @@
# frozen_string_literal: true
require "test_helper"
class HeadingTest < Minitest::Test
include EzdocTestHelpers
def test_h1
xml = create_doc_and_read_xml { |doc| doc.h1 "Title" }
assert_includes xml, "<w:pStyle"
assert_includes xml, 'w:val="Heading1"'
assert_includes xml, "Title"
end
def test_h2
xml = create_doc_and_read_xml { |doc| doc.h2 "Chapter" }
assert_includes xml, 'w:val="Heading2"'
assert_includes xml, "Chapter"
end
def test_h3
xml = create_doc_and_read_xml { |doc| doc.h3 "Section" }
assert_includes xml, 'w:val="Heading3"'
end
def test_h4
xml = create_doc_and_read_xml { |doc| doc.h4 "Subsection" }
assert_includes xml, 'w:val="Heading4"'
end
def test_h5
xml = create_doc_and_read_xml { |doc| doc.h5 "Minor" }
assert_includes xml, 'w:val="Heading5"'
end
def test_h6
xml = create_doc_and_read_xml { |doc| doc.h6 "Smallest" }
assert_includes xml, 'w:val="Heading6"'
end
def test_heading_with_block
xml = create_doc_and_read_xml do |doc|
doc.h1 do
doc.text "Part 1 "
doc.b { doc.text "Bold" }
end
end
assert_includes xml, 'w:val="Heading1"'
assert_includes xml, "Part 1 "
assert_includes xml, "<w:b/>"
assert_includes xml, "Bold"
end
def test_multiple_headings
xml = create_doc_and_read_xml do |doc|
doc.h1 "Title"
doc.h2 "Chapter 1"
doc.h3 "Section 1.1"
doc.p "Normal paragraph"
end
assert_includes xml, 'w:val="Heading1"'
assert_includes xml, 'w:val="Heading2"'
assert_includes xml, 'w:val="Heading3"'
# Regular paragraph should not have pStyle
assert_equal 3, xml.scan("<w:pStyle").count
end
def test_heading_styles_in_styles_xml
xml_files = create_doc_and_read_all_xml do |doc|
doc.h1 "Test"
end
styles_xml = xml_files["word/styles.xml"]
assert styles_xml, "styles.xml should exist"
assert_includes styles_xml, 'w:styleId="Heading1"'
assert_includes styles_xml, "<w:b/>"
assert_includes styles_xml, "<w:sz"
end
end