summaryrefslogtreecommitdiffhomepage
path: root/test/workbook/worksheet/tc_sheet_format_pr.rb
blob: ac7048cd893f04dbee7e75b58bda784f243fce6d (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# frozen_string_literal: true

require 'tc_helper'

class TestSheetFormatPr < Test::Unit::TestCase
  def setup
    @options = {
      base_col_width: 5,
      default_col_width: 7.2,
      default_row_height: 5.2,
      custom_height: true,
      zero_height: false,
      thick_top: true,
      thick_bottom: true,
      outline_level_row: 0,
      outline_level_col: 0
    }
    @sheet_format_pr = Axlsx::SheetFormatPr.new(@options)
  end

  def test_default_initialization
    sheet_format_pr = Axlsx::SheetFormatPr.new

    assert_equal 8, sheet_format_pr.base_col_width
    assert_equal 18, sheet_format_pr.default_row_height
  end

  def test_initialization_with_options
    @options.each do |key, value|
      assert_equal value, @sheet_format_pr.instance_variable_get("@#{key}")
    end
  end

  def test_base_col_width
    assert_raise(ArgumentError) { @sheet_format_pr.base_col_width = :foo }
    assert_nothing_raised { @sheet_format_pr.base_col_width = 1 }
  end

  def test_outline_level_row
    assert_raise(ArgumentError) { @sheet_format_pr.outline_level_row = :foo }
    assert_nothing_raised { @sheet_format_pr.outline_level_row = 1 }
  end

  def test_outline_level_col
    assert_raise(ArgumentError) { @sheet_format_pr.outline_level_col = :foo }
    assert_nothing_raised { @sheet_format_pr.outline_level_col = 1 }
  end

  def test_default_row_height
    assert_raise(ArgumentError) { @sheet_format_pr.default_row_height = :foo }
    assert_nothing_raised { @sheet_format_pr.default_row_height = 1.0 }
  end

  def test_default_col_width
    assert_raise(ArgumentError) { @sheet_format_pr.default_col_width = :foo }
    assert_nothing_raised { @sheet_format_pr.default_col_width = 1.0 }
  end

  def test_custom_height
    assert_raise(ArgumentError) { @sheet_format_pr.custom_height = :foo }
    assert_nothing_raised { @sheet_format_pr.custom_height = true }
  end

  def test_zero_height
    assert_raise(ArgumentError) { @sheet_format_pr.zero_height = :foo }
    assert_nothing_raised { @sheet_format_pr.zero_height = true }
  end

  def test_thick_top
    assert_raise(ArgumentError) { @sheet_format_pr.thick_top = :foo }
    assert_nothing_raised { @sheet_format_pr.thick_top = true }
  end

  def test_thick_bottom
    assert_raise(ArgumentError) { @sheet_format_pr.thick_bottom = :foo }
    assert_nothing_raised { @sheet_format_pr.thick_bottom = true }
  end

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

    assert doc.xpath("sheetFormatPr[@thickBottom=1]")
    assert doc.xpath("sheetFormatPr[@baseColWidth=5]")
    assert doc.xpath("sheetFormatPr[@default_col_width=7.2]")
    assert doc.xpath("sheetFormatPr[@default_row_height=5.2]")
    assert doc.xpath("sheetFormatPr[@custom_height=1]")
    assert doc.xpath("sheetFormatPr[@zero_height=0]")
    assert doc.xpath("sheetFormatPr[@thick_top=1]")
    assert doc.xpath("sheetFormatPr[@outline_level_row=0]")
    assert doc.xpath("sheetFormatPr[@outline_level_col=0]")
  end
end