summaryrefslogtreecommitdiffhomepage
path: root/test/workbook/worksheet/tc_table_style_info.rb
blob: 6cb12b9478a82ec08c4c85032deb710ae43ad244 (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
47
48
49
50
51
52
53
54
55
# frozen_string_literal: true

require 'tc_helper'

class TestTableStyleInfo < Test::Unit::TestCase
  def setup
    p = Axlsx::Package.new
    @ws = p.workbook.add_worksheet
    40.times do
      @ws.add_row %w(aa bb cc dd ee ff gg hh ii jj kk)
    end
    @table = @ws.add_table(Axlsx::cell_range([@ws.rows.first.cells.first, @ws.rows.last.cells.last], false), name: 'foo')
    @options =  { show_first_column: 1,
                  show_last_column: 1,
                  show_row_stripes: 1,
                  show_column_stripes: 1,
                  name: "TableStyleDark4" }
  end

  def test_initialize
    table_style = Axlsx::TableStyleInfo.new @options

    @options.each do |key, value|
      assert_equal(value, table_style.send(key.to_sym))
    end
  end

  def test_boolean_properties
    table_style = Axlsx::TableStyleInfo.new
    @options.each_key do |key|
      assert_nothing_raised { table_style.send("#{key.to_sym}=", true) }
      assert_raises(ArgumentError) { table_style.send(key.to_sym, 'foo') }
    end
  end

  def doc
    @doc ||= Nokogiri::XML(Axlsx::TableStyleInfo.new(@options).to_xml_string)
  end

  def test_to_xml_string_first_column
    assert(doc.xpath('//tableStyleInfo[@showLastColumn=1]'))
  end

  def test_to_xml_string_row_stripes
    assert(doc.xpath('//tableStyleInfo[@showRowStripes=1]'))
  end

  def test_to_xml_string_column_stripes
    assert(doc.xpath('//tableStyleInfo[@showColumnStripes=1]'))
  end

  def test_to_xml_string_name
    assert(doc.xpath("//tableStyleInfo[@name=#{@options[:name]}]"))
  end
end