summaryrefslogtreecommitdiffhomepage
path: root/test/drawing/tc_chart.rb
diff options
context:
space:
mode:
authorRandy Morgan <[email protected]>2011-11-20 23:22:04 +0900
committerRandy Morgan <[email protected]>2011-11-20 23:22:04 +0900
commite53f04284618713b0a90b7a691425c380e829476 (patch)
tree801fea138160f9af426d62bf94ad5bf97123ece9 /test/drawing/tc_chart.rb
downloadcaxlsx-e53f04284618713b0a90b7a691425c380e829476.tar.gz
caxlsx-e53f04284618713b0a90b7a691425c380e829476.zip
first commit
Diffstat (limited to 'test/drawing/tc_chart.rb')
-rw-r--r--test/drawing/tc_chart.rb59
1 files changed, 59 insertions, 0 deletions
diff --git a/test/drawing/tc_chart.rb b/test/drawing/tc_chart.rb
new file mode 100644
index 00000000..8e26a832
--- /dev/null
+++ b/test/drawing/tc_chart.rb
@@ -0,0 +1,59 @@
+require 'test/unit'
+require 'axlsx.rb'
+
+class TestChart < Test::Unit::TestCase
+
+ def setup
+ @p = Axlsx::Package.new
+ ws = @p.workbook.add_worksheet
+ @row = ws.add_row ["one", 1, Time.now]
+ @chart = ws.add_chart Axlsx::Bar3DChart, :title => "fishery"
+ end
+
+ def teardown
+ end
+
+ def test_initialization
+ assert_equal(@p.workbook.charts.last,@chart, "the chart is in the workbook")
+ assert_equal(@chart.title.text, "fishery", "the title option has been applied")
+ assert((@chart.series.is_a?(Axlsx::SimpleTypedList) && @chart.series.empty?), "The series is initialized and empty")
+ end
+
+ def test_title
+ @chart.title.text = 'wowzer'
+ assert_equal(@chart.title.text, "wowzer", "the title text via a string")
+ assert_equal(@chart.title.cell, nil, "the title cell is nil as we set the title with text.")
+ @chart.title.cell = @row.cells.first
+ assert_equal(@chart.title.text, "one", "the title text was set via cell reference")
+ assert_equal(@chart.title.cell, @row.cells.first)
+ end
+
+
+ def test_add_series
+ s = @chart.add_series :data=>[0,1,2,3], :labels => ["one", 1, "anything"], :title=>"bob"
+ assert_equal(@chart.series.last, s, "series has been added to chart series collection")
+ assert_equal(s.title, "bob", "series title has been applied")
+ assert_equal(s.data, [0,1,2,3], "data option applied")
+ assert_equal(s.labels, ["one",1,"anything"], "labels option applied")
+ end
+
+ def test_create_range
+
+ end
+
+ def test_pn
+ assert_equal(@chart.pn, "charts/chart1.xml")
+ end
+
+ def test_to_xml
+ schema = Nokogiri::XML::Schema(File.open(Axlsx::DRAWING_XSD))
+ doc = Nokogiri::XML(@chart.to_xml)
+ errors = []
+ schema.validate(doc).each do |error|
+ errors.push error
+ puts error.message
+ end
+ assert(errors.empty?, "error free validation")
+ end
+
+end