axlsx_styler 1.0.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,84 +0,0 @@
1
- require 'test_helper'
2
-
3
- class GeneralTest < MiniTest::Test
4
-
5
- def setup
6
- @axlsx = Axlsx::Package.new
7
- @workbook = @axlsx.workbook
8
- end
9
-
10
- def test_adding_styled_cells
11
- p = Axlsx::Package.new
12
- wb = p.workbook
13
- wb.add_styled_cell 'Cell 1'
14
- wb.add_styled_cell 'Cell 2'
15
- assert_equal ['Cell 1', 'Cell 2'].to_set, wb.styled_cells
16
- assert_nil wb.styles_applied
17
- end
18
-
19
- def test_can_add_style
20
- p = Axlsx::Package.new
21
- wb = p.workbook
22
- sheet = wb.add_worksheet
23
- row = sheet.add_row ["x", "y"]
24
- cell = row.cells.first
25
-
26
- cell.add_style b: true
27
- assert_equal({b: true}, cell.raw_style)
28
- end
29
-
30
- def test_table_with_num_fmt
31
- filename = 'num_fmt_test'
32
- t = Time.now
33
- day = 24 * 60 * 60
34
- @workbook.add_worksheet do |sheet|
35
- sheet.add_row %w(Date Count Percent)
36
- sheet.add_row [t - 2 * day, 2, 2.to_f.round(2) / 11]
37
- sheet.add_row [t - 1 * day, 3, 3.to_f.round(2) / 11]
38
- sheet.add_row [t, 6, 6.to_f.round(2) / 11]
39
-
40
- sheet.add_style 'A1:B1', b: true
41
- sheet.add_style 'A2:A4', format_code: 'YYYY-MM-DD hh:mm:ss'
42
- end
43
- serialize(filename)
44
- assert_equal 2, @workbook.styles.style_index.count
45
- assert_equal 2 + 2, @workbook.styles.style_index.keys.max
46
- assert_equal 5, @workbook.styled_cells.count
47
- end
48
-
49
- def test_duplicate_styles
50
- filename = 'duplicate_styles'
51
- @workbook.add_worksheet do |sheet|
52
- sheet.add_row %w(Index City)
53
- sheet.add_row [1, 'Ottawa']
54
- sheet.add_row [2, 'Boston']
55
-
56
- sheet.add_border 'A1:B1', [:bottom]
57
- sheet.add_border 'A1:B1', [:bottom]
58
- sheet.add_style 'A1:A3', b: true
59
- sheet.add_style 'A1:A3', b: true
60
- end
61
- serialize(filename)
62
- assert_equal 4, @workbook.styled_cells.count
63
- assert_equal 3, @workbook.styles.style_index.count
64
- end
65
-
66
- def test_multiple_named_styles
67
- filename = 'multiple_named_styles'
68
- bold_blue = { b: true, fg_color: '0000FF' }
69
- large = { sz: 16 }
70
- red = { fg_color: 'FF0000' }
71
- @workbook.add_worksheet do |sheet|
72
- sheet.add_row %w(Index City)
73
- sheet.add_row [1, 'Ottawa']
74
- sheet.add_row [2, 'Boston']
75
-
76
- sheet.add_style 'A1:B1', bold_blue, large
77
- sheet.add_style 'A1:A3', red
78
- end
79
- serialize(filename)
80
- assert_equal 4, @workbook.styled_cells.count
81
- assert_equal 3, @workbook.styles.style_index.count
82
- end
83
-
84
- end