# frozen_string_literal: true
require "test_helper"
class StyleTest < Minitest::Test
include NotareTestHelpers
def test_define_custom_style
xml_files = create_doc_and_read_all_xml do |doc|
doc.define_style :warning, bold: true, color: "FF0000"
doc.p "Test", style: :warning
end
styles_xml = xml_files["word/styles.xml"]
assert_includes styles_xml, 'w:styleId="Warning"'
assert_includes styles_xml, ""
assert_includes styles_xml, 'w:val="FF0000"'
end
def test_apply_style_to_paragraph
xml = create_doc_and_read_xml do |doc|
doc.p "Quote text", style: :quote
end
assert_includes xml, '"
assert_includes styles_xml, ""
assert_includes styles_xml, 'w:val="0000FF"'
assert_includes styles_xml, 'w:val="32"' # 16pt = 32 half-points
assert_includes styles_xml, 'w:ascii="Arial"'
assert_includes styles_xml, '"
end
def test_invalid_highlight_raises_error
assert_raises(ArgumentError) do
Notare::Style.new(:bad, highlight: "invalid_color")
end
end
def test_valid_highlight_colors
# Test a few valid highlight colors
%w[yellow red blue green cyan magenta].each do |color|
style = Notare::Style.new(:test, highlight: color)
assert_equal color, style.highlight
end
end
def test_highlight_in_text_run
xml_files = create_doc_and_read_all_xml do |doc|
doc.define_style :yellow_highlight, highlight: "yellow"
doc.p do
doc.text "Normal "
doc.text "highlighted", style: :yellow_highlight
end
end
# Highlight is in the style definition, not inline when using style reference
styles_xml = xml_files["word/styles.xml"]
assert_includes styles_xml, '