Skip to content

Commit 191526c

Browse files
Chris WangDavis Lynn McClellan
authored andcommitted
add filter for users on quiz moderation
closes CNVS-3080 test plan: - Course with at least two students and a quiz - Go to moderation page - input somthing into the filter - ensure that filters correctly Change-Id: Ia893d7b26c63e3596e9a1d42c33a75972574d467 Reviewed-on: https://gerrit.instructure.com/85870 Tested-by: Jenkins Reviewed-by: Ryan Taylor <rtaylor@instructure.com> QA-Review: Robin Kuss <rkuss@instructure.com> Product-Review: Jason Sparks <jsparks@instructure.com>
1 parent 5271f3f commit 191526c

4 files changed

Lines changed: 83 additions & 1 deletion

File tree

app/controllers/quizzes/quizzes_controller.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,9 @@ def history
644644

645645
def moderate
646646
if authorized_action(@quiz, @current_user, :grade)
647-
@students = @context.students_visible_to(@current_user, include: :inactive).uniq.order_by_sortable_name
647+
@students = @context.students_visible_to(@current_user, include: :inactive)
648+
@students = @students.name_like(params[:search_term]) if params[:search_term].present?
649+
@students = @students.uniq.order_by_sortable_name
648650
@students = @students.order(:uuid) if @quiz.survey? && @quiz.anonymous_submissions
649651
last_updated_at = Time.parse(params[:last_updated_at]) rescue nil
650652
respond_to do |format|

app/views/quizzes/quizzes/moderate.html.erb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@
1212
<div class="moderate_header">
1313
<h1><%= t(:page_title, "Moderate Quiz") %></h1>
1414
</div>
15+
<%= form_tag(context_url(@context, :context_quiz_moderate_url, @quiz.id), method: :get) do %>
16+
<div class="ic-Form-control">
17+
<div class="ic-Input-group">
18+
<%= text_field_tag :search_term, params[:search_term], class: "ic-Input", placeholder: t('Search People'),
19+
aria_label: t('Search people. As you type in this field, the list of people will be automatically filtered to only include those whose names match your input.') %>
20+
<%= submit_tag t('Filter'), class: "Button" %>
21+
</div>
22+
</div>
23+
<% end %>
1524
<table id="students" class="table table-striped <%= 'can_add_attempts' if @quiz.allowed_attempts < 0 %>">
1625
<thead>
1726
<tr>

spec/controllers/quizzes/quizzes_controller_spec.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,29 @@ def logged_out_survey_with_submission(user, questions, &block)
485485
assert_unauthorized
486486
end
487487

488+
context 'student_filters' do
489+
before do
490+
user_session(@teacher)
491+
5.times.map do |i|
492+
name = "#{(i + 'a'.ord).chr}_student"
493+
course_with_student(name: name, course: @course)
494+
@student
495+
end
496+
end
497+
498+
it "should sort students" do
499+
get 'moderate', :course_id => @course.id, :quiz_id => @quiz.id
500+
expect(assigns[:students] - assigns[:students].sort_by(&:sortable_name)).to eq []
501+
end
502+
503+
it "should filter students" do
504+
get 'moderate', :course_id => @course.id, :quiz_id => @quiz.id, :search_term => 'a'
505+
506+
expect(assigns[:students].count).to eq 1
507+
expect(assigns[:students].first.sortable_name).to eq 'a_student'
508+
end
509+
end
510+
488511
it "should assign variables" do
489512
user_session(@teacher)
490513
sub = @quiz.generate_submission(@student)
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#
2+
# Copyright (C) 2011 Instructure, Inc.
3+
#
4+
# This file is part of Canvas.
5+
#
6+
# Canvas is free software: you can redistribute it and/or modify it under
7+
# the terms of the GNU Affero General Public License as published by the Free
8+
# Software Foundation, version 3 of the License.
9+
#
10+
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
11+
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12+
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
13+
# details.
14+
#
15+
# You should have received a copy of the GNU Affero General Public License along
16+
# with this program. If not, see <http://www.gnu.org/licenses/>.
17+
#
18+
19+
require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
20+
require File.expand_path(File.dirname(__FILE__) + '/../../views_helper')
21+
22+
describe "/quizzes/quizzes/moderate" do
23+
let(:num_students) { 5 }
24+
25+
before do
26+
course_with_teacher
27+
@students = num_students.times.map do |i|
28+
name = "#{(i + 'a'.ord).chr}_student"
29+
course_with_student(name: name, course: @course)
30+
@student
31+
end
32+
course_quiz
33+
view_context
34+
assigns[:students] = @students.paginate
35+
assigns[:quiz] = @quiz
36+
assigns[:submissions] = []
37+
end
38+
39+
it "should render" do
40+
render "quizzes/quizzes/moderate"
41+
expect(response).not_to be_nil
42+
end
43+
44+
it "should have filter options" do
45+
render "quizzes/quizzes/moderate"
46+
expect(response.inspect).to include 'Search people. As you type in this field, the list of people will be automatically filtered to only include those whose names match your input.'
47+
end
48+
end

0 commit comments

Comments
 (0)