forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalerts_spec.rb
More file actions
220 lines (178 loc) · 7.24 KB
/
Copy pathalerts_spec.rb
File metadata and controls
220 lines (178 loc) · 7.24 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
require File.expand_path(File.dirname(__FILE__) + '/common')
describe "Alerts" do
include_context "in-process server selenium tests"
before (:each) do
@context = Account.default
@context.settings[:enable_alerts] = true
@context.save!
@alerts = @context.alerts
admin_logged_in
end
it "should be able to create, then update, then delete" do
get "/accounts/#{@context.id}/settings"
expect(@alerts.length).to eq 0
find('#tab-alerts-link').click
wait_for_ajaximations
find('.add_alert_link').click
wait_for_ajaximations
alert = find('.alert.new')
(add_criterion = alert.find('.add_criterion_link')).click
wait_for_ajaximations
alert.find('.add_recipient_link').click
wait_for_ajaximations
(submit = alert.find('.submit_button')).click
wait_for_ajaximations
keep_trying_until do
@alerts.reload
expect(@alerts.length).to eq 1
end
expect(@alerts.first.criteria.length).to eq 1
(edit = alert.find('.edit_link')).click
add_criterion.click
wait_for_ajaximations
submit.click
wait_for_ajaximations
keep_trying_until do
@alerts.first.criteria.reload
expect(@alerts.first.criteria.length).to eq 2
end
@alerts.reload
expect(@alerts.length).to eq 1
wait_for_ajaximations
edit.click
alert.find('.criteria .delete_item_link').click
expect(ff('.alert .criteria li')).to have_size(1)
submit.click
wait_for_ajaximations
keep_trying_until do
@alerts.first.criteria.reload
expect(@alerts.first.criteria.length).to eq 1
end
@alerts.reload
expect(@alerts.length).to eq 1
wait_for_ajaximations
alert.find('.delete_link').click
wait_for_ajaximations
expect(find('.alert')).not_to be_displayed
keep_trying_until do
@alerts.reload
expect(@alerts.length).to eq 0
end
end
it "should delete alerts" do
alert = @alerts.create!(:recipients => [:student], :criteria => [:criterion_type => 'Interaction', :threshold => 7])
get "/accounts/#{@context.id}/settings"
find('#tab-alerts-link').click
wait_for_ajaximations
find("#edit_alert_#{alert.id} .delete_link").click
expect(f("#content")).not_to contain_css("#edit_alert_#{alert.id}")
@alerts.reload
expect(@alerts).to be_empty
end
it "should remove non-created alerts by clicking delete link" do
get "/accounts/#{@context.id}/settings"
find('#tab-alerts-link').click
wait_for_ajaximations
find('.add_alert_link').click
wait_for_ajaximations
find('.alert.new .delete_link').click
wait_for_ajaximations
expect(f("#content")).not_to contain_css(".alert.new")
expect(@alerts).to be_empty
end
it "should remove non-created alerts by clicking cancel button" do
get "/accounts/#{@context.id}/settings"
find('#tab-alerts-link').click
wait_for_ajaximations
find('.add_alert_link').click
wait_for_ajaximations
find('.alert.new .cancel_button').click
expect(f("#content")).not_to contain_css(".alert.new")
expect(@alerts).to be_empty
end
it "should validate the form" do
get "/accounts/#{@context.id}/settings"
find('#tab-alerts-link').click
wait_for_ajaximations
find('.add_alert_link').click
wait_for_ajaximations
alert = find('.alert.new')
alert.find('input[name="repetition"][value="value"]').click
submit_form('#new_alert')
wait_for_ajaximations
error_boxes = ff('.error_box')
expect(error_boxes).to have_size(4)
# clicking "do not repeat" should remove the number of days error
alert.find('input[name="repetition"][value="none"]').click
wait_for_ajaximations
expect(error_boxes).to have_size(3)
# adding recipient and criterion make the errors go away
alert.find('.add_recipient_link').click
alert.find('.add_criterion_link').click
expect(error_boxes).to have_size(1)
alert.find('.criteria input[type="text"]').send_keys("abc")
submit_form('#new_alert')
expect(error_boxes).to have_size(2)
end
context "recipients" do
it "should hide the add link when all recipients are added" do
get "/accounts/#{@context.id}/settings"
find('#tab-alerts-link').click
wait_for_ajaximations
find('.add_alert_link').click
wait_for_ajaximations
alert = find('.alert.new')
link = alert.find('.add_recipient_link')
expect(ff('.alert.new .add_recipients_line select option')).to have_size(3)
alert.find_all('.add_recipients_line select option').each do
link.click
end
expect(find('.alert.new .add_recipient_link')).not_to be_displayed
end
it "should not show the add link when all recipients are already there" do
alert = @alerts.create!(:recipients => [:student, :teachers, {:role_id => admin_role.id}], :criteria => [{:criterion_type => 'Interaction', :threshold => 7}])
get "/accounts/#{@context.id}/settings"
find('#tab-alerts-link').click
wait_for_ajaximations
alertElement = find("#edit_alert_#{alert.id}")
alertElement.find(".edit_link").click
wait_for_ajaximations
expect(f("#edit_alert_#{alert.id}")).not_to contain_jqcss(".add_recipient_link:visible")
# Deleting a recipient should add it to the dropdown (which is now visible)
alertElement.find('.recipients .delete_item_link').click
wait_for_ajaximations
expect(fj("#edit_alert_#{alert.id} .add_recipient_link")).to be_displayed
expect(alertElement.find_all('.add_recipients_line select option').length).to eq 1
expect(ff('.recipients li', alertElement)).to have_size(2)
# Do it again, with the same results
alertElement.find('.recipients .delete_item_link').click
expect(fj("#edit_alert_#{alert.id} .add_recipient_link")).to be_displayed
expect(alertElement.find_all('.add_recipients_line select option').length).to eq 2
expect(ff('.recipients li', alertElement)).to have_size(1)
# Clicking cancel should restore the LIs
alertElement.find('.cancel_button').click
expect(alertElement.find_all('.recipients li').length).to eq 3
end
it "should work with custom roles" do
role1 = custom_account_role('these rolls are delicious', :account => @context)
role2 = custom_account_role('your just jelly', :account => @context)
alert = @alerts.create!(:recipients => [{:role_id => role1.id}], :criteria => [{:criterion_type => 'Interaction', :threshold => 7}])
get "/accounts/#{@context.id}/settings"
find('#tab-alerts-link').click
wait_for_ajaximations
alertElement = find("#edit_alert_#{alert.id}")
alertElement.find(".edit_link").click
wait_for_ajaximations
recipients = find_all("#edit_alert_#{alert.id} .recipients li")
expect(recipients.count).to eq 1
expect(recipients.first.text).to match_ignoring_whitespace(role1.name)
expect(find("#edit_alert_#{alert.id} .recipients li input")["value"].to_s).to eq role1.id.to_s
set_value(find("#edit_alert_#{alert.id} .add_recipients_line select"), role2.id.to_s)
fj("#edit_alert_#{alert.id} .add_recipient_link").click
submit_form("#edit_alert_#{alert.id}")
wait_for_ajaximations
alert.reload
expect(alert.recipients.map{|r| r[:role_id]}.sort).to eq [role1.id, role2.id].sort
end
end
end