summaryrefslogtreecommitdiffhomepage
path: root/test/stylesheet/tc_table_style.rb
blob: defa0531fa84f02a53f8e63bf3920facf11c7fa7 (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
45
46
# frozen_string_literal: true

require 'tc_helper'

class TestTableStyle < Test::Unit::TestCase
  def setup
    @item = Axlsx::TableStyle.new "fisher"
  end

  def teardown; end

  def test_initialiation
    assert_equal("fisher", @item.name)
    assert_nil(@item.pivot)
    assert_nil(@item.table)
    ts = Axlsx::TableStyle.new 'price', pivot: true, table: true

    assert_equal('price', ts.name)
    assert(ts.pivot)
    assert(ts.table)
  end

  def test_name
    assert_raise(ArgumentError) { @item.name = -1.1 }
    assert_nothing_raised { @item.name = "lovely table style" }
    assert_equal("lovely table style", @item.name)
  end

  def test_pivot
    assert_raise(ArgumentError) { @item.pivot = -1.1 }
    assert_nothing_raised { @item.pivot = true }
    assert(@item.pivot)
  end

  def test_table
    assert_raise(ArgumentError) { @item.table = -1.1 }
    assert_nothing_raised { @item.table = true }
    assert(@item.table)
  end

  def test_to_xml_string
    doc = Nokogiri::XML(@item.to_xml_string)

    assert(doc.xpath("//tableStyle[@name='#{@item.name}']"))
  end
end