test/workbook/worksheet/tc_worksheet.rb in axlsx-1.3.4 vs test/workbook/worksheet/tc_worksheet.rb in axlsx-1.3.5

- old
+ new

@@ -17,13 +17,20 @@ def test_name_is_html_encoded @ws.name = '<foo> & <bar>' assert_equal(@ws.name, '&lt;foo&gt; &amp; &lt;bar&gt;') end - def test_name_exception_on_colon + def test_name_exception_on_invalid_character assert_raises(ArgumentError) { @ws.name = 'foo:bar' } + assert_raises(ArgumentError) { @ws.name = 'foo[bar' } + assert_raises(ArgumentError) { @ws.name = 'foo]bar' } + assert_raises(ArgumentError) { @ws.name = 'foo*bar' } + assert_raises(ArgumentError) { @ws.name = 'foo/bar' } + assert_raises(ArgumentError) { @ws.name = 'foo\bar' } + assert_raises(ArgumentError) { @ws.name = 'foo?bar' } end + def test_page_margins assert(@ws.page_margins.is_a? Axlsx::PageMargins) end def test_page_margins_yeild @@ -166,10 +173,16 @@ assert @ws.drawing == nil @ws.add_chart(Axlsx::Pie3DChart) assert @ws.drawing.is_a?(Axlsx::Drawing) end + def test_add_pivot_table + assert(@ws.workbook.pivot_tables.empty?, "the sheet's workbook should not have any pivot tables by default") + @ws.add_pivot_table 'G5:G6', 'A1:D:10' + assert_equal(@ws.workbook.pivot_tables.size, 1, "add_pivot_tables adds a pivot_table to the workbook") + end + def test_col_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] @@ -364,10 +377,11 @@ @ws.print_options.set :headings => true @ws.auto_filter.range = "A1:C3" @ws.merge_cells "A4:A5" @ws.add_chart Axlsx::Pie3DChart @ws.add_table "E1:F3" + @ws.add_pivot_table 'G5:G6', 'A1:D10' schema = Nokogiri::XML::Schema(File.open(Axlsx::SML_XSD)) doc = Nokogiri::XML(@ws.to_xml_string) assert(schema.validate(doc).map { |e| puts e.message; e }.empty?, schema.validate(doc).map { |e| e.message }.join('\n')) end @@ -380,17 +394,24 @@ assert_equal(@ws.relationships.size, 1, "multiple charts still only result in one relationship") c = @ws.add_comment :text => 'builder', :author => 'bob', :ref => @ws.rows.last.cells.last assert_equal(@ws.relationships.size, 4, "adding a comment adds 3 relationships") c = @ws.add_comment :text => 'not that is a comment!', :author => 'travis', :ref => "A1" assert_equal(@ws.relationships.size, 4, "adding multiple comments in the same worksheet should not add any additional comment relationships") + c = @ws.add_pivot_table 'G5:G6', 'A1:D10' + assert_equal(@ws.relationships.size, 5, "adding a pivot table adds 1 relationship") end def test_name_unique assert_raise(ArgumentError, "worksheet name must be unique") { n = @ws.name; @ws.workbook.add_worksheet(:name=> n) } end + def test_name_unique_only_checks_other_worksheet_names + assert_nothing_raised { @ws.name = @ws.name } + assert_nothing_raised { Axlsx::Package.new.workbook.add_worksheet :name => 'Sheet1' } + end + def test_name_size assert_raise(ArgumentError, "name too long!") { @ws.name = Array.new(32, "A").join() } assert_nothing_raised { @ws.name = Array.new(31, "A").join() } end @@ -457,6 +478,29 @@ @ws.auto_filter.range = 'A1:D9' @ws.auto_filter.add_column 0, :filters, :filter_items => [1] doc = Nokogiri::XML(@ws.to_xml_string) assert(doc.xpath('//sheetPr[@filterMode="true"]')) end + + def test_outline_level_rows + 3.times { @ws.add_row [1,2,3] } + @ws.outline_level_rows 0, 2 + assert_equal(1, @ws.rows[0].outline_level) + assert_equal(true, @ws.rows[2].hidden) + assert_equal(true, @ws.sheet_view.show_outline_symbols) + end + + def test_outline_level_columns + 3.times { @ws.add_row [1,2,3] } + @ws.outline_level_columns 0, 2 + assert_equal(1, @ws.column_info[0].outline_level) + assert_equal(true, @ws.column_info[2].hidden) + assert_equal(true, @ws.sheet_view.show_outline_symbols) + end + + def test_worksheet_does_not_get_added_to_workbook_on_initialize_failure + assert_equal(1, @wb.worksheets.size) + assert_raise(ArgumentError) { @wb.add_worksheet(:name => 'Sheet1') } + assert_equal(1, @wb.worksheets.size) + end + end