forked from ManageIQ/manageiq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwidgets_spec.rb
80 lines (72 loc) · 4.19 KB
/
widgets_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
describe ReportController do
before(:each) do
EvmSpecHelper.create_guid_miq_server_zone
set_user_privileges
end
describe "#widget_edit" do
let(:miq_schedule) { FactoryGirl.build(:miq_schedule, :run_at => {}, :sched_action => {}) }
let(:new_widget) { controller.instance_variable_get(:@widget) }
# Configuration Management/Virtual Machines/VMs with Free Space > 50% by Department report
let(:report_id) { 100_000_000_000_01 }
before :each do
@previous_count_of_widgets = MiqWidget.count
allow(controller).to receive_messages(:load_edit => true)
allow(controller).to receive(:widget_graph_menus)
allow(controller).to receive(:replace_right_cell)
allow(controller).to receive(:render)
controller.instance_variable_set(:@sb, :wtype => 'c') # chart widget
end
context "add new widget" do
before :each do
controller.instance_variable_set(:@_params, :button => "add")
end
context "valid attributes" do
before :each do
controller.instance_variable_set(:@edit,
:schedule => miq_schedule, :new => {:title => "NewCustomWidget",
:description => "NewCustomWidget",
:enabled => true, :roles => ["_ALL_"],
:groups => [], :timer_weeks => "1",
:timer_days => "1", :timer_hours => "1",
:timer_typ => "Hourly",
:start_hour => "00",
:start_min => "10",
:start_date => "11/13/2015",
:repfilter => report_id})
controller.send(:widget_edit)
end
it "adds new widget with entered attributes" do
expect(MiqWidget.count).to eq(@previous_count_of_widgets + 1)
expect(new_widget.errors.count).to eq(0)
expect(new_widget.title).to eq("NewCustomWidget")
expect(new_widget.description).to eq("NewCustomWidget")
expect(new_widget.enabled).to eq(true)
end
it "creates widget with widget.id in 'value' field from cond. of MiqExpression (in MiqSchedule.filter)" do
expect(new_widget.id).to be_instance_of(Fixnum)
expect(miq_schedule.filter.exp["="]["value"]).to eq(new_widget.id)
end
end
context "invalid attributes" do
before :each do
controller.instance_variable_set(:@edit,
:schedule => miq_schedule, :new => {:title => "",
:description => "",
:enabled => true, :roles => ["_ALL_"],
:groups => [], :timer_weeks => "1",
:timer_days => "1", :timer_hours => "1",
:timer_typ => "Hourly",
:start_hour => "00",
:start_min => "10",
:start_date => "11/13/2015",
:repfilter => report_id})
controller.send(:widget_edit)
end
it "doesn't add new widget" do
expect(MiqWidget.count).to eq(@previous_count_of_widgets)
expect(new_widget.errors.count).not_to eq(0)
end
end
end
end
end