summaryrefslogtreecommitdiffhomepage
path: root/test/workbook/worksheet/tc_data_bar.rb
blob: 65995dd24d46f184e8e9c3ec00bfc32e877d3b40 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
require 'tc_helper.rb'

class TestDataBar < Test::Unit::TestCase
  def setup
    @data_bar = Axlsx::DataBar.new :color => "FF638EC6"
  end

  def test_defaults
    assert_equal @data_bar.minLength, 10
    assert_equal @data_bar.maxLength, 90
    assert_equal @data_bar.showValue, true
  end

  def test_override_default_cfvos
    data_bar = Axlsx::DataBar.new({:color => 'FF00FF00'}, {:type => :min, :val => "20"})
    assert_equal("20", data_bar.value_objects.first.val)
    assert_equal("0", data_bar.value_objects.last.val)
  end

  def test_minLength
    assert_raise(ArgumentError) { @data_bar.minLength = :invalid_type }
    assert_nothing_raised { @data_bar.minLength =  0}
    assert_equal(@data_bar.minLength, 0)
  end

  def test_maxLength
    assert_raise(ArgumentError) { @data_bar.maxLength = :invalid_type }
    assert_nothing_raised { @data_bar.maxLength =  0}
    assert_equal(@data_bar.maxLength, 0)
  end

  def test_showValue
    assert_raise(ArgumentError) { @data_bar.showValue = :invalid_type }
    assert_nothing_raised { @data_bar.showValue =  false}
    assert_equal(@data_bar.showValue, false)
  end

  def test_to_xml_string
    doc = Nokogiri::XML.parse(@data_bar.to_xml_string)
    assert_equal(doc.xpath(".//dataBar[@minLength=10][@maxLength=90][@showValue=1]").size, 1)
    assert_equal(doc.xpath(".//dataBar//cfvo").size, 2)
    assert_equal(doc.xpath(".//dataBar//color").size, 1)
  end
end