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

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

  def go_to_calendar
    get "/calendar"
    wait_for_ajaximations
  end

  before (:each) do
    Account.default.update_attribute(:settings, {:enable_scheduler => false})
  end

  context "teacher view" do
    before (:each) do
      course_with_teacher_logged_in
    end

    it "should create an event" do
      new_event_name = 'new event'
      go_to_calendar

      f("##{Time.now.strftime("day_%Y_%m_%d")} .calendar_day").click
      replace_content(f('#calendar_event_title'), new_event_name)
      submit_form('#edit_calendar_event_form')
      wait_for_ajaximations
      f("##{Time.now.strftime("day_%Y_%m_%d")} .calendar_day").should include_text(new_event_name)
      CalendarEvent.find_by_title(new_event_name).should be_present
    end

    it "should edit an event" do
      edit_name = 'edited cal title'
      calendar_event_model(:title => "new event", :start_at => Time.now)
      go_to_calendar

      f("##{Time.now.strftime("day_%Y_%m_%d")} .calendar_day .calendar_event").click
      f('.edit_event_link').click
      replace_content(f('#calendar_event_title'), edit_name)
      submit_form('#edit_calendar_event_form')
      wait_for_ajaximations
      CalendarEvent.find_by_title(edit_name).should be_present
    end

    it "should delete an event" do
      event_title = 'new event'
      calendar_event_model(:title => event_title, :start_at => Time.now)
      go_to_calendar

      f("##{Time.now.strftime("day_%Y_%m_%d")} .calendar_day .calendar_event").click
      f('.delete_event_link').click
      driver.switch_to.alert.accept
      wait_for_ajaximations
      f("##{Time.now.strftime("day_%Y_%m_%d")} .calendar_day").should_not include_text(event_title)
      CalendarEvent.find_by_title(event_title).workflow_state.should == 'deleted'
    end

    it "should view the full details of an event" do
      event_title = 'new event'
      calendar_event_model(:title => event_title, :start_at => Time.now)
      go_to_calendar

      f("##{Time.now.strftime("day_%Y_%m_%d")} .calendar_day .calendar_event").click
      expect_new_page_load { f('.view_event_link').click }<commit_msg>spec: fix calendar intermittent failure<commit_after>require File.expand_path(File.dirname(__FILE__) + '/common')

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

  def go_to_calendar
    get "/calendar"
    wait_for_ajaximations
  end

  before (:each) do
    Account.default.update_attribute(:settings, {:enable_scheduler => false})
  end

  context "teacher view" do
    before (:each) do
      course_with_teacher_logged_in
    end

    it "should create an event" do
      new_event_name = 'new event'
      go_to_calendar

      f("##{Time.now.strftime("day_%Y_%m_%d")} .calendar_day").click
      replace_content(f('#calendar_event_title'), new_event_name)
      submit_form('#edit_calendar_event_form')
      wait_for_ajaximations
      f("##{Time.now.strftime("day_%Y_%m_%d")} .calendar_day").should include_text(new_event_name)
      CalendarEvent.find_by_title(new_event_name).should be_present
    end

    it "should edit an event" do
      edit_name = 'edited cal title'
      calendar_event_model(:title => "new event", :start_at => Time.now)
      go_to_calendar

      f("##{Time.now.strftime("day_%Y_%m_%d")} .calendar_day .calendar_event").click
      f('.edit_event_link').click
      replace_content(f('#calendar_event_title'), edit_name)
      submit_form('#edit_calendar_event_form')
      wait_for_ajaximations
      CalendarEvent.find_by_title(edit_name).should be_present
    end

    it "should delete an event" do
      event_title = 'new event'
      calendar_event_model(:title => event_title, :start_at => Time.now)
      go_to_calendar

      f("##{Time.now.strftime("day_%Y_%m_%d")} .calendar_day .calendar_event").click
      f('.delete_event_link').click
      keep_trying_until do
        driver.switch_to.alert.should_not be nil
        driver.switch_to.alert.accept
        true
      end
      wait_for_ajaximations
      f("##{Time.now.strftime("day_%Y_%m_%d")} .calendar_day").should_not include_text(event_title)
      CalendarEvent.find_by_title(event_title).workflow_state.should == 'deleted'
    end

    it "should view the full details of an event" do
      event_title = 'new event'
      calendar_event_model(:title => event_title, :start_at => Time.now)
      go_to_calendar

      f("##{Time.now.strftime("day_%Y_%m_%d")} .calendar_day .calendar_event").click
      expect_new_page_load { f('.view_event_link').click }
{'fraction_non_alphanumeric': 0.12005981627857296, 'fraction_numerical': 0.0, 'mean_word_length': 3.8317853457172344, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '4415845', 'n_tokens_mistral': 1612, 'n_tokens_neox': 1557, 'n_words': 273}