forked from theforeman/foreman_salt
/
hosts_js_test.rb
82 lines (65 loc) · 2.89 KB
/
hosts_js_test.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
81
82
require 'test_plugin_helper'
require 'integration_test_helper'
module ForemanSalt
class HostJSTest < IntegrationTestWithJavascript
def index_modal
page.find('#confirmation-modal')
end
def multiple_actions_div
page.find('#submit_multiple')
end
setup do
as_admin do
proxy = FactoryBot.create(:smart_proxy, :with_salt_feature)
salt_environment = FactoryBot.create(:salt_environment)
@host = FactoryBot.create(:host, :salt_proxy => proxy, :salt_environment => salt_environment)
end
end
describe "hosts index salt multiple actions" do
test 'change salt master action' do
visit hosts_path
page.find('#check_all').trigger('click')
# Ensure and wait for all hosts to be checked, and that no unchecked hosts remain
assert page.has_no_selector?('input.host_select_boxes:not(:checked)')
# Dropdown visible?
assert multiple_actions_div.find('.dropdown-toggle').visible?
multiple_actions_div.find('.dropdown-toggle').click
assert multiple_actions_div.find('ul').visible?
# Hosts are added to cookie
host_ids_on_cookie = JSON.parse(CGI.unescape(page.driver.cookies['_ForemanSelectedhosts'].value))
assert(host_ids_on_cookie.include?(@host.id))
within('#submit_multiple') do
click_on('Change Salt Master')
end
assert index_modal.visible?, "Modal window was shown"
page.find('#proxy_proxy_id').find("option[value='#{@host.salt_proxy.id}']").select_option
# remove hosts cookie on submit
index_modal.find('.btn-primary').click
assert_current_path hosts_path
assert_empty(page.driver.cookies['_ForemanSelectedhosts'])
end
test 'change salt environment action' do
visit hosts_path
page.find('#check_all').trigger('click')
# Ensure and wait for all hosts to be checked, and that no unchecked hosts remain
assert page.has_no_selector?('input.host_select_boxes:not(:checked)')
# Dropdown visible?
assert multiple_actions_div.find('.dropdown-toggle').visible?
multiple_actions_div.find('.dropdown-toggle').click
assert multiple_actions_div.find('ul').visible?
# Hosts are added to cookie
host_ids_on_cookie = JSON.parse(CGI.unescape(page.driver.cookies['_ForemanSelectedhosts'].value))
assert(host_ids_on_cookie.include?(@host.id))
within('#submit_multiple') do
click_on('Change Salt Environment')
end
assert index_modal.visible?, "Modal window was shown"
page.find('#salt_environment_id').find("option[value='#{@host.salt_environment.id}']").select_option
# remove hosts cookie on submit
index_modal.find('.btn-primary').click
assert_current_path hosts_path
assert_empty(page.driver.cookies['_ForemanSelectedhosts'])
end
end
end
end