Sha256: a25ca519b15334a1b81983dfd7800f4d5e9449228fc785b09f2bc17d40f6f780

Contents?: true

Size: 1.94 KB

Versions: 3

Compression:

Stored size: 1.94 KB

Contents

require 'tc_helper.rb'

class TestWorksheetHyperlink < Test::Unit::TestCase
  def setup
    p = Axlsx::Package.new
    wb = p.workbook
    @ws = wb.add_worksheet
    @options = { :location => 'https://github.com/randym/axlsx?foo=1&bar=2', :tooltip => 'axlsx', :ref => 'A1', :display => 'AXSLX', :target => :internal }
    @a = @ws.add_hyperlink @options
  end

  def test_initailize
    assert_raise(ArgumentError) { Axlsx::WorksheetHyperlink.new }
  end

  def test_location
    assert_equal(@options[:location], @a.location)
  end

  def test_tooltip
    assert_equal(@options[:tooltip], @a.tooltip)
  end

  def test_target
    assert_equal(@options[:target], @a.instance_values['target'])
  end

  def test_display
    assert_equal(@options[:display], @a.display)
  end
  def test_ref
    assert_equal(@options[:ref], @a.ref)
  end

  def test_id
    @a.target = :external

    assert_equal("rId1", @a.id)
    @a.target = :internal
    assert_equal(nil, @a.id)
  end


  def test_to_xml_string_with_non_external
    doc = Nokogiri::XML(@ws.to_xml_string)
    assert_equal(doc.xpath("//xmlns:hyperlink[@ref='#{@a.ref}']").size, 1)
    assert_equal(doc.xpath("//xmlns:hyperlink[@tooltip='#{@a.tooltip}']").size, 1)
    assert_equal(doc.xpath("//xmlns:hyperlink[@location='#{@a.location}']").size, 1)
    assert_equal(doc.xpath("//xmlns:hyperlink[@display='#{@a.display}']").size, 1)
    assert_equal(doc.xpath("//xmlns:hyperlink[@r:id='#{@a.id}']").size, 0)
  end

  def test_to_xml_stirng_with_external
    @a.target = :external
    doc = Nokogiri::XML(@ws.to_xml_string)
    assert_equal(doc.xpath("//xmlns:hyperlink[@ref='#{@a.ref}']").size, 1)
    assert_equal(doc.xpath("//xmlns:hyperlink[@tooltip='#{@a.tooltip}']").size, 1)
    assert_equal(doc.xpath("//xmlns:hyperlink[@display='#{@a.display}']").size, 1)
    assert_equal(doc.xpath("//xmlns:hyperlink[@location='#{@a.location}']").size, 0)
    assert_equal(doc.xpath("//xmlns:hyperlink[@r:id='#{@a.id}']").size, 1)
  end
end


Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
axlsx-1.3.6 test/workbook/worksheet/tc_worksheet_hyperlink.rb
axlsx-1.3.5 test/workbook/worksheet/tc_worksheet_hyperlink.rb
axlsx-1.3.4 test/workbook/worksheet/tc_worksheet_hyperlink.rb