/
batch_action_steps.rb
94 lines (78 loc) · 3.1 KB
/
batch_action_steps.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
83
84
85
86
87
88
89
90
91
92
93
94
Then /^I (should|should not) see the batch action "([^"]*)"$/ do |maybe, title|
%{Then I #{maybe} see the batch action :#{title.gsub(' ','').gsub(" Selected", "").underscore} "#{title}"}
end
Then /^I (should|should not) be asked to confirm "([^"]*)" for "([^"]*)"$/ do |maybe, confirmation, title|
within "#batch_actions_popover" do
unless maybe == "should not"
link = page.find "a.batch_action", :text => title
link["data-confirm"].should match( confirmation )
else
page.should_not have_css("a.batch_action", :text => title)
end
end
end
Then /^I (should|should not) see the batch action :([^\s]*) "([^"]*)"$/ do |maybe, sym, title|
within "#batch_actions_selector" do
unless maybe == "should not"
link = page.find "a.batch_action", :text => title
link["data-action"].should match( sym )
link[:href].should match( "#" )
else
page.should_not have_css("a.batch_action", :text => title)
end
end
end
Then /^the (\d+)(?:st|nd|rd|th) batch action should be "([^"]*)"$/ do |index, title|
within "#batch_actions_selector" do
page.all( "a.batch_action" )[index.to_i - 1].text.should match( title )
end
end
When /^I check the (\d+)(?:st|nd|rd|th) record$/ do |index|
page.all( "table.index_table input[type=checkbox]" )[index.to_i].set( true )
end
When /^I uncheck the (\d+)(?:st|nd|rd|th) record$/ do |index|
page.all( "table.index_table input[type='checkbox']" )[index.to_i].set( false )
end
When /^I toggle the collection selection$/ do
toggle_box = page.find( "#collection_selection_toggle_all" )
toggle_box.click
end
Then /^I should see (\d+) record(?:s)? selected$/ do |count|
within "table.index_table" do
unless count.to_i == 0
page.should have_xpath(".//input[@type='checkbox' and @checked='checked']", :count => count)
else
page.should have_no_xpath(".//input[@type='checkbox' and @checked='checked']")
end
end
end
Then /^I should see that the batch action button is disabled$/ do
page.should have_css("#batch_actions_selector .dropdown_menu_button.disabled")
end
Then /^I (should|should not) see the batch action button$/ do |maybe|
if maybe == "should not"
page.should_not have_css("div.table_tools #batch_actions_selector .dropdown_menu_button")
else
page.should have_css("div.table_tools #batch_actions_selector .dropdown_menu_button")
end
end
Then "I should not see the batch actions selector" do
page.should_not have_css("div.table_tools #batch_actions_selector")
end
Then /^I should see the batch action popover exists$/ do
page.should have_css("#batch_actions_selector")
end
Given /^I submit the batch action form with "([^"]*)"$/ do |action|
page.find(:css, "#batch_action").set(action)
within("#main_content") do
@params = page.all("input").reduce({}) do |acc, input|
acc.store(input['name'], input['value'])
acc
end
end
form = page.find("#collection_selection")
page.driver.submit(form['method'].to_sym, form['action'], @params)
end
Then /^I should not see checkboxes in the table$/ do
page.should_not have_css( ".paginated_collection table input[type=checkbox]" )
end