|
| 1 | +require File.expand_path(File.dirname(__FILE__) + '/common') |
| 2 | + |
| 3 | +describe "manage_groups selenium tests" do |
| 4 | + it_should_behave_like "in-process server selenium tests" |
| 5 | + |
| 6 | + it "should show one div.group_category per category" do |
| 7 | + course_with_teacher_logged_in |
| 8 | + |
| 9 | + @course.enroll_student(user_model(:name => "John Doe")) |
| 10 | + @course.enroll_student(user_model(:name => "Jane Doe")) |
| 11 | + @course.enroll_student(user_model(:name => "Spot the Dog")) |
| 12 | + @course.groups.create(:name => "Group 1", :group_category_name => "Group Category 1") |
| 13 | + @course.groups.create(:name => "Group 2", :group_category_name => "Group Category 2") |
| 14 | + @course.groups.create(:name => "Group 3", :group_category_name => "Group Category 2") |
| 15 | + @course.groups.create(:name => "Group 4", :group_category_name => "Group Category 3") |
| 16 | + |
| 17 | + get "/courses/#{@course.id}/groups" |
| 18 | + |
| 19 | + group_divs = find_all_with_jquery("div.group_category") |
| 20 | + group_divs.size.should == 4 # three groups + blank |
| 21 | + |
| 22 | + ids = group_divs.map{ |div| div.attribute(:id) } |
| 23 | + ids.should be_include("Group Category 1".unpack('H*').first) |
| 24 | + ids.should be_include("Group Category 2".unpack('H*').first) |
| 25 | + ids.should be_include("Group Category 3".unpack('H*').first) |
| 26 | + ids.should be_include("category_template") |
| 27 | + end |
| 28 | + |
| 29 | + it "should flag div.group_category for student organized categories with student_organized class" do |
| 30 | + course_with_teacher_logged_in |
| 31 | + |
| 32 | + @course.enroll_student(user_model(:name => "John Doe")) |
| 33 | + @course.enroll_student(user_model(:name => "Jane Doe")) |
| 34 | + @course.enroll_student(user_model(:name => "Spot the Dog")) |
| 35 | + @course.groups.create(:name => "Group 1", :group_category_name => "Student Groups") |
| 36 | + @course.groups.create(:name => "Group 2", :group_category_name => "Student Groups") |
| 37 | + @course.groups.create(:name => "Group 3", :group_category_name => "Other Groups") |
| 38 | + |
| 39 | + get "/courses/#{@course.id}/groups" |
| 40 | + |
| 41 | + find_all_with_jquery("div.group_category").size.should == 3 |
| 42 | + find_all_with_jquery("div.group_category.student_organized").size.should == 1 |
| 43 | + find_with_jquery("div.group_category.student_organized").attribute(:id). |
| 44 | + should == "Student Groups".unpack('H*').first |
| 45 | + end |
| 46 | + |
| 47 | + it "should show one li.category per category" do |
| 48 | + course_with_teacher_logged_in |
| 49 | + |
| 50 | + @course.enroll_student(user_model(:name => "John Doe")) |
| 51 | + @course.enroll_student(user_model(:name => "Jane Doe")) |
| 52 | + @course.enroll_student(user_model(:name => "Spot the Dog")) |
| 53 | + @course.groups.create(:name => "Group 1", :group_category_name => "Group Category 1") |
| 54 | + @course.groups.create(:name => "Group 2", :group_category_name => "Group Category 2") |
| 55 | + @course.groups.create(:name => "Group 3", :group_category_name => "Group Category 2") |
| 56 | + @course.groups.create(:name => "Group 4", :group_category_name => "Group Category 3") |
| 57 | + |
| 58 | + get "/courses/#{@course.id}/groups" |
| 59 | + |
| 60 | + group_divs = find_all_with_jquery("li.category") |
| 61 | + group_divs.size.should == 3 # three groups, no blank on this one |
| 62 | + |
| 63 | + labels = group_divs.map{ |div| div.find_element(:css, "a").text } |
| 64 | + labels.should be_include("Group Category 1") |
| 65 | + labels.should be_include("Group Category 2") |
| 66 | + labels.should be_include("Group Category 3") |
| 67 | + end |
| 68 | + |
| 69 | + it "should flag li.category for student organized categories with student_organized class" do |
| 70 | + course_with_teacher_logged_in |
| 71 | + |
| 72 | + @course.enroll_student(user_model(:name => "John Doe")) |
| 73 | + @course.enroll_student(user_model(:name => "Jane Doe")) |
| 74 | + @course.enroll_student(user_model(:name => "Spot the Dog")) |
| 75 | + @course.groups.create(:name => "Group 1", :group_category_name => "Student Groups") |
| 76 | + @course.groups.create(:name => "Group 2", :group_category_name => "Student Groups") |
| 77 | + @course.groups.create(:name => "Group 3", :group_category_name => "Other Groups") |
| 78 | + |
| 79 | + get "/courses/#{@course.id}/groups" |
| 80 | + |
| 81 | + find_all_with_jquery("li.category").size.should == 2 |
| 82 | + find_all_with_jquery("li.category.student_organized").size.should == 1 |
| 83 | + find_with_jquery("li.category.student_organized a").text.should == "Student Groups" |
| 84 | + end |
| 85 | + |
| 86 | + context "dragging a user between groups" do |
| 87 | + it "should remove a user from the old group if the category is not student organized" do |
| 88 | + course_with_teacher_logged_in |
| 89 | + |
| 90 | + @course.enroll_student(john = user_model(:name => "John Doe")) |
| 91 | + group1 = @course.groups.create(:name => "Group 1", :group_category_name => "Other Groups") |
| 92 | + group2 = @course.groups.create(:name => "Group 2", :group_category_name => "Other Groups") |
| 93 | + |
| 94 | + get "/courses/#{@course.id}/groups" |
| 95 | + |
| 96 | + category = driver.find_element(:css, ".group_category") |
| 97 | + unassigned_div = category.find_element(:css, ".group_blank") |
| 98 | + group1_div = category.find_element(:css, "#group_#{group1.id}") |
| 99 | + group2_div = category.find_element(:css, "#group_#{group2.id}") |
| 100 | + unassigned_div.find_elements(:css, ".user_id_#{john.id}").should_not be_empty |
| 101 | + |
| 102 | + # from unassigned to group1 |
| 103 | + # drag_and_drop version doesn't work for some reason |
| 104 | + # driver.action.drag_and_drop(john_li, group1_div).perform |
| 105 | + driver.execute_script(<<-SCRIPT) |
| 106 | + window.contextGroups.moveToGroup( |
| 107 | + $('.group_category:visible .group_blank .user_id_#{john.id}'), |
| 108 | + $('#group_#{group1.id}')) |
| 109 | + SCRIPT |
| 110 | + unassigned_div.find_elements(:css, ".user_id_#{john.id}").should be_empty |
| 111 | + group1_div.find_elements(:css, ".user_id_#{john.id}").should_not be_empty |
| 112 | + |
| 113 | + # from group1 to group2 |
| 114 | + # driver.action.drag_and_drop(john_li, group2_div).perform |
| 115 | + driver.execute_script(<<-SCRIPT) |
| 116 | + window.contextGroups.moveToGroup( |
| 117 | + $('#group_#{group1.id} .user_id_#{john.id}'), |
| 118 | + $('#group_#{group2.id}')) |
| 119 | + SCRIPT |
| 120 | + group1_div.find_elements(:css, ".user_id_#{john.id}").should be_empty |
| 121 | + group2_div.find_elements(:css, ".user_id_#{john.id}").should_not be_empty |
| 122 | + |
| 123 | + # from group2 to unassigned |
| 124 | + # driver.action.drag_and_drop(john_li, unassigned_div).perform |
| 125 | + driver.execute_script(<<-SCRIPT) |
| 126 | + window.contextGroups.moveToGroup( |
| 127 | + $('#group_#{group2.id} .user_id_#{john.id}'), |
| 128 | + $('.group_category:visible .group_blank')) |
| 129 | + SCRIPT |
| 130 | + group2_div.find_elements(:css, ".user_id_#{john.id}").should be_empty |
| 131 | + unassigned_div.find_elements(:css, ".user_id_#{john.id}").should_not be_empty |
| 132 | + end |
| 133 | + |
| 134 | + it "should not remove a user from the old group if the category is student organized unless dragging to unassigned" do |
| 135 | + course_with_teacher_logged_in |
| 136 | + |
| 137 | + @course.enroll_student(john = user_model(:name => "John Doe")) |
| 138 | + group1 = @course.groups.create(:name => "Group 1", :group_category_name => "Student Groups") |
| 139 | + group2 = @course.groups.create(:name => "Group 2", :group_category_name => "Student Groups") |
| 140 | + |
| 141 | + get "/courses/#{@course.id}/groups" |
| 142 | + |
| 143 | + category = driver.find_element(:css, ".group_category") |
| 144 | + unassigned_div = category.find_element(:css, ".group_blank") |
| 145 | + group1_div = category.find_element(:css, "#group_#{group1.id}") |
| 146 | + group2_div = category.find_element(:css, "#group_#{group2.id}") |
| 147 | + unassigned_div.find_elements(:css, ".user_id_#{john.id}").should_not be_empty |
| 148 | + |
| 149 | + # from unassigned to group1 |
| 150 | + # drag_and_drop version doesn't work for some reason |
| 151 | + # driver.action.drag_and_drop(john_li, group1_div).perform |
| 152 | + driver.execute_script(<<-SCRIPT) |
| 153 | + window.contextGroups.moveToGroup( |
| 154 | + $('.group_category:visible .group_blank .user_id_#{john.id}'), |
| 155 | + $('#group_#{group1.id}')) |
| 156 | + SCRIPT |
| 157 | + unassigned_div.find_elements(:css, ".user_id_#{john.id}").should_not be_empty |
| 158 | + group1_div.find_elements(:css, ".user_id_#{john.id}").should_not be_empty |
| 159 | + |
| 160 | + # from group1 to group2 |
| 161 | + # driver.action.drag_and_drop(john_li, group2_div).perform |
| 162 | + driver.execute_script(<<-SCRIPT) |
| 163 | + window.contextGroups.moveToGroup( |
| 164 | + $('#group_#{group1.id} .user_id_#{john.id}'), |
| 165 | + $('#group_#{group2.id}')) |
| 166 | + SCRIPT |
| 167 | + group1_div.find_elements(:css, ".user_id_#{john.id}").should_not be_empty |
| 168 | + group2_div.find_elements(:css, ".user_id_#{john.id}").should_not be_empty |
| 169 | + |
| 170 | + # from group2 to unassigned |
| 171 | + # driver.action.drag_and_drop(john_li, unassigned_div).perform |
| 172 | + driver.execute_script(<<-SCRIPT) |
| 173 | + window.contextGroups.moveToGroup( |
| 174 | + $('#group_#{group2.id} .user_id_#{john.id}'), |
| 175 | + $('.group_category:visible .group_blank')) |
| 176 | + SCRIPT |
| 177 | + group2_div.find_elements(:css, ".user_id_#{john.id}").should be_empty |
| 178 | + unassigned_div.find_elements(:css, ".user_id_#{john.id}").should_not be_empty |
| 179 | + end |
| 180 | + end |
| 181 | + |
| 182 | + it "should add new categories at the end of the tabs" do |
| 183 | + course_with_teacher_logged_in |
| 184 | + |
| 185 | + @course.enroll_student(user_model(:name => "John Doe")) |
| 186 | + @course.groups.create(:name => "Group 1", :group_category_name => "Existing Category") |
| 187 | + |
| 188 | + get "/courses/#{@course.id}/groups" |
| 189 | + driver.find_elements(:css, "#category_list li").size.should == 1 |
| 190 | + |
| 191 | + # submit new category form |
| 192 | + driver.find_element(:css, ".add_category_link").click |
| 193 | + form = driver.find_element(:css, "#add_category_form") |
| 194 | + form.find_element(:css, "input[type=text]").clear |
| 195 | + form.find_element(:css, "input[type=text]").send_keys("New Category") |
| 196 | + form.find_element(:css, "#category_no_groups").click |
| 197 | + form.submit |
| 198 | + wait_for_ajax_requests |
| 199 | + |
| 200 | + driver.find_elements(:css, "#category_list li").size.should == 2 |
| 201 | + driver.find_elements(:css, "#category_list li a").last.text.should == "New Category" |
| 202 | + end |
| 203 | + |
| 204 | + it "should keep the student organized category after any new categories" do |
| 205 | + course_with_teacher_logged_in |
| 206 | + |
| 207 | + @course.enroll_student(user_model(:name => "John Doe")) |
| 208 | + @course.groups.create(:name => "Group 1", :group_category_name => "Student Groups") |
| 209 | + |
| 210 | + get "/courses/#{@course.id}/groups" |
| 211 | + driver.find_elements(:css, "#category_list li").size.should == 1 |
| 212 | + |
| 213 | + # submit new category form |
| 214 | + driver.find_element(:css, ".add_category_link").click |
| 215 | + form = driver.find_element(:css, "#add_category_form") |
| 216 | + form.find_element(:css, "input[type=text]").clear |
| 217 | + form.find_element(:css, "input[type=text]").send_keys("New Category") |
| 218 | + form.find_element(:css, "#category_no_groups").click |
| 219 | + form.submit |
| 220 | + wait_for_ajax_requests |
| 221 | + |
| 222 | + driver.find_elements(:css, "#category_list li").size.should == 2 |
| 223 | + driver.find_elements(:css, "#category_list li a").first.text.should == "New Category" |
| 224 | + driver.find_elements(:css, "#category_list li a").last.text.should == "Student Groups" |
| 225 | + end |
| 226 | + |
| 227 | + it "should move students from a deleted group back to unassigned" do |
| 228 | + course_with_teacher_logged_in |
| 229 | + |
| 230 | + @course.enroll_student(john = user_model(:name => "John Doe")) |
| 231 | + group = @course.groups.create(:name => "Group 1", :group_category_name => "Some Category") |
| 232 | + group.add_user(john) |
| 233 | + @course.groups.create(:name => "Group 2", :group_category_name => "Some Category") |
| 234 | + |
| 235 | + get "/courses/#{@course.id}/groups" |
| 236 | + |
| 237 | + category = find_with_jquery(".group_category:visible") |
| 238 | + category.find_elements(:css, ".group_blank .user_id_#{john.id}").should be_empty |
| 239 | + |
| 240 | + group_div = category.find_element(:css, "#group_#{group.id}") |
| 241 | + driver.action.move_to(group_div).perform |
| 242 | + group_div.find_element(:css, ".delete_group_link").click |
| 243 | + confirm_dialog = driver.switch_to.alert |
| 244 | + confirm_dialog.accept |
| 245 | + wait_for_ajaximations |
| 246 | + |
| 247 | + category.find_elements(:css, ".group_blank .user_id_#{john.id}").should_not be_empty |
| 248 | + end |
| 249 | +end |
0 commit comments