From a98e6945da43db6ee47f5e931edd6307b31e4ff1 Mon Sep 17 00:00:00 2001 From: Harpreet Kataria Date: Fri, 16 Nov 2018 11:18:03 -0500 Subject: [PATCH] Fixed to enable the download buttons on Utilization Report tab Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1649945 --- .../button/utilization_download.rb | 4 +- .../buttons/utilization_download_spec.rb | 61 ++++++++++++++----- 2 files changed, 47 insertions(+), 18 deletions(-) diff --git a/app/helpers/application_helper/button/utilization_download.rb b/app/helpers/application_helper/button/utilization_download.rb index 71f8ad29c9d..352ddfd458a 100644 --- a/app/helpers/application_helper/button/utilization_download.rb +++ b/app/helpers/application_helper/button/utilization_download.rb @@ -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? diff --git a/spec/helpers/application_helper/buttons/utilization_download_spec.rb b/spec/helpers/application_helper/buttons/utilization_download_spec.rb index d2e3709c677..d1e7321e3b9 100644 --- a/spec/helpers/application_helper/buttons/utilization_download_spec.rb +++ b/spec/helpers/application_helper/buttons/utilization_download_spec.rb @@ -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