All checks were successful
CI Pipeline / build (pull_request) Successful in 12s
Adds these new styling and formatting nodes * strike * highlight * linebreaks * pagebreaks * Hyperlinks
128 lines
3.1 KiB
Ruby
128 lines
3.1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require "test_helper"
|
|
|
|
class HyperlinkTest < Minitest::Test
|
|
include NotareTestHelpers
|
|
|
|
def test_simple_hyperlink
|
|
xml = create_doc_and_read_xml do |doc|
|
|
doc.p do
|
|
doc.link "https://example.com", "Example"
|
|
end
|
|
end
|
|
|
|
assert_includes xml, '<w:hyperlink r:id="rId2"'
|
|
assert_includes xml, "Example"
|
|
assert_includes xml, '<w:u w:val="single"/>'
|
|
assert_includes xml, '<w:color w:val="0000FF"/>'
|
|
end
|
|
|
|
def test_hyperlink_url_as_text
|
|
xml = create_doc_and_read_xml do |doc|
|
|
doc.p do
|
|
doc.link "https://example.com"
|
|
end
|
|
end
|
|
|
|
assert_includes xml, "https://example.com"
|
|
end
|
|
|
|
def test_hyperlink_with_block
|
|
xml = create_doc_and_read_xml do |doc|
|
|
doc.p do
|
|
doc.link "https://example.com" do
|
|
doc.b { doc.text "Bold Link" }
|
|
end
|
|
end
|
|
end
|
|
|
|
assert_includes xml, '<w:hyperlink r:id="rId2"'
|
|
assert_includes xml, "<w:b/>"
|
|
assert_includes xml, "Bold Link"
|
|
end
|
|
|
|
def test_hyperlink_relationship
|
|
xml_files = create_doc_and_read_all_xml do |doc|
|
|
doc.p do
|
|
doc.link "https://example.com", "Example"
|
|
end
|
|
end
|
|
|
|
rels = xml_files["word/_rels/document.xml.rels"]
|
|
assert_includes rels, "https://example.com"
|
|
assert_includes rels, 'TargetMode="External"'
|
|
assert_includes rels, "relationships/hyperlink"
|
|
end
|
|
|
|
def test_multiple_hyperlinks
|
|
xml = create_doc_and_read_xml do |doc|
|
|
doc.p do
|
|
doc.link "https://one.com", "One"
|
|
doc.text " and "
|
|
doc.link "https://two.com", "Two"
|
|
end
|
|
end
|
|
|
|
assert_includes xml, '<w:hyperlink r:id="rId2"'
|
|
assert_includes xml, '<w:hyperlink r:id="rId3"'
|
|
assert_includes xml, "One"
|
|
assert_includes xml, "Two"
|
|
end
|
|
|
|
def test_hyperlink_in_list_item
|
|
xml = create_doc_and_read_xml do |doc|
|
|
doc.ul do
|
|
doc.li do
|
|
doc.link "https://example.com", "Link in list"
|
|
end
|
|
end
|
|
end
|
|
|
|
assert_includes xml, '<w:hyperlink r:id="rId3"'
|
|
assert_includes xml, "Link in list"
|
|
end
|
|
|
|
def test_hyperlink_in_table_cell
|
|
xml = create_doc_and_read_xml do |doc|
|
|
doc.table do
|
|
doc.tr do
|
|
doc.td do
|
|
doc.link "https://example.com", "Link in table"
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
assert_includes xml, '<w:hyperlink r:id="rId2"'
|
|
assert_includes xml, "Link in table"
|
|
end
|
|
|
|
def test_hyperlink_with_surrounding_text
|
|
xml = create_doc_and_read_xml do |doc|
|
|
doc.p do
|
|
doc.text "Visit "
|
|
doc.link "https://example.com", "our site"
|
|
doc.text " for more info."
|
|
end
|
|
end
|
|
|
|
assert_includes xml, "Visit "
|
|
assert_includes xml, "our site"
|
|
assert_includes xml, " for more info."
|
|
end
|
|
|
|
def test_multiple_hyperlinks_relationships
|
|
xml_files = create_doc_and_read_all_xml do |doc|
|
|
doc.p do
|
|
doc.link "https://one.com", "One"
|
|
doc.link "https://two.com", "Two"
|
|
end
|
|
end
|
|
|
|
rels = xml_files["word/_rels/document.xml.rels"]
|
|
assert_includes rels, "https://one.com"
|
|
assert_includes rels, "https://two.com"
|
|
end
|
|
end
|