Skip to content

Commit

Permalink
Fixed to enable the download buttons on Utilization Report tab
Browse files Browse the repository at this point in the history
  • Loading branch information
h-kataria committed Nov 16, 2018
1 parent ab78538 commit a98e694
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 18 deletions.
4 changes: 2 additions & 2 deletions app/helpers/application_helper/button/utilization_download.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ def disabled?
return false if @view_context.x_active_tree.nil? &&
@sb.fetch_path(:planning, :rpt) && !@sb[:rpt].table.data.empty?

# b) we are in the "Utilization" and have trend report and summary
return false if @sb.fetch_path(:util, :trend_rpt) && @sb.fetch_path(:util, :summary)
# b) we are in the "Utilization" and have trend report
return false if @layout == 'miq_capacity_utilization' && @sb[:active_tab] == 'report' && !@sb.fetch_path(:trend_rpt).table.data.empty?

# c) we are in the "Bottlenecks" on 'Report' tab and have report data available
return false if @layout == 'miq_capacity_bottlenecks' && @sb[:active_tab] == 'report' && !@sb[:report].table.data.empty?
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,57 @@
describe ApplicationHelper::Button::UtilizationDownload do
let(:view_context) { setup_view_context_with_sandbox({}) }
let(:report) { FactoryGirl.create(:miq_report, :miq_report_results => []) }
let(:button) { described_class.new(view_context, {}, {'layout' => 'miq_capacity_bottlenecks'}, {}) }
let!(:button) { described_class.new(view_context, {}, {'layout' => 'miq_capacity_bottlenecks'}, {}) }

before do
button.instance_variable_set(:@sb, :active_tab => "report", :report => report)
allow(view_context).to receive(:x_active_tree).and_return(:bottlenecks_tree)
end
context "Bottlenecks explorer" do
before do
button.instance_variable_set(:@sb, :active_tab => "report", :report => report)
allow(view_context).to receive(:x_active_tree).and_return(:bottlenecks_tree)
end

context '#disabled?' do
it 'when report tab has no data available' do
report.table = OpenStruct.new(:data => [])
expect(button.disabled?).to be_truthy
end

it 'when report tab has data' do
report.table = OpenStruct.new(:data => [:foo => 'bar'])
expect(button.disabled?).to be_falsey
end

context '#disabled?' do
it 'when report tab has no data available' do
report.table = OpenStruct.new(:data => [])
expect(button.disabled?).to be_truthy
it 'when on summary tab' do
button.instance_variable_set(:@sb, :active_tab => "summary", :report => report)
report.table = OpenStruct.new(:data => [:foo => 'bar'])
expect(button.disabled?).to be_truthy
end
end
end

context "Utilization explorer" do
let(:button) { described_class.new(view_context, {}, {'layout' => 'miq_capacity_utilization'}, {}) }

it 'when report tab has data' do
report.table = OpenStruct.new(:data => [:foo => 'bar'])
expect(button.disabled?).to be_falsey
before do
button.instance_variable_set(:@sb, :active_tab => "report", :trend_rpt => report)
allow(view_context).to receive(:x_active_tree).and_return(:utilization_tree)
end

it 'when on summary tab' do
button.instance_variable_set(:@sb, :active_tab => "summary", :report => report)
report.table = OpenStruct.new(:data => [:foo => 'bar'])
expect(button.disabled?).to be_truthy
context '#disabled?' do
it 'when report tab has no data available' do
report.table = OpenStruct.new(:data => [])
expect(button.disabled?).to be_truthy
end

it 'when report tab has data' do
report.table = OpenStruct.new(:data => [:foo => 'bar'])
expect(button.disabled?).to be_falsey
end

it 'when on summary tab' do
button.instance_variable_set(:@sb, :active_tab => "summary", :trend_rpt => report)
report.table = OpenStruct.new(:data => [:foo => 'bar'])
expect(button.disabled?).to be_truthy
end
end
end
end

0 comments on commit a98e694

Please sign in to comment.