summaryrefslogtreecommitdiffhomepage
path: root/test/workbook/worksheet/tc_pivot_table.rb
diff options
context:
space:
mode:
authorGeremia Taglialatela <[email protected]>2023-04-13 13:13:34 +0200
committerGeremia Taglialatela <[email protected]>2023-05-03 16:05:17 +0200
commit350f7ae9a04f3d39c099cc54f7c04bf31f385d96 (patch)
treee84af2a70d3b18a0b94c784338faf48215c9c8a8 /test/workbook/worksheet/tc_pivot_table.rb
parente81036b76e734ab03fac31faafb9732f6b3b2928 (diff)
downloadcaxlsx-350f7ae9a04f3d39c099cc54f7c04bf31f385d96.tar.gz
caxlsx-350f7ae9a04f3d39c099cc54f7c04bf31f385d96.zip
Add RuboCop Minitest
Diffstat (limited to 'test/workbook/worksheet/tc_pivot_table.rb')
-rw-r--r--test/workbook/worksheet/tc_pivot_table.rb43
1 files changed, 29 insertions, 14 deletions
diff --git a/test/workbook/worksheet/tc_pivot_table.rb b/test/workbook/worksheet/tc_pivot_table.rb
index a5bb8906..91df5597 100644
--- a/test/workbook/worksheet/tc_pivot_table.rb
+++ b/test/workbook/worksheet/tc_pivot_table.rb
@@ -8,7 +8,8 @@ def shared_test_pivot_table_xml_validity(pivot_table)
errors.push error
puts error.message
end
- assert(errors.empty?, "error free validation")
+
+ assert_empty(errors, "error free validation")
end
class TestPivotTable < Test::Unit::TestCase
@@ -21,12 +22,13 @@ class TestPivotTable < Test::Unit::TestCase
end
def test_initialization
- assert(@ws.workbook.pivot_tables.empty?)
- assert(@ws.pivot_tables.empty?)
+ assert_empty(@ws.workbook.pivot_tables)
+ assert_empty(@ws.pivot_tables)
end
def test_add_pivot_table
pivot_table = @ws.add_pivot_table('G5:G6', 'A1:D5')
+
assert_equal('G5:G6', pivot_table.ref, 'ref assigned from first parameter')
assert_equal('A1:D5', pivot_table.range, 'range assigned from second parameter')
assert_equal('PivotTable1', pivot_table.name, 'name automatically generated')
@@ -42,6 +44,7 @@ class TestPivotTable < Test::Unit::TestCase
assert_equal(pivot_table.data_sheet.name, @ws.name, "must default to the same sheet the pivot table is added to")
pivot_table.data_sheet = data_sheet
+
assert_equal(pivot_table.data_sheet.name, data_sheet.name, "data sheet assigned to pivot table")
end
@@ -52,6 +55,7 @@ class TestPivotTable < Test::Unit::TestCase
pt.data = ['Sales']
pt.pages = ['Region']
end
+
assert_equal(['Year', 'Month'], pivot_table.rows)
assert_equal(['Type'], pivot_table.columns)
assert_equal([{ :ref => "Sales" }], pivot_table.data)
@@ -63,6 +67,7 @@ class TestPivotTable < Test::Unit::TestCase
pivot_table = @ws.add_pivot_table('G5:G6', 'A1:D5') do |pt|
pt.data = [{ :ref => "Sales", :subtotal => 'average' }]
end
+
assert_equal([{ :ref => "Sales", :subtotal => 'average' }], pivot_table.data)
end
@@ -74,6 +79,7 @@ class TestPivotTable < Test::Unit::TestCase
pt.data = ['Sales']
pt.pages = ['Region']
end
+
assert_equal(style_info_data, pivot_table.style_info)
shared_test_pivot_table_xml_validity(pivot_table)
end
@@ -83,6 +89,7 @@ class TestPivotTable < Test::Unit::TestCase
pt.data = ['Sales']
pt.rows = ['Year', 'Month']
end
+
assert_equal(['Year'], pivot_table.no_subtotals_on_headers)
end
@@ -91,9 +98,11 @@ class TestPivotTable < Test::Unit::TestCase
pt.data = ['Sales']
pt.rows = ['Year', 'Month']
end
+
assert_equal({ 'Month' => :ascending }, pivot_table.sort_on_headers)
pivot_table.sort_on_headers = { 'Month' => :descending }
+
assert_equal({ 'Month' => :descending }, pivot_table.sort_on_headers)
shared_test_pivot_table_xml_validity(pivot_table)
@@ -101,31 +110,36 @@ class TestPivotTable < Test::Unit::TestCase
def test_header_indices
pivot_table = @ws.add_pivot_table('G5:G6', 'A1:E5')
+
assert_equal(0, pivot_table.header_index_of('Year'))
assert_equal(1, pivot_table.header_index_of('Month'))
assert_equal(2, pivot_table.header_index_of('Region'))
assert_equal(3, pivot_table.header_index_of('Type'))
assert_equal(4, pivot_table.header_index_of('Sales'))
- assert_equal(nil, pivot_table.header_index_of('Missing'))
+ assert_nil(pivot_table.header_index_of('Missing'))
assert_equal(%w(A1 B1 C1 D1 E1), pivot_table.header_cell_refs)
end
def test_pn
@ws.add_pivot_table('G5:G6', 'A1:D5')
- assert_equal(@ws.pivot_tables.first.pn, "pivotTables/pivotTable1.xml")
+
+ assert_equal("pivotTables/pivotTable1.xml", @ws.pivot_tables.first.pn)
end
def test_index
@ws.add_pivot_table('G5:G6', 'A1:D5')
+
assert_equal(@ws.pivot_tables.first.index, @ws.workbook.pivot_tables.index(@ws.pivot_tables.first))
end
def test_relationships
- assert(@ws.relationships.empty?)
+ assert_empty(@ws.relationships)
@ws.add_pivot_table('G5:G6', 'A1:D5')
- assert_equal(@ws.relationships.size, 1, "adding a pivot table adds a relationship")
+
+ assert_equal(1, @ws.relationships.size, "adding a pivot table adds a relationship")
@ws.add_pivot_table('G10:G11', 'A1:D5')
- assert_equal(@ws.relationships.size, 2, "adding a pivot table adds a relationship")
+
+ assert_equal(2, @ws.relationships.size, "adding a pivot table adds a relationship")
end
def test_to_xml_string
@@ -150,6 +164,7 @@ class TestPivotTable < Test::Unit::TestCase
pt.data = [{ :ref => "Sales", :subtotal => 'sum', num_fmt: 4 }]
end
doc = Nokogiri::XML(pivot_table.to_xml_string)
+
assert_equal('4', doc.at_css('dataFields dataField')['numFmtId'], 'adding format options to pivot_table')
end
@@ -167,9 +182,9 @@ class TestPivotTable < Test::Unit::TestCase
xml = pivot_table.to_xml_string
- assert(!xml.include?('dataOnRows'))
- assert(xml.include?('colFields'))
- assert(xml.include?('colItems'))
+ refute_includes(xml, 'dataOnRows')
+ assert_includes(xml, 'colFields')
+ assert_includes(xml, 'colItems')
doc = Nokogiri::XML(pivot_table.to_xml_string)
@@ -195,9 +210,9 @@ class TestPivotTable < Test::Unit::TestCase
xml = pivot_table.to_xml_string
- assert(xml.include?('dataOnRows'))
- assert(xml.include?('colItems'))
+ assert_includes(xml, 'dataOnRows')
+ assert_includes(xml, 'colItems')
- assert(!xml.include?('colFields'))
+ refute_includes(xml, 'colFields')
end
end