<commit_before># frozen_string_literal: true

#
# Copyright (C) 2018 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.

require_relative "../../common"
require_relative "../../helpers/speed_grader_common"
require_relative "../pages/moderate_page"
require_relative "../pages/speedgrader_page"

describe "SpeedGrader" do
  include_context "in-process server selenium tests"
  include SpeedGraderCommon

  before(:once) do
    # a course with 1 teacher
    @teacher1 = course_with_teacher(name: "Teacher1", active_all: true).user
    @teacher2 = course_with_teacher(course: @course, name: "Teacher2", active_all: true).user
    @teacher3 = course_with_teacher(course: @course, name: "Teacher3", active_all: true).user

    # enroll two students
    @student1 = User.create!(name: "<NAME>")
    @student1.register!
    @course.enroll_student(@student1, enrollment_state: "active")

    @student2 = User.create!(name: "<NAME>")
    @student2.register!
    @course.enroll_student(@student2, enrollment_state: "active")
  end

  context "with an anonymous assignment" do
    before do
      # an anonymous assignment
      @assignment = @course.assignments.create!(
        name: "anonymous assignment",
        points_possible: 10,
        submission_types: "online_text_entry,online_upload",
        anonymous_grading: true
      )

      # Student1 & Student2 submit homework and a comment
      file_attachment = attachment_model(content_type: "application/pdf", context: @student1)
      @submission1 = @assignment.submit_homework(@student1,
                                                 submission_type: "online_upload",
                                                 attachments: [file_attachment],
                                                 comment: "This is Student One's comment")

      file_attachment = attachment_model(content_type: "application/pdf", context: @student2)
      @submission1 = @assignment.submit_homework(@student2,
                                                 submission_type: "online_upload",
                                                 attachments: [file_attachment],
                                                 comment: "This is Student Two's comment")
      user_session(@teacher)
      Speedgrader.visit(@course.id, @assignment.id)
    end

    it "student names are anonymous", priority: "1" do
      Speedgrader.students_dropdown_button.click
      student_names = Speedgrader.students_select_menu_list.map(&:text)
      expect(student_names).to match_array ["Student 1", "Student 2"]
    end

    context "given a specific student" do
      before do
        Speedgrader.click_next_or_prev_student(:next)
        Speedgrader.students_dropdown_button.click
        @current_student = Speedgrader.selected_student
      end

      it "when their submission is selected and page reloaded", priority: "1" do
        expect { refresh_page }.not_to change { Speedgrader.selected_student.text }.from("Student 2")
      end
    end

    context "given student comment and file submission" do
      it "author of comment is anonymous", priority: 2 do
        expect(Speedgrader.comment_citation.first.text).not_to match(/(First|Second) Student/)
        expect(Speedgrader.comment_citation.first.text).to match(/Student (1|2)/)
      end<commit_msg>skip flaky speedgrader reload spec<commit_after># frozen_string_literal: true

#
# Copyright (C) 2018 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.

require_relative "../../common"
require_relative "../../helpers/speed_grader_common"
require_relative "../pages/moderate_page"
require_relative "../pages/speedgrader_page"

describe "SpeedGrader" do
  include_context "in-process server selenium tests"
  include SpeedGraderCommon

  before(:once) do
    # a course with 1 teacher
    @teacher1 = course_with_teacher(name: "Teacher1", active_all: true).user
    @teacher2 = course_with_teacher(course: @course, name: "Teacher2", active_all: true).user
    @teacher3 = course_with_teacher(course: @course, name: "Teacher3", active_all: true).user

    # enroll two students
    @student1 = User.create!(name: "<NAME>")
    @student1.register!
    @course.enroll_student(@student1, enrollment_state: "active")

    @student2 = User.create!(name: "<NAME>")
    @student2.register!
    @course.enroll_student(@student2, enrollment_state: "active")
  end

  context "with an anonymous assignment" do
    before do
      # an anonymous assignment
      @assignment = @course.assignments.create!(
        name: "anonymous assignment",
        points_possible: 10,
        submission_types: "online_text_entry,online_upload",
        anonymous_grading: true
      )

      # Student1 & Student2 submit homework and a comment
      file_attachment = attachment_model(content_type: "application/pdf", context: @student1)
      @submission1 = @assignment.submit_homework(@student1,
                                                 submission_type: "online_upload",
                                                 attachments: [file_attachment],
                                                 comment: "This is Student One's comment")

      file_attachment = attachment_model(content_type: "application/pdf", context: @student2)
      @submission1 = @assignment.submit_homework(@student2,
                                                 submission_type: "online_upload",
                                                 attachments: [file_attachment],
                                                 comment: "This is Student Two's comment")
      user_session(@teacher)
      Speedgrader.visit(@course.id, @assignment.id)
    end

    it "student names are anonymous", priority: "1" do
      Speedgrader.students_dropdown_button.click
      student_names = Speedgrader.students_select_menu_list.map(&:text)
      expect(student_names).to match_array ["Student 1", "Student 2"]
    end

    context "given a specific student" do
      before do
        Speedgrader.click_next_or_prev_student(:next)
        Speedgrader.students_dropdown_button.click
        @current_student = Speedgrader.selected_student
      end

      it "when their submission is selected and page reloaded", priority: "1" do
        skip "EVAL-2497 (6/10/22)"

        expect { refresh_page }.not_to change { Speedgrader.selected_student.text }.from("Student 2")
      end
    end

    context "given student comment and file submission" do
      it "author of comment is anonymous", priority: 2 do
        expect(Speedgrader.comment_citation.first.text).not_to match(/(First|Second) Student/)
        expect(Speedgrader.comment_citation.first.text).to match(/Student (1|2)/)
      end
{'fraction_non_alphanumeric': 0.08991479079231846, 'fraction_numerical': 0.01030141167493323, 'mean_word_length': 2.851126346718903, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 24, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1922083', 'n_tokens_mistral': 2138, 'n_tokens_neox': 2061, 'n_words': 630}