forked from CoralineAda/seer
/
area_chart_spec.rb
108 lines (93 loc) · 3.68 KB
/
area_chart_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
describe "Seer::AreaChart" do
before :each do
@chart = Seer::AreaChart.new(
:data => [0,1,2,3],
:series_label => 'to_s',
:data_series => [[1,2,3],[3,4,5]],
:data_label => 'to_s',
:data_method => 'size',
:chart_options => {},
:chart_element => 'chart'
)
end
describe 'defaults' do
it_should_behave_like 'it sets default values'
end
describe 'graph options' do
[:axis_color, :axis_background_color, :axis_font_size, :background_color, :border_color, :enable_tooltip, :focus_border_color, :height, :is_stacked, :legend, :legend_background_color, :legend_font_size, :legend_text_color, :line_size, :log_scale, :max, :min, :point_size, :reverse_axis, :show_categories, :title, :title_x, :title_y, :title_color, :title_font_size, :tooltip_font_size, :tooltip_height, :number, :tooltip_width, :width].each do |accessor|
it "sets its #{accessor} value" do
@chart.send("#{accessor}=", 'foo')
@chart.send(accessor).should == 'foo'
end
end
it_should_behave_like 'it has colors attribute'
end
it 'renders as JavaScript' do
(@chart.to_js =~ /javascript/).should be_true
(@chart.to_js =~ /areachart/).should be_true
end
it 'sets its data columns' do
@chart.data_columns.should =~ /addRows\(5\)/
@chart.data_columns.should add_column('string', 'Date')
@chart.data_columns.should add_column('number', '0')
@chart.data_columns.should add_column('number', '1')
@chart.data_columns.should add_column('number', '2')
@chart.data_columns.should add_column('number', '3')
end
it 'sets its data table' do
@chart.data_table.to_s.should set_cell(0, 0,'1')
@chart.data_table.to_s.should set_cell(1, 0,'2')
@chart.data_table.to_s.should set_cell(2, 0,'3')
@chart.data_table.to_s.should set_cell(3, 0,'4')
@chart.data_table.to_s.should set_cell(4, 0,'5')
@chart.data_table.to_s.should set_cell(0,1,8)
@chart.data_table.to_s.should set_cell(2,1,8)
@chart.data_table.to_s.should set_cell(0,2,8)
@chart.data_table.to_s.should set_cell(1,2,8)
@chart.data_table.to_s.should set_cell(2,2,8)
end
describe 'when data_series is an array of arrays of arrays/hashes' do
before(:each) do
data_series = Array.new(3) {|i| [[i, i+1], [i+1, i+2]]}
@chart = Seer::AreaChart.new(
:data => [0,1,2,3],
:series_label => 'to_s',
:data_series => data_series,
:data_label => 'first',
:data_method => 'size',
:chart_options => {},
:chart_element => 'chart'
)
end
it 'calculates number of rows' do
@chart.data_columns.should =~ /addRows\(4\)/
end
it 'sets its data table' do
@chart.data_table.to_s.should set_cell(0, 0,'0')
@chart.data_table.to_s.should set_cell(1, 0,'1')
@chart.data_table.to_s.should set_cell(2, 0,'2')
@chart.data_table.to_s.should set_cell(3, 0,'3')
end
end
describe 'should receive options' do
before(:each) do
data_series = Array.new(3) {|i| [[i, i+1], [i+1, i+2]]}
@options = {
:data => [0,1,2,3],
:series_label => 'to_s',
:data_series => data_series,
:data_label => 'first',
:data_method => 'size',
:chart_options => {},
:chart_element => 'chart'
}
end
it 'should receive :is_stacked option' do
create_chart_with_option(:is_stacked => true).to_js.should =~ /options\['isStacked'\] = true/
end
end
end
def create_chart_with_option(option)
Seer::AreaChart.new(@options.merge(option))
end