<commit_before>#
# Copyright (C) 2013 - 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/>.

module GradingSchemesCommon
  def save_and_reload_changes(grading_standard)
    f('.save_button').click
    wait_for_ajaximations
    grading_standard.reload
  end

  def simple_grading_standard(context)
    @standard = context.grading_standards.create!(
      title: "My Grading Standard",
      standard_data: {
        "scheme_0" => { name: "A", value: "90" },
        "scheme_1" => { name: "B", value: "80" },
        "scheme_2" => { name: "C", value: "70" },
        "scheme_3" => { name: "D", value: "0" }
      }
    )
  end

  def should_add_a_grading_scheme(options = {name: "new grading standard"})
    new_standard_name = options[:name]
    f('.add_standard_button').click
    expect(f('.add_standard_button')).to have_class('disabled')
    replace_content(f('.scheme_name'), new_standard_name)
    f('.save_button').click
    wait_for_ajax_requests
    @new_grading_standard = GradingStandard.last
    expect(@new_grading_standard.title).to eq new_standard_name
    expect(f("#grading_standard_#{@new_grading_standard.id}")).to be_displayed
  end

  def should_edit_a_grading_scheme(context, url)
    edit_name = 'edited grading scheme'
    simple_grading_standard(context)
    grading_standard = GradingStandard.last
    get url
    f('#react_grading_tabs a[href="#grading-standards-tab"]').click if context.is_a?(Account)
    f('.edit_grading_standard_button').click
    replace_content(f('.scheme_name'), edit_name)
    save_and_reload_changes(grading_standard)
    expect(grading_standard.title).to eq edit_name
    expect(fj(".title span:eq(1)")).to include_text(edit_name)
  end

  def should_delete_a_grading_scheme(context, url)
    simple_grading_standard(context)
    get url
    f('#react_grading_tabs a[href="#grading-standards-tab"]').click if context.is_a?(Account)
    f('.delete_grading_standard_button').click
    driver.switch_to.alert.accept
    wait_for_ajaximations
    expect(GradingStandard.last.workflow_state).to eq 'deleted'
  end

  def create_simple_standard_and_edit(context, url)
    simple_grading_standard(context)
    @grading_standard = GradingStandard.last
    get url
    f('#react_grading_tabs a[href="#grading-standards-tab"]').click if context.is_a?(Account)
    f('.edit_grading_standard_button').click
  end

  def should_add_a_grading_scheme_item
    data_count = @grading_standard.data.count<commit_msg>spec: fix grading_schemes spec so it works w/ react 15<commit_after>#
# Copyright (C) 2013 - 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/>.

module GradingSchemesCommon
  def save_and_reload_changes(grading_standard)
    f('.save_button').click
    wait_for_ajaximations
    grading_standard.reload
  end

  def simple_grading_standard(context)
    @standard = context.grading_standards.create!(
      title: "My Grading Standard",
      standard_data: {
        "scheme_0" => { name: "A", value: "90" },
        "scheme_1" => { name: "B", value: "80" },
        "scheme_2" => { name: "C", value: "70" },
        "scheme_3" => { name: "D", value: "0" }
      }
    )
  end

  def should_add_a_grading_scheme(options = {name: "new grading standard"})
    new_standard_name = options[:name]
    f('.add_standard_button').click
    expect(f('.add_standard_button')).to have_class('disabled')
    replace_content(f('.scheme_name'), new_standard_name)
    f('.save_button').click
    wait_for_ajax_requests
    @new_grading_standard = GradingStandard.last
    expect(@new_grading_standard.title).to eq new_standard_name
    expect(f("#grading_standard_#{@new_grading_standard.id}")).to be_displayed
  end

  def should_edit_a_grading_scheme(context, url)
    edit_name = 'edited grading scheme'
    simple_grading_standard(context)
    grading_standard = GradingStandard.last
    get url
    f('#react_grading_tabs a[href="#grading-standards-tab"]').click if context.is_a?(Account)
    f('.edit_grading_standard_button').click
    replace_content(f('.scheme_name'), edit_name)
    save_and_reload_changes(grading_standard)
    expect(grading_standard.title).to eq edit_name
    expect(fj(".standard_title .title")).to include_text(edit_name)
  end

  def should_delete_a_grading_scheme(context, url)
    simple_grading_standard(context)
    get url
    f('#react_grading_tabs a[href="#grading-standards-tab"]').click if context.is_a?(Account)
    f('.delete_grading_standard_button').click
    driver.switch_to.alert.accept
    wait_for_ajaximations
    expect(GradingStandard.last.workflow_state).to eq 'deleted'
  end

  def create_simple_standard_and_edit(context, url)
    simple_grading_standard(context)
    @grading_standard = GradingStandard.last
    get url
    f('#react_grading_tabs a[href="#grading-standards-tab"]').click if context.is_a?(Account)
    f('.edit_grading_standard_button').click
  end

  def should_add_a_grading_scheme_item
    data_count = @grading_standard.data.count
{'fraction_non_alphanumeric': 0.10598179453836151, 'fraction_numerical': 0.005689206762028608, 'mean_word_length': 4.41637323943662, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2643521', 'n_tokens_mistral': 1968, 'n_tokens_neox': 1940, 'n_words': 464}