Skip to content

Commit

Permalink
Fixed Schedules accordion swapping logic.
Browse files Browse the repository at this point in the history
Only need to set params[:accord] when add button is pressed from Reports accordion, setting of acord parameter causes acoridon to be swapped to Schedule accordion by Explorer presenter code. Undid code changes made in ManageIQ#3399 this was causing issues when adding a schedule from Reports accordion.
Also need to hide form buttons post accordion switch when schedule is added from Reports accordion.

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1624248
  • Loading branch information
h-kataria committed Sep 6, 2018
1 parent f862e53 commit 62aec06
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
3 changes: 1 addition & 2 deletions app/assets/javascripts/miq_explorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,7 @@ ManageIQ.explorer.processReplaceRightCell = function(data) {
ManageIQ.explorer.miqButtons(data);

if (_.isString(data.clearTreeCookies)) { miqDeleteTreeCookies(data.clearTreeCookies); }

if (_.isString(data.accordionSwap) && ! data.activateNode.activeTree.includes(data.accordionSwap)) {
if (_.isString(data.accordionSwap)) {
miqAccordionSwap('#accordion .panel-collapse.collapse.in', '#' + data.accordionSwap + '_accord');
}

Expand Down
1 change: 1 addition & 0 deletions app/controllers/report_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,7 @@ def replace_right_cell(options = {}) # :replace_trees key can be an array of tre
end
presenter.show(:paging_div)
else
presenter.hide(:form_buttons_div)
presenter.hide(:paging_div)
end
if (@sb[:active_tab] == 'report_info' && x_node.split('-').length == 5 && !@in_a_form) || %w(xx-exportwidgets xx-exportcustomreports).include?(x_node)
Expand Down
3 changes: 1 addition & 2 deletions app/controllers/report_controller/schedules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,10 @@ def schedule_edit
# ensure we land in the right accordion with the right tree and
# with the listing opened even when entering 'add' from the reports
# menu

@_params[:accord] = "schedules" unless x_active_accord == :schedules
self.x_active_tree = "schedules_tree"
self.x_active_accord = "schedules"
self.x_node = "msc-#{schedule.id}"
@_params[:accord] = "schedules"
replace_right_cell(:replace_trees => [:schedules])
else
schedule.errors.each do |field, msg|
Expand Down
31 changes: 31 additions & 0 deletions spec/controllers/report_controller/schedules_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
let(:admin_user) { FactoryGirl.create(:user, :role => "super_administrator") }

let(:schedule) { FactoryGirl.create(:miq_schedule, :name => "tester1") }
let(:report) { FactoryGirl.create(:miq_report, :name => "report1") }

before do
EvmSpecHelper.create_guid_miq_server_zone
Expand All @@ -14,6 +15,15 @@
allow(controller).to receive(:assert_privileges)
allow(controller).to receive(:checked_or_params).and_return(MiqSchedule.all.ids)
allow(controller).to receive(:replace_right_cell).and_return(true)

timer = ReportHelper::Timer.new('hourly', 1, 1, 1, 1, Time.now.utc, '00', '00')
edit = {:key => "schedule_edit__#{schedule.id}",
:sched_id => schedule.id,
:new => {:name => "foo", :description => "Foo", :repfilter => report.id, :timer => timer}}
controller.instance_variable_set(:@edit, edit)
controller.instance_variable_set(:@sb, {})
session[:edit] = edit
allow(controller).to receive(:drop_breadcrumb)
end

it "reset rbac testing" do
Expand All @@ -22,5 +32,26 @@
expected_id = controller.instance_variable_get(:@schedule).id
expect(expected_id).to eq(schedule.id)
end

it "sets params accord only when schedule is added from Reports accordion" do
allow(controller).to receive(:x_active_accord).and_return(:reports)
post :schedule_edit, :params => { :button => "add", :id => schedule.id }
params = ActionController::Parameters.new('button' => 'add',
'id' => schedule.id.to_s,
'controller' => 'report',
'action' => 'schedule_edit',
'accord' => 'schedules')
expect(controller.params).to eq(params)
end

it "does not set params accord when adding/editing schedule from Schedules accordion" do
allow(controller).to receive(:x_active_accord).and_return(:schedules)
post :schedule_edit, :params => { :button => "add", :id => schedule.id }
params = ActionController::Parameters.new('button' => 'add',
'id' => schedule.id.to_s,
'controller' => 'report',
'action' => 'schedule_edit')
expect(controller.params).to eq(params)
end
end
end

0 comments on commit 62aec06

Please sign in to comment.