<commit_before>require File.expand_path(File.dirname(__FILE__) + "/common")

describe "gradebook2 selenium tests" do
  it_should_behave_like "in-process server selenium tests"

  ASSIGNMENT_1_POINTS = "10"
  ASSIGNMENT_2_POINTS = "5"
  ASSIGNMENT_3_POINTS = "50"
  ATTENDANCE_POINTS = "15"


  STUDENT_NAME_1 = "<EMAIL>"
  STUDENT_NAME_2 = "<EMAIL>"
  STUDENT_1_TOTAL_IGNORING_UNGRADED = "100%"
  STUDENT_2_TOTAL_IGNORING_UNGRADED = "66.7%"
  STUDENT_1_TOTAL_TREATING_UNGRADED_AS_ZEROS = "18.8%"
  STUDENT_2_TOTAL_TREATING_UNGRADED_AS_ZEROS = "12.5%"
  DEFAULT_PASSWORD = "<PASSWORD>"

  def find_slick_cells(row_index, element)
    grid = element
    rows = grid.find_elements(:css, '.slick-row')
    row_cells = rows[row_index].find_elements(:css, '.slick-cell')
    row_cells
  end

  def edit_grade(cell, grade)
    grade_input = keep_trying_until do
      cell.click
      cell.find_element(:css, '.grade')
    end
    grade_input.clear
    grade_input.send_keys(grade)
    grade_input.send_keys(:return)
    wait_for_ajax_requests
  end

  def validate_cell_text(cell, text)
    cell.text.should == text
    cell.text
  end

  def open_gradebook_settings(element_to_click = nil)
    driver.find_element(:css, '#gradebook_settings').click
    driver.find_element(:css, '#ui-menu-0').should be_displayed
    element_to_click.click if element_to_click != nil
  end

  def open_comment_dialog
    #move_to occasionally breaks in the hudson build
    cell = driver.execute_script "return $('#gradebook_grid .slick-row:first .slick-cell:first').addClass('hover')[0]"
    cell.find_element(:css, '.gradebook-cell-comment').click
    # the dialog fetches the comments async after it displays and then innerHTMLs the whole
    # thing again once it has fetched them from the server, completely replacing it
    wait_for_ajax_requests
    find_with_jquery '.submission_details_dialog:visible'
  end

  def open_assignment_options(cell_index)
    assignment_cell = driver.find_elements(:css, '.slick-column-name')[cell_index]
    driver.action.move_to(assignment_cell).perform
    assignment_cell.find_element(:css, '.gradebook-header-drop').click
    driver.find_element(:css, '#ui-menu-1').should be_displayed
  end

  def final_score_for_row(row)
    grade_grid = driver.find_element(:css, '#gradebook_grid')
    cells = find_slick_cells(row, grade_grid)
    cells[4].text
  end

  # `students` should be a hash of student_id, expected total pairs, like:
  # {
  #   1 => '12%',
  #   3 => '86.7%',
  # }
  def check_gradebook_1_totals(students)
    get "/courses/#{@course.id}/gradebook"
    # this keep_trying_untill is there because gradebook1 loads it's cells in a bunch of setTimeouts
    keep_trying_until {
      students.each do |student_id, expected_score|
        row_total = driver.find_element(:css, ".final_grade .student_#{student_id}").text
        # gradebook1 has a space between number and % like: "33.3 %"
        row_total = row_total.sub ' ', ''
        row_total.should eql expected_score
      end
    }
  end

  before(:each) do
    course_with_teacher_logged_in

    #add first student
    @student_1 = User.create!(:name => STUDENT_NAME_1)
    @student_1.register!
    @student_1.pseudonyms.create!(:unique_id => STUDENT_NAME_1, :password => <PASSWORD>, :password_confirmation => <PASSWORD>)

    e1 = @course.enroll_student(@student_1)
    e1.workflow_state = 'active'
    e1.save!
    @course.reload
    #add second student
    @other_section = @course.course_sections.create(:name => "the other section")
    @student_2 = User.create!(:name => STUDENT_NAME_2)
    @student_2.register!
    @student_2.pseudonyms.create!(:unique_id => STUDENT_NAME_2, :password => <PASSWORD>, :password_confirmation => <PASSWORD>)
    e2 = @course.enroll_student(@student_2, :section => @other_section)

    e2.workflow_state = 'active'
    e2.save!
    @course.reload

    #first assignment data
    @group = @course.assignment_groups.create!(:name => 'first assignment group')
    @assignment = assignment_model({
                                       :course => @course,
                                       :name => 'first assignment',
                                       :due_at => nil,
                                       :points_possible => ASSIGNMENT_1_POINTS,
                                       :submission_types => 'online_text_entry',
                                       :assignment_group => @group
                                   })
    rubric_model
    @association = @rubric.associate_with(@assignment, @course, :purpose => 'grading')
    @assignment.reload
    @submission = @assignment.submit_homework(@student_1, :body => 'student 1 submission assignment 1')
    @assignment.grade_student(@student_1, :grade => 10)
    @submission.score = 10
    @submission.save!

    #second student submission for assignment 1
    @student_2_submission = @assignment.submit_homework(@student_2, :body => 'student 2 submission assignment 1')
    @assignment.grade_student(@student_2, :grade => 5)
    @student_2_submission.score = 5
    @submission.save!

    #second assignment data
    @second_assignment = assignment_model({
                                              :course => @course,
                                              :name => 'second assignment',
                                              :due_at => nil,
                                              :points_possible => ASSIGNMENT_2_POINTS,
                                              :submission_types => 'online_text_entry',
                                              :assignment_group => @group
                                          })
    @second_association = @rubric.associate_with(@second_assignment, @course, :purpose => 'grading')

    #student 1 submission for assignment 2
    @second_submission = @second_assignment.submit_homework(@student_1, :body => 'student 1 submission assignment 2')
    @second_assignment.grade_student(@student_1, :grade => 5)
    @second_submission.save!

    #student 2 submission for assignment 2
    @second_submission = @second_assignment.submit_homework(@student_2, :body => 'student 2 submission assignment 2')
    @second_assignment.grade_student(@student_2, :grade => 5)
    @second_submission.save!

    #third assignment data
    due_date = Time.now + 1.days
    @third_assignment = assignment_model({
                                             :course => @course,
                                             :name => 'assignment three',
                                             :due_at => due_date,
                                             :points_possible => ASSIGNMENT_3_POINTS,
                                             :submission_types => 'online_text_entry',
                                             :assignment_group => @group
                                         })
    @third_association = @rubric.associate_with(@third_assignment, @course, :purpose => 'grading')

    #attendance assignment
    @attendance_assignment = assignment_model({
                                                  :course => @course,
                                                  :name => 'attendance assignment',
                                                  :title => 'attendance assignment',
                                                  :due_at => nil,
                                                  :points_possible => ATTENDANCE_POINTS,
                                                  :submission_types => 'attendance',
                                                  :assignment_group => @group,
                                              })

    @ungraded_assignment = @course.assignments.create! :title => 'not-graded assignment',
                                                       :submission_types => 'not_graded'

    get "/courses/#{@course.id}/gradebook2"
    wait_for_ajaximations
  end

  it "should not show 'not-graded' assignments" do
    driver.find_element(:css, '#gradebook_grid .slick-header').should_not include_text(@ungraded_assignment.title)
  end

  it "should validate correct number of students showing up in gradebook" do
    driver.find_elements(:css, '.student-name').count.should == @course.students.count
  end

  it "should allow showing only a certain section" do
    button = driver.find_element(:id, 'section_to_show')
    button.should include_text "All Sections"
    button.click
    sleep 1 #TODO find a better way to wait for css3 anmation to end
    driver.find_element(:id, 'section-to-show-menu').should be_displayed
    driver.find_element(:css, "label[for='section_option_#{@other_section.id}']").click
    button.should include_text @other_section.name

    # verify that it remembers the section to show across page loads
    get "/courses/#{@course.id}/gradebook2"
    wait_for_ajaximations
    button = driver.find_element(:id, 'section_to_show')
    button.should include_text @other_section.name

    # now verify that you can set it back
    button.click
    sleep 1 #TODO find a better way to wait for css3 anmation to end
    driver.find_element(:id, 'section-to-show-menu').should be_displayed
    driver.find_element(:css, "label[for='section_option_']").click
    button.should include_text "All Sections"
  end

  it "should validate initial grade totals are correct" do
    final_score_for_row(0).should eql STUDENT_1_TOTAL_IGNORING_UNGRADED
    final_score_for_row(1).should eql STUDENT_2_TOTAL_IGNORING_UNGRADED
  end

  it "should treat ungraded as 0's when asked, and ignore when not" do
    # make sure it shows like it is not treating ungraded as 0's by default
    is_checked('#include_ungraded_assignments').should be_false
    final_score_for_row(0).should eql STUDENT_1_TOTAL_IGNORING_UNGRADED
    final_score_for_row(1).should eql STUDENT_2_TOTAL_IGNORING_UNGRADED

    # set the "treat ungraded as 0's" option in the header
    open_gradebook_settings(driver.find_element(:css, 'label[for="include_ungraded_assignments"]'))

    # now make sure that the grades show as if those ungraded assignments had a '0'
    is_checked('#include_ungraded_assignments').should be_true
    final_score_for_row(0).should eql STUDENT_1_TOTAL_TREATING_UNGRADED_AS_ZEROS
    final_score_for_row(1).should eql STUDENT_2_TOTAL_TREATING_UNGRADED_AS_ZEROS

    # reload the page and make sure it remembered the setting
    get "/courses/#{@course.id}/gradebook2"
    wait_for_ajaximations
    is_checked('#include_ungraded_assignments').should be_true
    final_score_for_row(0).should eql STUDENT_1_TOTAL_TREATING_UNGRADED_AS_ZEROS
    final_score_for_row(1).should eql STUDENT_2_TOTAL_TREATING_UNGRADED_AS_ZEROS

    # NOTE: gradebook1 does not handle 'remembering' the `include_ungraded_assignments` setting

    # clear our saved settings
    driver.execute_script '$.store.clear();'
  end

  it "should change grades and validate course total is correct" do
    expected_edited_total = "33.3%"

    #editing grade for first row, first cell
    edit_grade(driver.find_element(:css, '#gradebook_grid [row="0"] .l0'), 0)

    #editing grade for second row, first cell
    edit_grade(driver.find_element(:css, '#gradebook_grid [row="1"] .l0'), 0)

    #refresh page and make sure the grade sticks
    get "/courses/#{@course.id}/gradebook2"
    wait_for_ajaximations
    final_score_for_row(0).should eql expected_edited_total
    final_score_for_row(1).should eql expected_edited_total

    #go back to gradebook1 and compare to make sure they match
    check_gradebook_1_totals({
      @student_1.id => expected_edited_total,
      @student_2.id => expected_edited_total
    })
  end

  it "should validate that gradebook settings is displayed when button is clicked" do
    open_gradebook_settings
  end

  it "should validate row sorting works when first column is clicked" do
    first_column = driver.find_elements(:css, '.slick-column-name')[0]
    2.times do
      first_column.click
    end
    meta_cells = find_slick_cells(0, driver.find_element(:css, '.grid-canvas'))
    grade_cells = find_slick_cells(0, driver.find_element(:css, '#gradebook_grid'))

    #filter validation
    validate_cell_text(meta_cells[0], STUDENT_NAME_2 + "\n" + @other_section.name)
    validate_cell_text(grade_cells[0], ASSIGNMENT_2_POINTS)
    validate_cell_text(grade_cells[4], STUDENT_2_TOTAL_IGNORING_UNGRADED)
  end

  it "should validate setting group weights" do
    weight_num = 50.0

    driver.find_element(:id, 'gradebook_settings').click
    wait_for_animations
    driver.find_element(:css, '[aria-controls="assignment_group_weights_dialog"]').click

    dialog = driver.find_element(:id, 'assignment_group_weights_dialog')
    dialog.should be_displayed

    dialog.find_element(:css, '#group_weighting_scheme').click
    set_value(dialog.find_element(:css, '.group_weight'), weight_num)

    save_button = find_with_jquery('.ui-dialog-buttonset .ui-button:contains("Save")')
    save_button.click
    wait_for_ajax_requests
    @course.reload.group_weighting_scheme.should == 'percent'
    @group.reload.group_weight.should eql(weight_num)

    # TODO: make the header cell in the UI update to reflect new value
    # heading = find_with_jquery(".slick-column-name:contains('#{@group.name}') .assignment-points-possible")
    # heading.should include_text("#{weight_num}% of grade")
  end

  it "should validate arrange columns by due date option" do
    expected_text = "-"

    open_gradebook_settings(driver.find_element(:css, '#ui-menu-0-4'))
    first_row_cells = find_slick_cells(0, driver.find_element(:css, '#gradebook_grid'))
    validate_cell_text(first_row_cells[0], expected_text)
  end

  it "should validate arrange columns by assignment group option" do
    open_gradebook_settings(driver.find_element(:css, '#ui-menu-0-4'))
    open_gradebook_settings(driver.find_element(:css, '#ui-menu-0-5'))
    first_row_cells = find_slick_cells(0, driver.find_element(:css, '#gradebook_grid'))
    validate_cell_text(first_row_cells[0], ASSIGNMENT_1_POINTS)
  end

  it "should validate show attendance columns option" do
    open_gradebook_settings(driver.find_element(:css, '#ui-menu-0-6'))
    headers = driver.find_elements(:css, '.slick-header')
    headers[1].should include_text(@attendance_assignment.title)
    open_gradebook_settings(driver.find_element(:css, '#ui-menu-0-6'))
  end

  it "should validate posting a comment to a graded assignment" do
    comment_text = "This is a new comment!"

    dialog = open_comment_dialog
    set_value(dialog.find_element(:id, "add_a_comment"), comment_text)
    driver.find_element(:css, "form.submission_details_add_comment_form.clearfix > button.button").click<commit_msg>flag selenium gradebook2 comment spec as pending<commit_after>require File.expand_path(File.dirname(__FILE__) + "/common")

describe "gradebook2 selenium tests" do
  it_should_behave_like "in-process server selenium tests"

  ASSIGNMENT_1_POINTS = "10"
  ASSIGNMENT_2_POINTS = "5"
  ASSIGNMENT_3_POINTS = "50"
  ATTENDANCE_POINTS = "15"


  STUDENT_NAME_1 = "<EMAIL>"
  STUDENT_NAME_2 = "<EMAIL>"
  STUDENT_1_TOTAL_IGNORING_UNGRADED = "100%"
  STUDENT_2_TOTAL_IGNORING_UNGRADED = "66.7%"
  STUDENT_1_TOTAL_TREATING_UNGRADED_AS_ZEROS = "18.8%"
  STUDENT_2_TOTAL_TREATING_UNGRADED_AS_ZEROS = "12.5%"
  DEFAULT_PASSWORD = "<PASSWORD>"

  def find_slick_cells(row_index, element)
    grid = element
    rows = grid.find_elements(:css, '.slick-row')
    row_cells = rows[row_index].find_elements(:css, '.slick-cell')
    row_cells
  end

  def edit_grade(cell, grade)
    grade_input = keep_trying_until do
      cell.click
      cell.find_element(:css, '.grade')
    end
    grade_input.clear
    grade_input.send_keys(grade)
    grade_input.send_keys(:return)
    wait_for_ajax_requests
  end

  def validate_cell_text(cell, text)
    cell.text.should == text
    cell.text
  end

  def open_gradebook_settings(element_to_click = nil)
    driver.find_element(:css, '#gradebook_settings').click
    driver.find_element(:css, '#ui-menu-0').should be_displayed
    element_to_click.click if element_to_click != nil
  end

  def open_comment_dialog
    #move_to occasionally breaks in the hudson build
    cell = driver.execute_script "return $('#gradebook_grid .slick-row:first .slick-cell:first').addClass('hover')[0]"
    cell.find_element(:css, '.gradebook-cell-comment').click
    # the dialog fetches the comments async after it displays and then innerHTMLs the whole
    # thing again once it has fetched them from the server, completely replacing it
    wait_for_ajax_requests
    find_with_jquery '.submission_details_dialog:visible'
  end

  def open_assignment_options(cell_index)
    assignment_cell = driver.find_elements(:css, '.slick-column-name')[cell_index]
    driver.action.move_to(assignment_cell).perform
    assignment_cell.find_element(:css, '.gradebook-header-drop').click
    driver.find_element(:css, '#ui-menu-1').should be_displayed
  end

  def final_score_for_row(row)
    grade_grid = driver.find_element(:css, '#gradebook_grid')
    cells = find_slick_cells(row, grade_grid)
    cells[4].text
  end

  # `students` should be a hash of student_id, expected total pairs, like:
  # {
  #   1 => '12%',
  #   3 => '86.7%',
  # }
  def check_gradebook_1_totals(students)
    get "/courses/#{@course.id}/gradebook"
    # this keep_trying_untill is there because gradebook1 loads it's cells in a bunch of setTimeouts
    keep_trying_until {
      students.each do |student_id, expected_score|
        row_total = driver.find_element(:css, ".final_grade .student_#{student_id}").text
        # gradebook1 has a space between number and % like: "33.3 %"
        row_total = row_total.sub ' ', ''
        row_total.should eql expected_score
      end
    }
  end

  before(:each) do
    course_with_teacher_logged_in

    #add first student
    @student_1 = User.create!(:name => STUDENT_NAME_1)
    @student_1.register!
    @student_1.pseudonyms.create!(:unique_id => STUDENT_NAME_1, :password => <PASSWORD>, :password_confirmation => <PASSWORD>)

    e1 = @course.enroll_student(@student_1)
    e1.workflow_state = 'active'
    e1.save!
    @course.reload
    #add second student
    @other_section = @course.course_sections.create(:name => "the other section")
    @student_2 = User.create!(:name => STUDENT_NAME_2)
    @student_2.register!
    @student_2.pseudonyms.create!(:unique_id => STUDENT_NAME_2, :password => <PASSWORD>, :password_confirmation => <PASSWORD>)
    e2 = @course.enroll_student(@student_2, :section => @other_section)

    e2.workflow_state = 'active'
    e2.save!
    @course.reload

    #first assignment data
    @group = @course.assignment_groups.create!(:name => 'first assignment group')
    @assignment = assignment_model({
                                       :course => @course,
                                       :name => 'first assignment',
                                       :due_at => nil,
                                       :points_possible => ASSIGNMENT_1_POINTS,
                                       :submission_types => 'online_text_entry',
                                       :assignment_group => @group
                                   })
    rubric_model
    @association = @rubric.associate_with(@assignment, @course, :purpose => 'grading')
    @assignment.reload
    @submission = @assignment.submit_homework(@student_1, :body => 'student 1 submission assignment 1')
    @assignment.grade_student(@student_1, :grade => 10)
    @submission.score = 10
    @submission.save!

    #second student submission for assignment 1
    @student_2_submission = @assignment.submit_homework(@student_2, :body => 'student 2 submission assignment 1')
    @assignment.grade_student(@student_2, :grade => 5)
    @student_2_submission.score = 5
    @submission.save!

    #second assignment data
    @second_assignment = assignment_model({
                                              :course => @course,
                                              :name => 'second assignment',
                                              :due_at => nil,
                                              :points_possible => ASSIGNMENT_2_POINTS,
                                              :submission_types => 'online_text_entry',
                                              :assignment_group => @group
                                          })
    @second_association = @rubric.associate_with(@second_assignment, @course, :purpose => 'grading')

    #student 1 submission for assignment 2
    @second_submission = @second_assignment.submit_homework(@student_1, :body => 'student 1 submission assignment 2')
    @second_assignment.grade_student(@student_1, :grade => 5)
    @second_submission.save!

    #student 2 submission for assignment 2
    @second_submission = @second_assignment.submit_homework(@student_2, :body => 'student 2 submission assignment 2')
    @second_assignment.grade_student(@student_2, :grade => 5)
    @second_submission.save!

    #third assignment data
    due_date = Time.now + 1.days
    @third_assignment = assignment_model({
                                             :course => @course,
                                             :name => 'assignment three',
                                             :due_at => due_date,
                                             :points_possible => ASSIGNMENT_3_POINTS,
                                             :submission_types => 'online_text_entry',
                                             :assignment_group => @group
                                         })
    @third_association = @rubric.associate_with(@third_assignment, @course, :purpose => 'grading')

    #attendance assignment
    @attendance_assignment = assignment_model({
                                                  :course => @course,
                                                  :name => 'attendance assignment',
                                                  :title => 'attendance assignment',
                                                  :due_at => nil,
                                                  :points_possible => ATTENDANCE_POINTS,
                                                  :submission_types => 'attendance',
                                                  :assignment_group => @group,
                                              })

    @ungraded_assignment = @course.assignments.create! :title => 'not-graded assignment',
                                                       :submission_types => 'not_graded'

    get "/courses/#{@course.id}/gradebook2"
    wait_for_ajaximations
  end

  it "should not show 'not-graded' assignments" do
    driver.find_element(:css, '#gradebook_grid .slick-header').should_not include_text(@ungraded_assignment.title)
  end

  it "should validate correct number of students showing up in gradebook" do
    driver.find_elements(:css, '.student-name').count.should == @course.students.count
  end

  it "should allow showing only a certain section" do
    button = driver.find_element(:id, 'section_to_show')
    button.should include_text "All Sections"
    button.click
    sleep 1 #TODO find a better way to wait for css3 anmation to end
    driver.find_element(:id, 'section-to-show-menu').should be_displayed
    driver.find_element(:css, "label[for='section_option_#{@other_section.id}']").click
    button.should include_text @other_section.name

    # verify that it remembers the section to show across page loads
    get "/courses/#{@course.id}/gradebook2"
    wait_for_ajaximations
    button = driver.find_element(:id, 'section_to_show')
    button.should include_text @other_section.name

    # now verify that you can set it back
    button.click
    sleep 1 #TODO find a better way to wait for css3 anmation to end
    driver.find_element(:id, 'section-to-show-menu').should be_displayed
    driver.find_element(:css, "label[for='section_option_']").click
    button.should include_text "All Sections"
  end

  it "should validate initial grade totals are correct" do
    final_score_for_row(0).should eql STUDENT_1_TOTAL_IGNORING_UNGRADED
    final_score_for_row(1).should eql STUDENT_2_TOTAL_IGNORING_UNGRADED
  end

  it "should treat ungraded as 0's when asked, and ignore when not" do
    # make sure it shows like it is not treating ungraded as 0's by default
    is_checked('#include_ungraded_assignments').should be_false
    final_score_for_row(0).should eql STUDENT_1_TOTAL_IGNORING_UNGRADED
    final_score_for_row(1).should eql STUDENT_2_TOTAL_IGNORING_UNGRADED

    # set the "treat ungraded as 0's" option in the header
    open_gradebook_settings(driver.find_element(:css, 'label[for="include_ungraded_assignments"]'))

    # now make sure that the grades show as if those ungraded assignments had a '0'
    is_checked('#include_ungraded_assignments').should be_true
    final_score_for_row(0).should eql STUDENT_1_TOTAL_TREATING_UNGRADED_AS_ZEROS
    final_score_for_row(1).should eql STUDENT_2_TOTAL_TREATING_UNGRADED_AS_ZEROS

    # reload the page and make sure it remembered the setting
    get "/courses/#{@course.id}/gradebook2"
    wait_for_ajaximations
    is_checked('#include_ungraded_assignments').should be_true
    final_score_for_row(0).should eql STUDENT_1_TOTAL_TREATING_UNGRADED_AS_ZEROS
    final_score_for_row(1).should eql STUDENT_2_TOTAL_TREATING_UNGRADED_AS_ZEROS

    # NOTE: gradebook1 does not handle 'remembering' the `include_ungraded_assignments` setting

    # clear our saved settings
    driver.execute_script '$.store.clear();'
  end

  it "should change grades and validate course total is correct" do
    expected_edited_total = "33.3%"

    #editing grade for first row, first cell
    edit_grade(driver.find_element(:css, '#gradebook_grid [row="0"] .l0'), 0)

    #editing grade for second row, first cell
    edit_grade(driver.find_element(:css, '#gradebook_grid [row="1"] .l0'), 0)

    #refresh page and make sure the grade sticks
    get "/courses/#{@course.id}/gradebook2"
    wait_for_ajaximations
    final_score_for_row(0).should eql expected_edited_total
    final_score_for_row(1).should eql expected_edited_total

    #go back to gradebook1 and compare to make sure they match
    check_gradebook_1_totals({
      @student_1.id => expected_edited_total,
      @student_2.id => expected_edited_total
    })
  end

  it "should validate that gradebook settings is displayed when button is clicked" do
    open_gradebook_settings
  end

  it "should validate row sorting works when first column is clicked" do
    first_column = driver.find_elements(:css, '.slick-column-name')[0]
    2.times do
      first_column.click
    end
    meta_cells = find_slick_cells(0, driver.find_element(:css, '.grid-canvas'))
    grade_cells = find_slick_cells(0, driver.find_element(:css, '#gradebook_grid'))

    #filter validation
    validate_cell_text(meta_cells[0], STUDENT_NAME_2 + "\n" + @other_section.name)
    validate_cell_text(grade_cells[0], ASSIGNMENT_2_POINTS)
    validate_cell_text(grade_cells[4], STUDENT_2_TOTAL_IGNORING_UNGRADED)
  end

  it "should validate setting group weights" do
    weight_num = 50.0

    driver.find_element(:id, 'gradebook_settings').click
    wait_for_animations
    driver.find_element(:css, '[aria-controls="assignment_group_weights_dialog"]').click

    dialog = driver.find_element(:id, 'assignment_group_weights_dialog')
    dialog.should be_displayed

    dialog.find_element(:css, '#group_weighting_scheme').click
    set_value(dialog.find_element(:css, '.group_weight'), weight_num)

    save_button = find_with_jquery('.ui-dialog-buttonset .ui-button:contains("Save")')
    save_button.click
    wait_for_ajax_requests
    @course.reload.group_weighting_scheme.should == 'percent'
    @group.reload.group_weight.should eql(weight_num)

    # TODO: make the header cell in the UI update to reflect new value
    # heading = find_with_jquery(".slick-column-name:contains('#{@group.name}') .assignment-points-possible")
    # heading.should include_text("#{weight_num}% of grade")
  end

  it "should validate arrange columns by due date option" do
    expected_text = "-"

    open_gradebook_settings(driver.find_element(:css, '#ui-menu-0-4'))
    first_row_cells = find_slick_cells(0, driver.find_element(:css, '#gradebook_grid'))
    validate_cell_text(first_row_cells[0], expected_text)
  end

  it "should validate arrange columns by assignment group option" do
    open_gradebook_settings(driver.find_element(:css, '#ui-menu-0-4'))
    open_gradebook_settings(driver.find_element(:css, '#ui-menu-0-5'))
    first_row_cells = find_slick_cells(0, driver.find_element(:css, '#gradebook_grid'))
    validate_cell_text(first_row_cells[0], ASSIGNMENT_1_POINTS)
  end

  it "should validate show attendance columns option" do
    open_gradebook_settings(driver.find_element(:css, '#ui-menu-0-6'))
    headers = driver.find_elements(:css, '.slick-header')
    headers[1].should include_text(@attendance_assignment.title)
    open_gradebook_settings(driver.find_element(:css, '#ui-menu-0-6'))
  end

  it "should validate posting a comment to a graded assignment" do
    pending("opening the comment dialog frequently fails")
    comment_text = "This is a new comment!"

    dialog = open_comment_dialog
    set_value(dialog.find_element(:id, "add_a_comment"), comment_text)
    driver.find_element(:css, "form.submission_details_add_comment_form.clearfix > button.button").click
{'fraction_non_alphanumeric': 0.0979367449436677, 'fraction_numerical': 0.011707615040043437, 'mean_word_length': 2.968888888888889, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 125, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 102, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4989699', 'n_tokens_mistral': 9115, 'n_tokens_neox': 8795, 'n_words': 1899}