test/workbook/worksheet/tc_worksheet.rb in axlsx-1.3.6 vs test/workbook/worksheet/tc_worksheet.rb in axlsx-2.0.0
- old
+ new
@@ -121,13 +121,11 @@
ws = @ws.workbook.add_worksheet
assert_equal(ws.rels_pn, "worksheets/_rels/sheet2.xml.rels")
end
def test_rId
- assert_equal(@ws.rId, "rId1")
- ws = @ws.workbook.add_worksheet
- assert_equal(ws.rId, "rId2")
+ assert_equal @ws.workbook.relationships.for(@ws).Id, @ws.rId
end
def test_index
assert_equal(@ws.index, @ws.workbook.worksheets.index(@ws))
end
@@ -167,10 +165,31 @@
assert(@ws.workbook.charts.empty?, "the sheet's workbook should not have any charts by default")
@ws.add_chart Axlsx::Pie3DChart
assert_equal(@ws.workbook.charts.size, 1, "add_chart adds a chart to the workbook")
end
+ def test_add_page_break_with_string_cell_ref
+ assert(@ws.row_breaks.empty?)
+ assert(@ws.col_breaks.empty?)
+ @ws.add_page_break("B1")
+ assert_equal(1, @ws.row_breaks.size)
+ assert_equal(1, @ws.col_breaks.size)
+ end
+
+ def test_add_page_break_with_cell
+ @ws.add_row [1, 2, 3, 4]
+ @ws.add_row [1, 2, 3, 4]
+
+
+ assert(@ws.row_breaks.empty?)
+ assert(@ws.col_breaks.empty?)
+ @ws.add_page_break(@ws.rows.last.cells[1])
+ assert_equal(1, @ws.row_breaks.size)
+ assert_equal(1, @ws.col_breaks.size)
+ end
+
+
def test_drawing
assert @ws.drawing == nil
@ws.add_chart(Axlsx::Pie3DChart)
assert @ws.drawing.is_a?(Axlsx::Drawing)
end
@@ -203,17 +222,24 @@
end
def test_cols
@ws.add_row [1,2,3,4]
@ws.add_row [1,2,3,4]
+ @ws.add_row [1,2,3]
@ws.add_row [1,2,3,4]
- @ws.add_row [1,2,3,4]
c = @ws.cols[1]
assert_equal(c.size, 4)
assert_equal(c[0].value, 2)
end
+ def test_cols_with_block
+ @ws.add_row [1,2,3]
+ @ws.add_row [1]
+ cols = @ws.cols {|row, column| :foo }
+ assert_equal(:foo, cols[1][1])
+ end
+
def test_row_style
@ws.add_row [1,2,3,4]
@ws.add_row [1,2,3,4]
@ws.add_row [1,2,3,4]
@ws.add_row [1,2,3,4]
@@ -286,10 +312,16 @@
doc = Nokogiri::XML(@ws.to_xml_string)
assert_equal(doc.xpath('//xmlns:worksheet/xmlns:mergeCells/xmlns:mergeCell[@ref="A1:D1"]').size, 1)
assert_equal(doc.xpath('//xmlns:worksheet/xmlns:mergeCells/xmlns:mergeCell[@ref="E1:F1"]').size, 1)
end
+ def test_to_xml_string_row_breaks
+ @ws.add_page_break("A1")
+ doc = Nokogiri::XML(@ws.to_xml_string)
+ assert_equal(doc.xpath('//xmlns:worksheet/xmlns:rowBreaks/xmlns:brk[@id="0"]').size, 1)
+ end
+
def test_to_xml_string_sheet_protection
@ws.sheet_protection.password = 'fish'
doc = Nokogiri::XML(@ws.to_xml_string)
assert(doc.xpath('//xmlns:sheetProtection'))
end
@@ -332,19 +364,19 @@
end
def test_to_xml_string_drawing
@ws.add_chart Axlsx::Pie3DChart
doc = Nokogiri::XML(@ws.to_xml_string)
- assert_equal(doc.xpath('//xmlns:worksheet/xmlns:drawing[@r:id="rId1"]').size, 1)
+ assert_equal @ws.send(:worksheet_drawing).relationship.Id, doc.xpath('//xmlns:worksheet/xmlns:drawing').first["r:id"]
end
def test_to_xml_string_tables
@ws.add_row ["one", "two"]
@ws.add_row [1, 2]
- @ws.add_table "A1:B2"
+ table = @ws.add_table "A1:B2"
doc = Nokogiri::XML(@ws.to_xml_string)
assert_equal(doc.xpath('//xmlns:worksheet/xmlns:tableParts[@count="1"]').size, 1)
- assert_equal(doc.xpath('//xmlns:worksheet/xmlns:tableParts/xmlns:tablePart[@r:id="rId1"]').size, 1)
+ assert_equal table.rId, doc.xpath('//xmlns:worksheet/xmlns:tableParts/xmlns:tablePart').first["r:id"]
end
def test_to_xml_string
schema = Nokogiri::XML::Schema(File.open(Axlsx::SML_XSD))
doc = Nokogiri::XML(@ws.to_xml_string)