Skip to content

Commit 2e662f8

Browse files
committed
Added tests
1 parent e456894 commit 2e662f8

File tree

3 files changed

+61
-2
lines changed

3 files changed

+61
-2
lines changed

lib/daru/view/adapters/googlecharts/display.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def extract_chart_id_script_path(id=nil)
124124
# @param id [String] The ID of the DIV element that the Google Chart
125125
# should be rendered in
126126
# @return [String] Javascript of the table or chart
127-
def set_chart_script(plot, id)
127+
def set_chart_script(plot, id=nil)
128128
if plot.is_a?(Daru::View::Plot)
129129
plot.chart.show_script(id, script_tag: false)
130130
else

spec/adapters/googlecharts/display_spec.rb

+51
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,57 @@
8383
expect(js).to match(
8484
/data_table.addRow\(\[\{v: \"2013\"\}\]\);/i)
8585
end
86+
it "generates valid js of the combined charts" do
87+
js = combined.chart.to_html
88+
expect(js).to match(/google.visualization.Table/)
89+
expect(js).to match(/google.visualization.AreaChart/)
90+
expect(js).to match(/google.visualization.ColumnChart/)
91+
end
92+
end
93+
94+
describe "#extract_multiple_charts_id_script_path" do
95+
it "returns correct path of the multiple_charts_div" do
96+
id_script_path = combined.chart.extract_multiple_charts_id_script_path
97+
expect(id_script_path[2]).to match(
98+
/templates\/googlecharts\/multiple_charts_div.erb/
99+
)
100+
end
101+
it "returns correct scripts of the multiple charts" do
102+
id_script_path = combined.chart.extract_multiple_charts_id_script_path
103+
expect(id_script_path[1][0]).to match(/google.visualization.Table/)
104+
expect(id_script_path[1][1]).to match(/google.visualization.AreaChart/)
105+
expect(id_script_path[1][2]).to match(/google.visualization.ColumnChart/)
106+
end
107+
end
108+
109+
describe "#extract_chart_id_script_path" do
110+
it "returns correct path of the chart_div" do
111+
id_script_path = area_chart_chart.chart.extract_chart_id_script_path
112+
expect(id_script_path[2]).to match(
113+
/templates\/googlecharts\/chart_div.erb/
114+
)
115+
end
116+
it "returns correct script of the chart" do
117+
id_script_path = area_chart_chart.chart.extract_chart_id_script_path
118+
expect(id_script_path[1]).to match(
119+
/google.visualization.AreaChart/
120+
)
121+
end
122+
it "returns correct id of the chart" do
123+
id_script_path = area_chart_chart.chart.extract_chart_id_script_path('id')
124+
expect(id_script_path[0]).to eq('id')
125+
end
126+
end
127+
128+
describe "#set_chart_script" do
129+
it "sets correct script of the data_table" do
130+
js = data_table.table.set_chart_script(data_table, 'id')
131+
expect(js).to match(/google.visualization.Table/)
132+
end
133+
it "sets correct script of the chart" do
134+
js = area_chart_chart.chart.set_chart_script(area_chart_chart, 'id')
135+
expect(js).to match(/google.visualization.AreaChart/)
136+
end
86137
end
87138

88139
describe "#show_script" do

spec/adapters/googlecharts_spec.rb

+9-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@
6767
new(data_table.table, area_chart_options)}
6868
let(:column_chart_chart) {Daru::View::Plot.
6969
new(data_table.table, column_chart_options)}
70-
70+
let(:combined) {
71+
Daru::View::Plot.new([data_table, area_chart_chart, column_chart_chart])
72+
}
7173

7274
describe "initialization Charts" do
7375
it "Default chart GoogleVisualr::Interactive::LineChart " do
@@ -208,6 +210,12 @@
208210
expect(js).to match(/google.visualization.ColumnChart/)
209211
expect(js).to match(/chart.draw\(data_table, \{width: 800\}/i)
210212
end
213+
it "generates valid js of the combined charts" do
214+
js = combined.adapter.generate_body(combined.chart)
215+
expect(js).to match(/google.visualization.Table/)
216+
expect(js).to match(/google.visualization.AreaChart/)
217+
expect(js).to match(/google.visualization.ColumnChart/)
218+
end
211219
end
212220

213221
describe "#generate_html" do

0 commit comments

Comments
 (0)