Sha256: 6e661bb3f644708f855484f6b864d04eb5d1a6862f4cb40336b362fe02d1221f
Contents?: true
Size: 1.79 KB
Versions: 2
Compression:
Stored size: 1.79 KB
Contents
require 'spec_helper' describe Chartnado::Renderer do describe "#chart_json" do def chart_json(*series, **options) Chartnado::Renderer.new(nil, nil).chart_json(*series, **options) end describe "for data formatted as a hash" do it "can generate chartkick compatible series" do expect(chart_json({[:a, 1] => 10, [:b, 1] => 20})). to eq [{name: :a, data: [[1, 10]]}, {name: :b, data: [[1,20]]}] end it "can add totals" do expect(chart_json({[:a, 1] => 10, [:b, 1] => 20}, show_total: true)). to eq [{name: 'Total', data: [[1, 0]], tooltip: [[1, 30.0]]}, {name: :a, data: [[1, 10]]}, {name: :b, data: [[1, 20]]}] end describe "with multiple scalar series" do it "can handle scalars" do expect(chart_json({:a => 10, :b => 20})). to eq([[:a, 10], [:b, 20]]) end it "can add totals" do expect(chart_json({:a => 10, :b => 20}, show_total: true)). to eq([[:a, 10], [:b, 20], ['Total', 30]]) end end end describe "for data formatted as an array" do it "can generate chartkick compatible series" do expect(chart_json([[:a, {1 => 10}], [:b, {1 => 20}]])). to eq [{name: :a, data: [[1, 10]]}, {name: :b, data: [[1,20]]}] end it "can add totals" do expect(chart_json([[:a, {1 => 10}], [:b, {1 => 20}]], show_total: true)). to eq [{name: 'Total', data: [[1, 0]], tooltip: [[1, 30.0]]}, {name: :a, data: [[1, 10]]}, {name: :b, data: [[1, 20]]}] end end describe "for data that is just a scalar" do it "shows the scalar as the total" do expect(chart_json(10)). to eq [['Total', 10]] end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
chartnado-0.0.2 | spec/renderer_spec.rb |
chartnado-0.0.1 | spec/renderer_spec.rb |