diff --git a/spec/factories/user_factory.rb b/spec/factories/user_factory.rb index 4a72a150ce3..9696fd911a5 100644 --- a/spec/factories/user_factory.rb +++ b/spec/factories/user_factory.rb @@ -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) diff --git a/spec/selenium/helpers/quizzes_common.rb b/spec/selenium/helpers/quizzes_common.rb index eb2d8365f46..92ec9a5043e 100644 --- a/spec/selenium/helpers/quizzes_common.rb +++ b/spec/selenium/helpers/quizzes_common.rb @@ -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 diff --git a/spec/selenium/quizzes_term_course_section_hierarchy.rb b/spec/selenium/quizzes_term_course_section_hierarchy.rb new file mode 100644 index 00000000000..97988057067 --- /dev/null +++ b/spec/selenium/quizzes_term_course_section_hierarchy.rb @@ -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 \ No newline at end of file