# frozen_string_literal: true require 'tc_helper' class TestDLbls < Test::Unit::TestCase def setup @d_lbls = Axlsx::DLbls.new(Axlsx::Pie3DChart) @boolean_attributes = [:show_legend_key, :show_val, :show_cat_name, :show_ser_name, :show_percent, :show_bubble_size, :show_leader_lines] end def test_initialization assert_equal(:bestFit, @d_lbls.d_lbl_pos) @boolean_attributes.each do |attr| refute(@d_lbls.send(attr)) end end def test_initialization_with_optoins options_hash = @boolean_attributes.to_h { |name| [name, true] } d_lbls = Axlsx::DLbls.new(Axlsx::Pie3DChart, options_hash.merge({ d_lbl_pos: :t })) @boolean_attributes.each do |attr| assert(d_lbls.send(attr), "boolean attributes set by options") end assert_equal(:t, d_lbls.d_lbl_pos, "d_lbl_pos set by options") end def test_d_lbl_pos assert_raise(ArgumentError, 'invlaid label positions are rejected') { @d_lbls.d_lbl_pos = :upside_down } assert_nothing_raised('accepts valid label position') { @d_lbls.d_lbl_pos = :ctr } end def test_boolean_attributes @boolean_attributes.each do |attr| assert_raise(ArgumentError, "rejects non boolean value for #{attr}") { @d_lbls.send("#{attr}=", :foo) } assert_nothing_raised("accepts boolean value for #{attr}") { @d_lbls.send("#{attr}=", true) } assert_nothing_raised("accepts boolean value for #{attr}") { @d_lbls.send("#{attr}=", false) } end end def test_to_xml_string str = +'' str << '' @d_lbls.to_xml_string(str) str << '' doc = Nokogiri::XML(str) Axlsx.instance_values_for(@d_lbls).each do |name, value| assert(doc.xpath("//c:#{Axlsx::camel(name, false)}[@val='#{value}']"), "#{name} is properly serialized") end end end