Skip to content

Commit

Permalink
Disable Order button and add flash message to Catalog Item's details
Browse files Browse the repository at this point in the history
  • Loading branch information
Hilda Stastna committed Jan 29, 2020
1 parent 3e953fc commit 150ef99
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 15 deletions.
2 changes: 2 additions & 0 deletions app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,8 @@ def identify_catalog(id = nil)
kls = TreeBuilder.get_model_for_prefix(@nodetype) == "MiqTemplate" ? VmOrTemplate : ServiceTemplate
@record = identify_record(id || params[:id], kls)
@tenants_tree = build_tenants_tree if kls == ServiceTemplate # Build the tree with available tenants for the Catalog Item/Bundle
@template_valid = @record.try(:template_valid?)
add_flash(_("This item is invalid"), :warning) unless @flash_array || @template_valid
end

# ST clicked on in the explorer right cell
Expand Down
9 changes: 5 additions & 4 deletions app/views/catalog/_svccat_tree_show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@
.col-md-1{:align => "center"}
#buttons
= button_tag(_("Order"),
:class => "btn btn-primary",
:alt => t = _("Order this Service"),
:title => t,
:onclick => "miqOrderService(#{@record.id})")
:class => "btn btn-primary",
:alt => t = @template_valid ? _("Order this Service") : _("This Service cannot be ordered"),
:title => t,
:disabled => !@template_valid,
:onclick => "miqOrderService(#{@record.id})")

:javascript
miq_bootstrap('#long_description');
40 changes: 29 additions & 11 deletions spec/controllers/catalog_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@
end

describe '#x_button' do
before do
ApplicationController.handle_exceptions = true
end
before { ApplicationController.handle_exceptions = true }

context 'corresponding methods are called for allowed actions' do
CatalogController::CATALOG_X_BUTTON_ALLOWED_ACTIONS.each_pair do |action_name, actual_method|
Expand Down Expand Up @@ -476,6 +474,7 @@

describe "#ot_rendering" do
render_views

before do
EvmSpecHelper.create_guid_miq_server_zone
session[:settings] = {
Expand Down Expand Up @@ -964,6 +963,7 @@

describe '#replace_right_cell' do
let(:dialog) { FactoryBot.create(:dialog) }

before do
allow(controller).to receive(:params).and_return(:action => 'dialog_provision')
controller.instance_variable_set(:@in_a_form, true)
Expand All @@ -984,14 +984,8 @@
end

describe '#service_template_list' do
let(:sandbox) { {:active_tree => tree} }

before do
controller.instance_variable_set(:@sb, sandbox)
end

context 'Service Catalogs accordion' do
let(:tree) { :svccat_tree }
before { controller.instance_variable_set(:@sb, :active_tree => :svccat_tree) }

it 'sets options for rendering proper type of view' do
expect(controller).to receive(:process_show_list).with(:gtl_dbname => :catalog, :named_scope => {})
Expand All @@ -1001,7 +995,7 @@
end

describe '#available_job_templates' do
it "" do
it "sets new available templates" do
ems = FactoryBot.create(:automation_manager_ansible_tower)
cs = FactoryBot.create(:configuration_script,
:type => 'ManageIQ::Providers::AnsibleTower::AutomationManager::ConfigurationScript')
Expand Down Expand Up @@ -1260,6 +1254,30 @@
controller.send(:identify_catalog, record.id)
expect(controller.instance_variable_get(:@tenants_tree).name).to eq(:tenants_tree)
end

it 'does not add warning flash message for valid Catalog Item or Bundle' do
controller.send(:identify_catalog, record.id)
expect(controller.instance_variable_get(:@flash_array)).to be_nil
end

it 'sets @template_valid to true' do
controller.send(:identify_catalog, record.id)
expect(controller.instance_variable_get(:@template_valid)).to be(true)
end

context 'invalid Catalog Item or Bundle' do
let(:record) { FactoryBot.create(:service_template, :service_resources => [FactoryBot.create(:service_resource)]) }

it 'adds warning flash message' do
controller.send(:identify_catalog, record.id)
expect(controller.instance_variable_get(:@flash_array)).to eq([{:message => 'This item is invalid', :level => :warning}])
end

it 'sets @template_valid to false' do
controller.send(:identify_catalog, record.id)
expect(controller.instance_variable_get(:@template_valid)).to be(false)
end
end
end

describe '#common_st_record_vars' do
Expand Down
23 changes: 23 additions & 0 deletions spec/views/catalog/_svccat_tree_show.html.haml_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
describe "catalog/_svccat_tree_show.html.haml" do
let(:service) { FactoryBot.create(:service_template) }

before do
assign(:record, service)
assign(:sb, {})
assign(:template_valid, true)
end

it 'enables Order button' do
render :partial => 'catalog/svccat_tree_show'
expect(response).to include("<button name=\"button\" type=\"submit\" class=\"btn btn-primary\" alt=\"Order this Service\" title=\"Order this Service\" onclick=\"miqOrderService(#{service.id})\">Order</button>")
end

context 'invalid Catalog items or Bundles' do
before { assign(:template_valid, false) }

it 'disables Order button' do
render :partial => 'catalog/svccat_tree_show'
expect(response).to include("<button name=\"button\" type=\"submit\" class=\"btn btn-primary\" alt=\"This Service cannot be ordered\" title=\"This Service cannot be ordered\" disabled=\"disabled\" onclick=\"miqOrderService(#{service.id})\">Order</button>")
end
end
end

0 comments on commit 150ef99

Please sign in to comment.