Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix toolbar on Reports tab on Overview -> Utilization screen #6624

Merged
merged 4 commits into from
Jan 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion app/controllers/utilization_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ def replace_right_cell(_nodetype)
presenter[:clear_selection] = x_node == ''

presenter.reload_toolbars(:view => v_tb)
presenter.set_visibility(@sb[:active_tab] == 'report', :toolbar)

presenter.update(:main_div, r[:partial => 'utilization_tabs'])
presenter.update(:breadcrumbs, r[:partial => 'layouts/breadcrumbs'])
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/application_helper/button/miq_capacity.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class ApplicationHelper::Button::MiqCapacity < ApplicationHelper::Button::Basic
def visible?
@view_context.sandbox[:active_tab] == 'report'
@view_context.sandbox[:active_tab] == 'report' && @sb[:summary].present?
end
end
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
class ApplicationHelper::Button::UtilizationDownload < ApplicationHelper::Button::Basic
def visible?
@sb[:active_tab] == 'report'
end

def disabled?
# to enable the button 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?
return false if @layout == 'miq_capacity_utilization' && @sb[:active_tab] == 'report' && @sb.fetch_path(:trend_rpt).present? && @sb[:summary].present?

# otherwise the button is off
@error_message = _('No records found for this report')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ApplicationHelper::Toolbar::MiqCapacityView < ApplicationHelper::Toolbar::
'pficon pficon-print fa-lg',
N_('Print or export this report in PDF format'),
N_('Print or export as PDF'),
:klass => ApplicationHelper::Button::Basic,
:klass => ApplicationHelper::Button::MiqCapacity,
:popup => true,
:url => "/report_download",
:url_parms => "?typ=pdf"),
Expand Down
16 changes: 13 additions & 3 deletions spec/helpers/application_helper/buttons/miq_capacity_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,23 @@

describe '#visible?' do
subject { button.visible? }
context 'when active_tab == report' do
context 'when active_tab == report and @sb[:summary] is present' do
let(:tab) { 'report' }
it { is_expected.to be_truthy }
it do
button.instance_variable_set(:@sb, :active_tab => "report", :summary => "data")
is_expected.to be(true)
end
end
context 'when active_tab == report and @sb[:summary] is empty' do
let(:tab) { 'report' }
it do
button.instance_variable_set(:@sb, :active_tab => "report", :summary => nil)
is_expected.to be(false)
end
end
context 'when active_tab != report' do
let(:tab) { 'not_report' }
it { is_expected.to be_falsey }
it { is_expected.to be(false) }
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,24 @@
context '#disabled?' do
it 'when report tab has no data available' do
report.table = OpenStruct.new(:data => [])
expect(button.disabled?).to be_truthy
expect(button.disabled?).to be(true)
end

it 'when report tab has data' do
it 'when report tab has data and @sb[:summary] is not set' do
report.table = OpenStruct.new(:data => [:foo => 'bar'])
expect(button.disabled?).to be_falsey
expect(button.disabled?).to be(true)
end

it 'when report tab has data and @sb[:summary] is set' do
button.instance_variable_set(:@sb, :active_tab => "report", :trend_rpt => report, :summary => "is set")
report.table = OpenStruct.new(:data => [:foo => 'bar'])
expect(button.disabled?).to be(false)
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
expect(button.disabled?).to be(true)
end
end
end
Expand Down