test/workbook/worksheet/tc_worksheet.rb in axlsx-1.1.4 vs test/workbook/worksheet/tc_worksheet.rb in axlsx-1.1.5

- old
+ new

@@ -23,28 +23,56 @@ assert(pm.is_a? Axlsx::PageMargins) assert(@ws.page_margins == pm) end end + def test_page_setup + assert(@ws.page_setup.is_a? Axlsx::PageSetup) + end + + def test_page_setup_yield + @ws.page_setup do |ps| + assert(ps.is_a? Axlsx::PageSetup) + assert(@ws.page_setup == ps) + end + end + + def test_print_options + assert(@ws.print_options.is_a? Axlsx::PrintOptions) + end + + def test_print_options_yield + @ws.print_options do |po| + assert(po.is_a? Axlsx::PrintOptions) + assert(@ws.print_options == po) + end + end + def test_no_autowidth @ws.workbook.use_autowidth = false @ws.add_row [1,2,3,4] assert_equal(@ws.column_info[0].width, nil) end def test_initialization_options page_margins = {:left => 2, :right => 2, :bottom => 2, :top => 2, :header => 2, :footer => 2} - optioned = @ws.workbook.add_worksheet(:name => 'bob', :page_margins => page_margins, :selected => true, :show_gridlines => false) - assert_equal(optioned.page_margins.left, page_margins[:left]) - assert_equal(optioned.page_margins.right, page_margins[:right]) - assert_equal(optioned.page_margins.top, page_margins[:top]) - assert_equal(optioned.page_margins.bottom, page_margins[:bottom]) - assert_equal(optioned.page_margins.header, page_margins[:header]) - assert_equal(optioned.page_margins.footer, page_margins[:footer]) + page_setup = {:fit_to_height => 1, :fit_to_width => 1, :orientation => :landscape, :paper_width => "210mm", :paper_height => "297mm", :scale => 80} + print_options = {:grid_lines => true, :headings => true, :horizontal_centered => true, :vertical_centered => true} + optioned = @ws.workbook.add_worksheet(:name => 'bob', :page_margins => page_margins, :page_setup => page_setup, :print_options => print_options, :selected => true, :show_gridlines => false) + page_margins.keys.each do |key| + assert_equal(page_margins[key], optioned.page_margins.send(key)) + end + page_setup.keys.each do |key| + assert_equal(page_setup[key], optioned.page_setup.send(key)) + end + print_options.keys.each do |key| + assert_equal(print_options[key], optioned.print_options.send(key)) + end assert_equal(optioned.name, 'bob') assert_equal(optioned.selected, true) assert_equal(optioned.show_gridlines, false) + end def test_use_gridlines assert_raise(ArgumentError) { @ws.show_gridlines = -1.1 } @@ -220,10 +248,28 @@ end doc = Nokogiri::XML(@ws.to_xml_string) assert_equal(doc.xpath('//xmlns:worksheet/xmlns:pageMargins[@left="9"][@right="7"]').size, 1) end + def test_to_xml_string_page_setup + @ws.page_setup do |ps| + ps.paper_width = "210mm" + ps.scale = 80 + end + doc = Nokogiri::XML(@ws.to_xml_string) + assert_equal(doc.xpath('//xmlns:worksheet/xmlns:pageSetup[@paperWidth="210mm"][@scale="80"]').size, 1) + end + + def test_to_xml_string_print_options + @ws.print_options do |po| + po.grid_lines = true + po.horizontal_centered = true + end + doc = Nokogiri::XML(@ws.to_xml_string) + assert_equal(doc.xpath('//xmlns:worksheet/xmlns:printOptions[@gridLines="true"][@horizontalCentered="true"]').size, 1) + end + def test_to_xml_string_drawing c = @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) end @@ -256,10 +302,12 @@ # Make sure the XML for all optional elements (like pageMargins, autoFilter, ...) # is generated in correct order. def test_valid_with_optional_elements @ws.page_margins.set :left => 9 + @ws.page_setup.set :fit_to_width => 1 + @ws.print_options.set :headings => true @ws.auto_filter = "A1:C3" @ws.merge_cells "A4:A5" @ws.add_chart Axlsx::Pie3DChart @ws.add_table "E1:F3" schema = Nokogiri::XML::Schema(File.open(Axlsx::SML_XSD)) @@ -272,14 +320,19 @@ assert(errors.empty?, "error free validation") end def test_relationships + @ws.add_row [1,2,3] assert(@ws.relationships.empty?, "No Drawing relationship until you add a chart") c = @ws.add_chart Axlsx::Pie3DChart assert_equal(@ws.relationships.size, 1, "adding a chart creates the relationship") c = @ws.add_chart Axlsx::Pie3DChart 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") end def test_name_unique assert_raise(ArgumentError, "worksheet name must be unique") { n = @ws.name; @ws.workbook.add_worksheet(:name=> @ws) }