|
1 | 1 | require File.expand_path(File.dirname(__FILE__) + '/common') |
2 | | -require File.expand_path(File.dirname(__FILE__) + '/helpers/discussion_announcement_specs') |
3 | 2 |
|
4 | 3 | describe "announcements" do |
5 | 4 | it_should_behave_like "in-process server selenium tests" |
@@ -106,13 +105,171 @@ def create_announcement_manual(css_checkbox) |
106 | 105 | describe "shared bulk topics specs" do |
107 | 106 | let(:url) { "/courses/#{@course.id}/announcements/" } |
108 | 107 | 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 |
110 | 182 | end |
111 | 183 |
|
112 | 184 | describe "shared main page topics specs" do |
113 | 185 | let(:url) { "/courses/#{@course.id}/announcements/" } |
114 | 186 | 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 |
116 | 273 | end |
117 | 274 |
|
118 | 275 | it "should create a delayed announcement" do |
|
0 commit comments