Skip to content

Commit 3dcef4a

Browse files
committed
spec: shared spec removal and refactor
Change-Id: I8011da7dd9c827e6118ded28acbacdf0aa3d5283 Reviewed-on: https://gerrit.instructure.com/18899 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Jake Sorce <jake@instructure.com> Product-Review: Jake Sorce <jake@instructure.com> QA-Review: Jake Sorce <jake@instructure.com>
1 parent 032b13b commit 3dcef4a

19 files changed

Lines changed: 566 additions & 362 deletions
Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,39 @@
11
require File.expand_path(File.dirname(__FILE__) + '/../common')
2-
require File.expand_path(File.dirname(__FILE__) + '/../helpers/rubrics_specs')
3-
describe "account rubrics" do
4-
describe "shared rubric specs" do
5-
let(:rubric_url) { "/accounts/#{Account.default.id}/rubrics" }
6-
let(:who_to_login) { 'admin' }
7-
let(:account) { Account.default }
8-
it_should_behave_like "rubric tests"
9-
end
10-
end
2+
require File.expand_path(File.dirname(__FILE__) + '/../helpers/rubrics_common')
3+
require File.expand_path(File.dirname(__FILE__) + '/../common')
4+
5+
describe "account shared rubric specs" do
6+
it_should_behave_like "in-process server selenium tests"
7+
8+
let(:rubric_url) { "/accounts/#{Account.default.id}/rubrics" }
9+
let(:who_to_login) { 'admin' }
10+
let(:account) { Account.default }
11+
12+
before (:each) do
13+
course_with_admin_logged_in
14+
end
15+
16+
it "should delete a rubric" do
17+
should_delete_a_rubric
18+
end
19+
it "should edit a rubric" do
20+
should_edit_a_rubric
21+
end
22+
23+
it "should allow fractional points" do
24+
should_allow_fractional_points
25+
end
26+
27+
28+
it "should round to 2 decimal places" do
29+
should_round_to_2_decimal_places
30+
end
31+
32+
it "should round to an integer when splitting" do
33+
should_round_to_an_integer_when_splitting
34+
end
35+
36+
it "should pick the lower value when splitting without room for an integer" do
37+
should_pick_the_lower_value_when_splitting_without_room_for_an_integer
38+
end
39+
end
Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,37 @@
11
require File.expand_path(File.dirname(__FILE__) + '/../../common')
2-
require File.expand_path(File.dirname(__FILE__) + '/../../helpers/rubrics_specs')
3-
4-
describe "sub account rubrics" do
5-
describe "shared rubric specs" do
6-
let(:account) { Account.create(:name => 'sub account from default account', :parent_account => Account.default) }
7-
let(:rubric_url) { "/accounts/#{account.id}/rubrics" }
8-
let(:who_to_login) { 'admin' }
9-
it_should_behave_like "rubric tests"
2+
require File.expand_path(File.dirname(__FILE__) + '/../../helpers/rubrics_common')
3+
4+
describe "sub account shared rubric specs" do
5+
it_should_behave_like "in-process server selenium tests"
6+
let(:account) { Account.create(:name => 'sub account from default account', :parent_account => Account.default) }
7+
let(:rubric_url) { "/accounts/#{account.id}/rubrics" }
8+
let(:who_to_login) { 'admin' }
9+
10+
before (:each) do
11+
course_with_admin_logged_in
12+
end
13+
14+
it "should delete a rubric" do
15+
should_delete_a_rubric
16+
end
17+
it "should edit a rubric" do
18+
should_edit_a_rubric
19+
end
20+
21+
it "should allow fractional points" do
22+
should_allow_fractional_points
23+
end
24+
25+
26+
it "should round to 2 decimal places" do
27+
should_round_to_2_decimal_places
28+
end
29+
30+
it "should round to an integer when splitting" do
31+
should_round_to_an_integer_when_splitting
32+
end
33+
34+
it "should pick the lower value when splitting without room for an integer" do
35+
should_pick_the_lower_value_when_splitting_without_room_for_an_integer
1036
end
1137
end

spec/selenium/announcements_spec.rb

Lines changed: 160 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
require File.expand_path(File.dirname(__FILE__) + '/common')
2-
require File.expand_path(File.dirname(__FILE__) + '/helpers/discussion_announcement_specs')
32

43
describe "announcements" do
54
it_should_behave_like "in-process server selenium tests"
@@ -106,13 +105,171 @@ def create_announcement_manual(css_checkbox)
106105
describe "shared bulk topics specs" do
107106
let(:url) { "/courses/#{@course.id}/announcements/" }
108107
let(:what_to_create) { Announcement }
109-
it_should_behave_like "discussion and announcement main page tests"
108+
109+
before (:each) do
110+
@context = @course
111+
5.times do |i|
112+
title = "new #{i.to_s.rjust(3, '0')}"
113+
what_to_create == DiscussionTopic ? @course.discussion_topics.create!(:title => title, :user => @user) : announcement_model(:title => title, :user => @user)
114+
end
115+
get url
116+
wait_for_ajaximations
117+
@checkboxes = ff('.toggleSelected')
118+
end
119+
120+
def update_attributes_and_validate(attribute, update_value, search_term = update_value, expected_results = 1)
121+
what_to_create.last.update_attributes(attribute => update_value)
122+
refresh_page # in order to get the new topic information
123+
replace_content(f('#searchTerm'), search_term)
124+
ff('.discussionTopicIndexList .discussion-topic').count.should == expected_results
125+
end
126+
127+
def refresh_and_filter(filter_type, filter, expected_text, expected_results = 1)
128+
refresh_page # in order to get the new topic information
129+
wait_for_ajaximations
130+
keep_trying_until { ff('.toggleSelected').count.should == what_to_create.count }
131+
filter_type == :css ? driver.execute_script("$('#{filter}').click()") : replace_content(f('#searchTerm'), filter)
132+
ff('.discussionTopicIndexList .discussion-topic').count.should == expected_results
133+
expected_results > 1 ? ff('.discussionTopicIndexList .discussion-topic').each { |topic| topic.should include_text(expected_text) } : (f('.discussionTopicIndexList .discussion-topic').should include_text(expected_text))
134+
end
135+
136+
it "should bulk delete topics" do
137+
5.times { |i| @checkboxes[i].click }
138+
f('#delete').click
139+
driver.switch_to.alert.accept
140+
wait_for_ajax_requests
141+
ff('.discussion-topic').count.should == 0
142+
what_to_create.where(:workflow_state => 'active').count.should == 0
143+
end
144+
145+
it "should bulk lock topics" do
146+
5.times { |i| @checkboxes[i].click }
147+
f('#lock').click
148+
wait_for_ajax_requests
149+
#TODO: check the UI to make sure the topics have a locked symbol
150+
what_to_create.where(:workflow_state => 'locked').count.should == 5
151+
end
152+
153+
it "should search by title" do
154+
expected_text = 'hey there'
155+
update_attributes_and_validate(:title, expected_text)
156+
end
157+
158+
it "should search by body" do
159+
body_text = 'new topic body'
160+
update_attributes_and_validate(:message, body_text, 'topic')
161+
end
162+
163+
it "should search by author" do
164+
user_name = 'jake@instructure.com'
165+
title = 'new one'
166+
new_teacher = teacher_in_course(:course => @course, :active_all => true, :name => user_name)
167+
what_to_create == DiscussionTopic ? @course.discussion_topics.create!(:title => title, :user => new_teacher.user) : announcement_model(:title => title, :user => new_teacher.user)
168+
refresh_and_filter(:string, 'jake', user_name)
169+
end
170+
171+
it "should return multiple items in the search" do
172+
new_title = 'updated'
173+
what_to_create.first.update_attributes(:title => "#{new_title} first")
174+
what_to_create.last.update_attributes(:title => "#{new_title} last")
175+
refresh_and_filter(:string, new_title, new_title, 2)
176+
end
177+
178+
it "should filter by unread" do
179+
what_to_create.last.change_read_state('unread', @user)
180+
refresh_and_filter(:css, '#onlyUnread', 'new 004')
181+
end
110182
end
111183

112184
describe "shared main page topics specs" do
113185
let(:url) { "/courses/#{@course.id}/announcements/" }
114186
let(:what_to_create) { Announcement }
115-
it_should_behave_like "discussion and announcement individual tests"
187+
188+
def add_attachment_and_validate
189+
filename, fullpath, data = get_file("testfile5.zip")
190+
f('input[name=attachment]').send_keys(fullpath)
191+
type_in_tiny('textarea[name=message]', 'file attachement discussion')
192+
expect_new_page_load { submit_form('.form-actions') }
193+
wait_for_ajaximations
194+
f('.zip').should include_text(filename)
195+
end
196+
197+
def edit(title, message)
198+
replace_content(f('input[name=title]'), title)
199+
type_in_tiny('textarea[name=message]', message)
200+
expect_new_page_load { submit_form('.form-actions') }
201+
f('#discussion_topic .discussion-title').text.should == title
202+
end
203+
204+
before (:each) do
205+
@topic_title = 'new discussion'
206+
@context = @course
207+
end
208+
209+
it "should start a new topic" do
210+
get url
211+
212+
expect_new_page_load { f('.btn-primary').click }
213+
edit(@topic_title, 'new topic')
214+
end
215+
216+
it "should add an attachment to a new topic" do
217+
topic_title = 'new topic with file'
218+
get url
219+
220+
expect_new_page_load { f('.btn-primary').click }
221+
replace_content(f('input[name=title]'), topic_title)
222+
add_attachment_and_validate
223+
what_to_create.find_by_title(topic_title).attachment_id.should be_present
224+
end
225+
226+
it "should add an attachment to a graded topic" do
227+
what_to_create == DiscussionTopic ? @course.discussion_topics.create!(:title => 'graded attachment topic', :user => @user) : announcement_model(:title => 'graded attachment topic', :user => @user)
228+
if what_to_create == DiscussionTopic
229+
what_to_create.last.update_attributes(:assignment => @course.assignments.create!(:name => 'graded topic assignment'))
230+
end
231+
get url
232+
expect_new_page_load { f('.discussion-title').click }
233+
expect_new_page_load { f(".edit-btn").click }
234+
235+
add_attachment_and_validate
236+
end
237+
238+
it "should edit a topic" do
239+
edit_name = 'edited discussion name'
240+
topic = what_to_create == DiscussionTopic ? @course.discussion_topics.create!(:title => @topic_title, :user => @user) : announcement_model(:title => @topic_title, :user => @user)
241+
get url + "#{topic.id}"
242+
expect_new_page_load { f(".edit-btn").click }
243+
244+
edit(edit_name, 'edit message')
245+
end
246+
247+
it "should delete a topic" do
248+
what_to_create == DiscussionTopic ? @course.discussion_topics.create!(:title => @topic_title, :user => @user) : announcement_model(:title => @topic_title, :user => @user)
249+
get url
250+
251+
f('.toggleSelected').click
252+
f('#delete').click
253+
driver.switch_to.alert.accept
254+
wait_for_ajaximations
255+
what_to_create.last.workflow_state.should == 'deleted'
256+
f('.discussionTopicIndexList').should be_nil
257+
end
258+
259+
it "should reorder topics" do
260+
3.times { |i| what_to_create == DiscussionTopic ? @course.discussion_topics.create!(:title => "new topic #{i}", :user => @user) : announcement_model(:title => "new topic #{i}", :user => @user) }
261+
get url
262+
wait_for_ajax_requests
263+
264+
topics = ff('.discussion-topic')
265+
driver.action.move_to(topics[0]).perform
266+
# drag first topic to second place
267+
# (using topics[2] as target to get the dragging to work)
268+
driver.action.drag_and_drop(fj('.discussion-drag-handle:visible', topics[0]), topics[2]).perform
269+
wait_for_ajax_requests
270+
new_topics = ffj('.discussion-topic') # using ffj to avoid selenium caching
271+
new_topics[0].should_not include_text('new topic 0')
272+
end
116273
end
117274

118275
it "should create a delayed announcement" do

spec/selenium/assignments_discussion_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
require File.expand_path(File.dirname(__FILE__) + '/helpers/assignments_common')
22

33
describe "discussion assignments" do
4-
it_should_behave_like "assignments selenium tests"
4+
it_should_behave_like "in-process server selenium tests"
5+
56

67
before (:each) do
78
course_with_teacher_logged_in

spec/selenium/assignments_quizzes_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
require File.expand_path(File.dirname(__FILE__) + '/helpers/assignments_common')
22

33
describe "quizzes assignments" do
4-
it_should_behave_like "assignments selenium tests"
4+
it_should_behave_like "in-process server selenium tests"
5+
56

67
before (:each) do
78
course_with_teacher_logged_in

spec/selenium/calendar2_spec.rb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1+
require File.expand_path(File.dirname(__FILE__) + '/common')
12
require File.expand_path(File.dirname(__FILE__) + '/helpers/calendar2_common')
23

34
describe "calendar2" do
4-
it_should_behave_like "calendar2 selenium tests"
5+
it_should_behave_like "in-process server selenium tests"
6+
7+
before (:each) do
8+
Account.default.tap do |a|
9+
a.settings[:enable_scheduler] = true
10+
a.settings[:show_scheduler] = true
11+
a.save!
12+
end
13+
end
514

615
def make_event(params = {})
716
opts = {
@@ -635,7 +644,7 @@ def create_middle_day_assignment(name = 'new assignment')
635644
# click the event in the calendar
636645
fj('.fc-event').click
637646
fj("#popover-0").should be_displayed
638-
expect_new_page_load { driver.execute_script("$('.view_event_link').hover().click()") }
647+
expect_new_page_load { driver.execute_script("$('.view_event_link').hover().click()") }
639648

640649
page_title = f('.title')
641650
page_title.should be_displayed

spec/selenium/context_modules_spec.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
require File.expand_path(File.dirname(__FILE__) + '/helpers/context_modules_common')
22

33
describe "context_modules" do
4-
it_should_behave_like "context module tests"
5-
4+
it_should_behave_like "in-process server selenium tests"
65
context "as a teacher" do
76

87
before (:each) do

0 commit comments

Comments
 (0)