Skip to content

Commit

Permalink
Add specs for dashboards clone methods
Browse files Browse the repository at this point in the history
  • Loading branch information
rvsia committed Jun 26, 2019
1 parent 3c07a8a commit 6d8df75
Showing 1 changed file with 100 additions and 10 deletions.
110 changes: 100 additions & 10 deletions spec/controllers/miq_report_controller/dashboards_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,97 @@
let(:user) { FactoryBot.create(:user, :features => "db_edit") }

before do
login_as user
stub_user(:features => :all)
end

describe "#db_copy" do
context "when save button" do
it "saves successfully" do
params = {:button => "save", :dashboard_id => miq_widget_set.id.to_s, :group_id => user.current_group.id.to_s, :name => 'New Name', :description => 'New description'}
post :db_copy, :params => params

expect(JSON.parse(response.body)).to eq({})
expect(response.status).to eq(200)
expect(MiqWidgetSet.last.name).to eq("New Name")
expect(MiqWidgetSet.last.description).to eq("New description")
expect(MiqWidgetSet.last.group_id).to eq(miq_widget_set.group_id)
expect(MiqWidgetSet.last.set_data).to eq(miq_widget_set.set_data)
expect(MiqWidgetSet.last.guid).not_to eq(miq_widget_set.guid)
end

it "saves unsuccessfully and returns error message" do
params = {:button => "save", :dashboard_id => miq_widget_set.id.to_s, :group_id => user.current_group.id.to_s, :name => miq_widget_set.name.to_s, :description => 'New description'}
post :db_copy, :params => params

expect(JSON.parse(response.body)["error"]["message"]).to include("Error")
expect(response.status).to eq(400)
end
end

context "when cancel button" do
it "cancels " do
controller.instance_variable_set(:@sb, {})

expect(controller).to receive(:get_node_info)
expect(controller).to receive(:replace_right_cell)
expect(controller).to receive(:add_flash)

controller.params = {:button => "cancel"}
controller.send(:db_copy)
expect(assigns(:dashboard)).to eq(nil)
end
end

context "when no button" do
it "sets variables" do
allow(controller).to receive(:find_record_with_rbac).and_return(miq_widget_set)

expect(controller).to receive(:replace_right_cell).with(:action => "copy_dashboard")

controller.send(:db_copy)

expect(assigns(:tabactive)).to eq(false)
expect(assigns(:in_a_form)).to eq(true)
expect(assigns(:right_cell_text)).to eq("Copy of \"%{dashboard}\" Dashboard" % {:dashboard => miq_widget_set.name})
end
end
end

describe "#dashboard_get" do
it "finds by id" do
get :dashboard_get, :params => {:id => miq_widget_set.id.to_s}

expect(JSON.parse(response.body)).to eq(
"description" => miq_widget_set.description.to_s,
"name" => miq_widget_set.name.to_s,
"owner_id" => miq_widget_set.owner_id.to_s
)
end

it "finds by name" do
get :dashboard_get, :params => {:id => miq_widget_set.id.to_s, :name => miq_widget_set.name.to_s}

expect(JSON.parse(response.body)).to eq("length" => 1)
end

it "finds by not existing name" do
get :dashboard_get, :params => {:id => miq_widget_set.id.to_s, :name => "blabla"}

expect(JSON.parse(response.body)).to eq("length" => 0)
end
end

describe "#dashboard_render" do
it "renders" do
controller.instance_variable_set(:@sb, {})

expect(controller).to receive(:get_node_info)
expect(controller).to receive(:replace_right_cell).with(:replace_trees => [:db])
expect(controller).to receive(:add_flash)

controller.send(:dashboard_render)
expect(assigns(:dashboard)).to eq(nil)
end
end

describe "#db_edit" do
Expand All @@ -29,7 +119,7 @@
end

before do
miq_widget_set.update_attributes!(:set_data => set_data)
miq_widget_set.update!(:set_data => set_data)

login_as user

Expand All @@ -51,15 +141,15 @@
@widget1 = FactoryBot.create(:miq_widget)
@widget2 = FactoryBot.create(:miq_widget)
@miq_widget_set = FactoryBot.create(:miq_widget_set,
:owner => user.current_group,
:name => "fred",
:description => "FRED",
:set_data => {:col1 => [@widget1.id], :col2 => [], :col3 => []})
:owner => user.current_group,
:name => "fred",
:description => "FRED",
:set_data => {:col1 => [@widget1.id], :col2 => [], :col3 => []})
FactoryBot.create(:miq_widget_set,
:owner => user.current_group,
:name => "wilma",
:description => "WILMA",
:set_data => {:col1 => [@widget2.id], :col2 => [], :col3 => []})
:owner => user.current_group,
:name => "wilma",
:description => "WILMA",
:set_data => {:col1 => [@widget2.id], :col2 => [], :col3 => []})
login_as user
EvmSpecHelper.local_miq_server
end
Expand Down

0 comments on commit 6d8df75

Please sign in to comment.