Skip to content

Commit

Permalink
Add spec for Bionya
Browse files Browse the repository at this point in the history
  • Loading branch information
domitry committed Aug 18, 2014
1 parent c9d517f commit 4ae07cf
Showing 1 changed file with 77 additions and 0 deletions.
77 changes: 77 additions & 0 deletions spec/bionya_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
require 'spec_helper'
require 'bionya'

describe "Bionya" do

context "core" do
it "should register the namespace of JS back-end" do
expect(Nyaplot.extension_lists.index("Bionya").nil?).to eq(false)
end
end
end

describe Nyaplot::CircularPlot do
before(:each) do
df = Nyaplot::DataFrame.new([{name:'hoge', df: [{axis: 0, val: 3, label:'a'},{axis: 1, val: 3, label:'a'}]}, {name:'huga', df: [{axis: 2, val: 3, label:'a'},{axis: 3, val: 3, label:'a'}]}])
df.each_row{|row| row[:df] = Nyaplot::DataFrame.new(row[:df])}
@df = df
@plot = Nyaplot::CircularPlot.new(df, :name, :df)
end

context ".add_connector_with_df" do
it "should register diagram" do
df = Nyaplot::DataFrame.new({from: ['hoge.1', 'huga.2'], to: ['hoge.1', 'huga.1']})
@plot.add_connector_with_df(df, :from, :to)
expect(JSON.parse(@plot.to_json)["diagrams"].any?{|d| d["type"] == "connector"}).to eq(true)
end
end

context ".add" do
it "should increment inner_num and outer_num" do
@plot.add(1, :arc, :axis, :val)
@plot.add(-1, :arc, :axis, :val)
@plot.to_json
expect(@plot.inner_num).to eq(1)
expect(@plot.outer_num).to eq(2)
end
end
end

describe Nyaplot::Diagrams do
before(:each) do
df = Nyaplot::DataFrame.new([{name:'hoge', df: [{axis: 0, val: 3, label:'a'},{axis: 1, val: 3, label:'a'}]}, {name:'huga', df: [{axis: 2, val: 3, label:'a'},{axis: 3, val: 3, label:'a'}]}])
df.each_row{|row| row[:df] = Nyaplot::DataFrame.new(row[:df])}
@df = df
@plot = Nyaplot::CircularPlot.new(df, :name, :df)
end

context "::Arc#process_data"do
it "should calcurate range of values" do
arc = @plot.add(1, :arc, :axis, :val)
expect(arc.range).to eq([0, 3])
end

it "should register 'x' and 'y'" do
arc = @plot.add(1, :arc, :axis, :val)
expect(arc.x).to eq(:axis)
expect(arc.y).to eq(:val)
end
end

context "::Labels#process_data"do
it "should register 'x' and 'text'" do
labels = @plot.add(1, :labels, :axis, :label)
expect(labels.x).to eq(:axis)
expect(labels.text).to eq(:label)
end
end

context "::Connector#process_data"do
it "should register 'from' and 'to'" do
df = Nyaplot::DataFrame.new({from: ['hoge.1', 'huga.2'], to: ['hoge.1', 'huga.1']})
connector = @plot.add_connector_with_df(df, :from, :to)
expect(connector.from).to eq(:from)
expect(connector.to).to eq(:to)
end
end
end

0 comments on commit 4ae07cf

Please sign in to comment.