Skip to content

Commit 3563529

Browse files
committed
remove special group name from manage_groups.js
Change-Id: I3a8e554a4148831550450109bafcc1df674aad70 Reviewed-on: https://gerrit.instructure.com/5763 Tested-by: Hudson <hudson@instructure.com> Reviewed-by: Cody Cutrer <cody@instructure.com>
1 parent 9bcf8d9 commit 3563529

4 files changed

Lines changed: 254 additions & 6 deletions

File tree

app/views/groups/_category.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div id="<%= category ? category.unpack('H*') : "category_template" %>" class="group_category">
1+
<div id="<%= category ? category.unpack('H*') : "category_template" %>" class="group_category <%= 'student_organized' if category == Group.student_organized_category %>">
22
<div class="category_header">
33
<div class="links">
44
<a href="#" class="add_group_link no-hover" title="<%= t 'buttons.add_group', "Add Another Group" %>"><%= image_tag "add.png" %></a>

app/views/groups/context_manage_groups.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ a.load_members_link, .loading_members {
193193
<div id="group_tabs" style="<%= hidden if @categories.empty? %>;">
194194
<ul id="category_list">
195195
<% @categories.each do |category| %>
196-
<li class="category"><a href="#<%= category.unpack('H*') %>"><%= category %></a></li>
196+
<li class="category <%= 'student_organized' if category == Group.student_organized_category %>"><a href="#<%= category.unpack('H*') %>"><%= category %></a></li>
197197
<% end %>
198198
</ul>
199199
<%= render :partial => "category", :collection => @categories %>

public/javascripts/manage_groups.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
I18n.scoped('groups', function(I18n){
2020
window.contextGroups = {
2121
autoLoadGroupThreshold: 15,
22-
studentGroupsCategoryName: $.encodeToHex(I18n.t('category_name', 'Student Groups')),
2322

2423
loadMembersForGroup: function($group) {
2524
var url = $("#manage_group_urls .list_users_url").attr('href');
@@ -127,7 +126,7 @@ I18n.scoped('groups', function(I18n){
127126

128127
var $student_instances = $student;
129128
contextGroups.insertIntoGroup($student, $group);
130-
if(($group.parents(".group_category").attr('id') == contextGroups.studentGroupsCategoryName) &&
129+
if($group.parents(".group_category").hasClass('student_organized') &&
131130
($group.get(0) !== $group.parents(".group_category").find(".group_blank").get(0))) {
132131
var $s = $student.clone();
133132
$student_instances = $student_instances.add($s);
@@ -415,7 +414,7 @@ I18n.scoped('groups', function(I18n){
415414
$category.find(".category_name").text(name);
416415

417416
var newIndex = $("#group_tabs").tabs('length');
418-
if ($("li.category").last().find("a").attr('href') == '#' + contextGroups.studentGroupsCategoryName) {
417+
if ($("li.category").last().hasClass('student_organized')) {
419418
newIndex -= 1;
420419
}
421420
$("#group_tabs").append($category);
@@ -443,7 +442,7 @@ I18n.scoped('groups', function(I18n){
443442
});
444443
$(this).slideUp(function() {
445444
var $category = $(this).parents(".group_category");
446-
if ($category.attr('id') != contextGroups.studentGroupsCategoryName) {
445+
if (!$category.hasClass('student_organized')) {
447446
$(this).find(".student").each(function() {
448447
contextGroups.insertIntoGroup($(this), $blank_category);
449448
});

spec/selenium/manage_groups_sel.rb

Lines changed: 249 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,249 @@
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

Comments
 (0)