Skip to content

Commit

Permalink
Corrects Apply button states on Import/Import Tags forms
Browse files Browse the repository at this point in the history
Apply button now remains disabled until valid files are uploaded in the form.

https://bugzilla.redhat.com/show_bug.cgi?id=1224428
  • Loading branch information
bmclaughlin committed Jun 17, 2016
1 parent 0a40f33 commit 5510547
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
6 changes: 3 additions & 3 deletions app/controllers/ops_controller.rb
Expand Up @@ -126,15 +126,15 @@ def explorer
@sb[:user] = nil
@ldap_group = nil
else
session[:changed] = @sb[:show_button] if params[:no_refresh] &&
%w(settings_import settings_import_tags).include?(@sb[:active_tab]) # show apply button enabled if this is set
enable_apply_button = !flash_errors? if %w(settings_import settings_import_tags).include?(@sb[:active_tab])
end
# setting active record object here again, since they are no longer there due to redirect
@ldap_group = @edit[:ldap_group] if params[:cls_id] && params[:cls_id].split('_')[0] == "lg"
@x_edit_buttons_locals = set_form_locals if @in_a_form
@collapse_c_cell = @in_a_form || @pages ? false : true
@sb[:center_tb_filename] = center_toolbar_filename
edit_changed? if @edit
enable_apply_button ||= false
edit_changed? if @edit && enable_apply_button
render :layout => "application"
end

Expand Down
35 changes: 35 additions & 0 deletions spec/controllers/ops_controller_spec.rb
Expand Up @@ -305,4 +305,39 @@
expect(response.body).to include("if (miqDomElementExists('toolbar')) $('#toolbar').show();")
end
end

context "Import Tags and Import forms" do
%w(settings_import settings_import_tags).each do |tab|
render_views

before do
_guid, @miq_server, @zone = EvmSpecHelper.remote_guid_miq_server_zone
allow(controller).to receive(:check_privileges).and_return(true)
allow(controller).to receive(:assert_privileges).and_return(true)
controller.instance_variable_set(:@sb, {})
allow(controller).to receive(:x_active_tree).and_return(:settings_tree)
allow(controller).to receive(:x_node).and_return("root")
controller.x_active_tree = 'settings_tree'
expect(controller).to receive(:render_to_string).with(any_args).twice
post :change_tab, :params => { :tab_id => tab }
end

it "Apply button remains disabled with flash errors" do
post :explorer, :params => { :flash_error => 'true', :flash_msg => 'Error during upload', :no_refresh => 'true' }
expect(response.status).to eq(200)
expect(response.body).to_not be_empty
expect(response.body).to include("<div id='buttons_on' style='display: none;'>")
expect(response.body).to include("<div id='buttons_off' style=''>\n<button name=\"button\" type=\"submit\" class=\"btn btn-primary btn-disabled\">Apply</button>")
end

it "Apply button enabled when there are no flash errors" do
controller.instance_variable_set(:@flash_array, [])
post :explorer, :params => {:no_refresh => 'true' }
expect(response.status).to eq(200)
expect(response.body).to_not be_empty
expect(response.body).to include("<div id='buttons_on' style=''>")
expect(response.body).to include("<div id='buttons_off' style='display: none;'>\n<button name=\"button\" type=\"submit\" class=\"btn btn-primary btn-disabled\">Apply</button>")
end
end
end
end

0 comments on commit 5510547

Please sign in to comment.