Quizzes term-course-section hierarchy

Written a bunch of specs to regression test the quizzes functionality
for various hierarchy levels

dsoundarrajan, panda, 12

Change-Id: I6e95b0c1f262488d164101db42aaba4f958e2274
Reviewed-on: https://gerrit.instructure.com/61987
Reviewed-by: Derek Hansen <dhansen@instructure.com>
Tested-by: Jenkins
Product-Review: Derek Hansen <dhansen@instructure.com>
QA-Review: Derek Hansen <dhansen@instructure.com>
This commit is contained in:
Deepeeca Soundarrajan 2015-08-27 15:46:15 -06:00 committed by Derek Hansen
parent e8df260562
commit 5c33b035ad
3 changed files with 212 additions and 0 deletions

View File

@ -104,6 +104,15 @@ def ta_in_section(section, opts={})
ta
end
def teacher_in_section(section, opts={})
teacher = opts.fetch(:user) { user }
enrollment = section.course.enroll_user(teacher, 'TeacherEnrollment', :section => section, :force_update => true)
teacher.save!
enrollment.workflow_state = 'active'
enrollment.save!
teacher
end
def teacher_in_course(opts={})
opts[:course] = @course if @course && !opts[:course]
course_with_teacher(opts)

View File

@ -98,6 +98,32 @@ require_relative "../common"
expect(f(".points_possible").text).to eq @points_total.to_s
end
def quiz_with_multiple_type_questions(goto_edit=true)
@context = @course
bank = @course.assessment_question_banks.create!(:title => 'Test Bank')
@q = quiz_model
a = bank.assessment_questions.create!
b = bank.assessment_questions.create!
c = bank.assessment_questions.create!
answers = [ {'id' => 1}, {'id' => 2}, {'id' => 3} ]
@quest1 = @q.quiz_questions.create!(question_data:
{name: "first question", question_type: 'multiple_choice_question',
'answers' => answers, points_possible: 1}, assessment_question: a)
@quest2 = @q.quiz_questions.create!(question_data:
{name: "second question", question_text: 'What is 5+5?',
question_type: 'numerical_question',
'answers' => [], points_possible: 1}, assessment_question: b)
@quest3 = @q.quiz_questions.create!(question_data:
{name: "third question", question_type: 'essay_question',
'answers' => [], points_possible: 1}, assessment_question: c)
yield bank, @q if block_given?
@q.generate_quiz_data
@q.save!
get "/courses/#{@course.id}/quizzes/#{@q.id}/edit" if goto_edit
@q
end
def quiz_with_new_questions(goto_edit=true)
@context = @course
bank = @course.assessment_question_banks.create!(:title => 'Test Bank')
@ -220,7 +246,29 @@ require_relative "../common"
if submit
driver.execute_script("$('#submit_quiz_form .btn-primary').click()")
keep_trying_until do
expect(f('.quiz-submission .quiz_score .score_value')).to be_displayed
end
end
end
def answer_questions_and_submit(quiz, num_questions, submit = true)
num_questions.times do |o|
question = quiz.stored_questions[o][:id]
case quiz.stored_questions[o][:question_type]
when "multiple_choice_question"
fj("input[type=radio][name= 'question_#{question}']").click
wait_for_js
when "essay_question"
type_in_tiny ".question:visible textarea[name = 'question_#{question}']", 'This is an essay question.'
when "numerical_question"
fj("input[type=text][name= 'question_#{question}']").send_keys('10')
wait_for_js
end
end
if submit
expect_new_page_load { f('#submit_quiz_button').click }
keep_trying_until do
expect(f('.quiz-submission .quiz_score .score_value')).to be_displayed
end

View File

@ -0,0 +1,155 @@
require File.expand_path(File.dirname(__FILE__) + '/helpers/quizzes_common')
require File.expand_path(File.dirname(__FILE__) + '/helpers/assignment_overrides.rb')
describe "quizzes section hierarchy" do
include_examples 'in-process server selenium tests'
before :each do
course_with_teacher_logged_in
@new_section = @course.course_sections.create!(name: 'New Section')
@student = student_in_section(@new_section)
@course.start_at = Time.zone.now.advance(days: -30)
@course.conclude_at = Time.zone.now.advance(days: -10)
@course.restrict_enrollments_to_course_dates = true
@course.save!
@new_section.start_at = Time.zone.now.advance(days: -30)
@new_section.end_at = Time.zone.now.advance(days: 10)
@new_section.restrict_enrollments_to_section_dates = true
@new_section.save!
# create a quiz and assign it to the section with due dae after course end date
@quiz = quiz_with_multiple_type_questions(!:goto_edit)
@override = @quiz.assignment_overrides.build
@override.set = @new_section
@override.due_at = Time.zone.now.advance(days:3)
@override.due_at_overridden = true
@override.save!
end
def take_quiz
get "/courses/#{@course.id}/quizzes/#{@quiz.id}"
expect_new_page_load{f('#take_quiz_link').click}
# make sure it does not create a blank submissions
expect(f(' .quiz_score')).not_to be_present
expect(f(' .quiz_duration')).not_to be_present
# take and submit the quiz
answer_questions_and_submit(@quiz, 3)
end
def verify_quiz_accessible
get "/courses/#{@course.id}/quizzes/#{@quiz.id}"
expect_new_page_load{f('#take_quiz_link').click}
# make sure it does not create a blank submissions
expect(f(' .quiz_score')).not_to be_present
expect(f(' .quiz_duration')).not_to be_present
end
context "section overrides course and term hierarchy" do
context "course end date in past" do
it "should allow the student to take the quiz", priority: "1", test_id: 282619 do
# ensure student is able to take the quiz and it does not create a blank submission
user_session(@student)
take_quiz
end
it "should allow the teacher to preview the quiz", priority: "1", test_id: 282838 do
get "/courses/#{@course.id}/quizzes"
keep_trying_until { fln('Test Quiz').click }
expect_new_page_load{f('#preview_quiz_button').click}
keep_trying_until do
expect(f(' .quiz-header').text).to include('This is a preview of the published version of the quiz')
end
end
it "should work with lock and unlock dates set up", priority: "1", test_id: 323086 do
@override.unlock_at = Time.zone.now.advance(days:-1)
@override.lock_at = Time.zone.now.advance(days:4)
user_session(@student)
take_quiz
end
end
context "term end date in past" do
before :each do
term = EnrollmentTerm.find(@course.enrollment_term_id)
term.start_at = Time.zone.now.advance(days: -60)
term.end_at = Time.zone.now.advance(days: -15)
term.save!
end
it "should still be accessible for student in the section after term end date", priority: "1", test_id: 323087 do
user_session(@student)
take_quiz
end
it "should be accessible for teachers enrolled in section after term end date", priority: "1", test_id: 323089 do
teacher_in_section(@new_section, user: @teacher)
take_quiz
end
it "should work with lock and unlock dates set up", priority: "1", test_id: 323090 do
@override.unlock_at = Time.zone.now.advance(days:-1)
@override.lock_at = Time.zone.now.advance(days:4)
user_session(@student)
take_quiz
end
end
end
context "course overrides hierarchy when restrict to section dates is not checked" do
before :each do
@new_section.restrict_enrollments_to_section_dates = false
@new_section.save!
end
context "course ends in past" do
it "should disallow student to view quiz", priority: "1", test_id: 323323 do
user_session(@student)
get "/courses/#{@course.id}/quizzes/#{@quiz.id}"
expect(f('#quiz_show .quiz-header .lock_explanation').text).
to include('This quiz is no longer available as the course has been concluded')
end
it "should still allow teachers to take the quiz", priority: "1", test_id: 323324 do
verify_quiz_accessible
end
end
context "course ends in future" do
before :each do
@course.conclude_at = Time.zone.now.advance(days: 10)
@course.save!
end
it "should allow student in section to take quiz", priority: "1", test_id: 323321 do
user_session(@student)
verify_quiz_accessible
end
it "should allow teachers to take the quiz", priority: "1", test_id: 323322 do
verify_quiz_accessible
end
end
end
context "term overrides hierarchy when restrict to course and section dates are not checked" do
context "course ends in past" do
before :each do
@course.restrict_enrollments_to_course_dates = false
@course.save!
@new_section.restrict_enrollments_to_section_dates = false
@new_section.save!
end
it "should allow student to take quiz", priority: "1", test_id: 323326 do
user_session(@student)
verify_quiz_accessible
end
it "should still allow teachers to take the quiz", priority: "1", test_id: 323328 do
verify_quiz_accessible
end
end
end
end