Skip to content

Commit

Permalink
Add specs
Browse files Browse the repository at this point in the history
  • Loading branch information
PanSpagetka committed Feb 21, 2017
1 parent 69dfff4 commit 8219974
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/controllers/application_controller/performance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ def prepare_perf_tag_chart(chart, rpt, cat_desc)
# Grab the first (and should be only) chart column
col = chart[:columns].first
# Create the new chart columns for each tag
chart[:columns] ||= rpt.extras[:group_by_tags].collect { |t| col + "_" + t }
chart[:columns] = rpt.extras[:group_by_tags].collect { |t| col + "_" + t }
end

def gen_perf_chart(chart, rpt, idx, zoom_action)
Expand Down
1 change: 0 additions & 1 deletion lib/report_formatter/c3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ def build_document_header
mri.chart[:legend] = {:position => 'bottom'}
end

binding.pry
column = is_grouped_by_tag_category? ? mri.graph[:columns][0].split(/_+/)[0..-2].join('_') : mri.graph[:columns][0]
format, options = javascript_format(column, nil)
return unless format
Expand Down
1 change: 0 additions & 1 deletion lib/report_formatter/chart_common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,6 @@ def extract_column_names
# 'Vm-num_cpu:total' gives 'num_cpu' and 'num_cpu__total'
# "Vm::Providers::InfraManager::Vm-num_cpu:total"
# gives 'Vm::Providers::InfraManager::Vm' and 'num_cpu__total'

stage1, aggreg = mri.graph[:column].split(/(?<!:):(?!:)/) # split by ':', NOT by '::'
model1, column = stage1.split('-', 2)
_model, sub_model = model1.split('.', 2)
Expand Down
54 changes: 54 additions & 0 deletions spec/lib/report_formater/c3_formatter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,58 @@
render_report(report)
end
end

context '#C&U charts without grouping' do
let(:report) { cu_chart_without_grouping }
before(:each) do
render_report(report, &Proc.new{ |e| e.options.graph_options = { :chart_type => :performance }})
end

it "has right data" do
expect(report.chart[:data][:columns][0].count).to eq(report.table.data.count + 1)
expect(report.chart[:data][:columns][0]).to eq(["x", "8/19", "8/20"])
expect(report.chart[:data][:columns][1]).to eq(["1", 19986.0, 205632.0])
expect(report.chart[:data][:columns][2]).to eq(["2", 41584.0, 41584.0])
end

it "has right type" do
expect(report.chart[:axis][:x][:type]).to eq("timeseries")
end

it 'has right formatting functions' do
expect(report.chart[:axis][:y][:tick][:format][:function]).to eq("mhz_to_human_size")
expect(report.chart[:miq][:format][:function]).to eq("mhz_to_human_size")
end
it 'has right tabels' do
expect(report.chart[:miq][:name_table]).to eq({"1"=>"Avg Used", "2"=>"Max Available"})
expect(report.chart[:miq][:category_table]).to eq(["8/19", "8/20"])
end
end

context '#C&U charts with grouping' do
let(:report) { cu_chart_with_grouping }
before(:each) do
render_report(report, &Proc.new{ |e| e.options.graph_options = { :chart_type => :performance }})
end

it "has right data" do
expect(report.chart[:data][:columns][0].count).to eq(report.table.data.count + 1)
expect(report.chart[:data][:columns][0]).to eq(["x", "8/19", "8/20"])
expect(report.chart[:data][:columns][1]).to eq(["1", 19986.0, 205632.0])
expect(report.chart[:data][:columns][2]).to eq(["2", 41584.0, 41584.0])
end

it "has right type" do
expect(report.chart[:axis][:x][:type]).to eq("timeseries")
end

it 'has right formatting functions' do
expect(report.chart[:axis][:y][:tick][:format][:function]).to eq("mhz_to_human_size")
expect(report.chart[:miq][:format][:function]).to eq("mhz_to_human_size")
end
it 'has right tabels' do
expect(report.chart[:miq][:name_table]).to eq({"1"=>"Avg Used", "2"=>"Max Available"})
expect(report.chart[:miq][:category_table]).to eq(["8/19", "8/20"])
end
end
end

0 comments on commit 8219974

Please sign in to comment.