summaryrefslogtreecommitdiffhomepage
path: root/test/workbook/worksheet/tc_border_creator.rb
blob: 86b47fc18f540f36b6a4b9789ace394f55e27117 (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
require 'tc_helper.rb'

class TestBorderCreator < Test::Unit::TestCase
  def setup
    @p = Axlsx::Package.new
    @wb = @p.workbook
    @ws = @wb.add_worksheet
  end

  def test_defaults
    3.times do
      @ws.add_row [1,2,3]
    end

    bc = Axlsx::BorderCreator.new(@ws, @ws["A1:B2"], {})
    assert_equal bc.instance_variable_get(:@edges), Axlsx::Border::EDGES
    assert_equal bc.instance_variable_get(:@width), :thin
    assert_equal bc.instance_variable_get(:@color), "000000"

    bc = Axlsx::BorderCreator.new(@ws, @ws["A1:B2"], ["top"])
    assert_equal bc.instance_variable_get(:@edges), [:top]
    assert_equal bc.instance_variable_get(:@width), :thin
    assert_equal bc.instance_variable_get(:@color), "000000"

    bc = Axlsx::BorderCreator.new(@ws, @ws["A1:B2"], :all)
    assert_equal bc.instance_variable_get(:@edges), Axlsx::Border::EDGES
    assert_equal bc.instance_variable_get(:@width), :thin
    assert_equal bc.instance_variable_get(:@color), "000000"

    bc = Axlsx::BorderCreator.new(@ws, @ws["A1:B2"], [:foo])
    assert_equal bc.instance_variable_get(:@edges), []
    assert_equal bc.instance_variable_get(:@width), :thin
    assert_equal bc.instance_variable_get(:@color), "000000"

    bc = Axlsx::BorderCreator.new(@ws, @ws["A1:B2"], {edges: ["top"], style: :thick, color: "ffffff"})
    assert_equal bc.instance_variable_get(:@edges), [:top]
    assert_equal bc.instance_variable_get(:@width), :thick
    assert_equal bc.instance_variable_get(:@color), "ffffff"
  end

  def test_draw
    5.times do
      @ws.add_row [1,2,3,4,5]
    end

    bc = Axlsx::BorderCreator.new(@ws, @ws["A1:C3"], {edges: ["top", :left], style: :thick, color: "ffffff"})

    bc.draw

    assert_equal 2, @ws.styles.borders.size

    @wb.apply_styles

    assert_equal 5, @ws.styles.borders.size

    assert_equal 2, @ws.styles.borders[2].prs.size
    assert_equal ["FFFFFFFF"], @ws.styles.borders[2].prs.map(&:color).map(&:rgb).uniq
    assert_equal [:thick], @ws.styles.borders[2].prs.map(&:style).uniq
    assert_equal [:left, :top], @ws.styles.borders[2].prs.map(&:name)


    assert_equal 1, @ws.styles.borders[3].prs.size
    assert_equal ["FFFFFFFF"], @ws.styles.borders[3].prs.map(&:color).map(&:rgb).uniq
    assert_equal [:thick], @ws.styles.borders[3].prs.map(&:style).uniq
    assert_equal [:top], @ws.styles.borders[3].prs.map(&:name)

    assert_equal 1, @ws.styles.borders[4].prs.size
    assert_equal ["FFFFFFFF"], @ws.styles.borders[4].prs.map(&:color).map(&:rgb).uniq
    assert_equal [:thick], @ws.styles.borders[4].prs.map(&:style).uniq
    assert_equal [:left], @ws.styles.borders[4].prs.map(&:name)
  end

end