<commit_before>require "acceptance/webdriver_test_case"

# :stopdoc:
class EventsTest < WebDriverTestCase
  def test_events
    login_as :administrator

    click :link_text => "New Event"

    type "Sausalito Criterium", "event_name"
    click "save"
    assert_page_source "Created Sausalito Criterium"
    
    if Date.today.month == 12
      open "/admin/events?year=#{Date.today.year}"
    else
      open "/admin/events"
    end
    assert_page_source "Sausalito Criterium"
    click :link_text => "Sausalito Criterium"

    assert_value "", "event_promoter_id"
    assert_value "", "promoter_auto_complete"
    type "<NAME>", "promoter_auto_complete"

    click "save"
    assert_value(/\d+/, "event_promoter_id")
    assert_value "<NAME>", "promoter_auto_complete"

    open "/admin/events?year=#{Date.today.year}"
    assert_page_source "Sausalito Criterium"
    click :link_text => "Sausalito Criterium"
    assert_value(/\d+/, "event_promoter_id")
    assert_value "<NAME>", "promoter_auto_complete"

    click "edit_promoter_link"
    assert_title(/<NAME>$/)

    type "Tim", "person_first_name"
    click "save"

    click "back_to_event"

    assert_title(/Sausalito Criterium/)
    assert_value(/\d+/, "event_promoter_id")
    assert_value "<NAME>", "promoter_auto_complete"

    candi = Person.find_by_name('<NAME>')
    type "candi m", "promoter_auto_complete"
    wait_for_element "person_#{candi.id}"
    
    click :css => "li#person_#{candi.id} a"
    wait_for_value candi.id, "event_promoter_id"
    assert_value "<NAME>", "promoter_auto_complete"

    click "save"

    assert_value candi.id, "event_promoter_id"
    assert_value "<NAME>", "promoter_auto_complete"

    click "promoter_auto_complete"
    type "", "promoter_auto_complete"
    assert_value "", "promoter_auto_complete"
    click "save"

    assert_value "", "event_promoter_id"
    assert_value "", "promoter_auto_complete"

    assert_value "", "event_team_id"
    assert_value "", "team_auto_complete"

    assert_value "", "event_phone"
    assert_value "", "event_email"

    type "(541) 212-9000", "event_phone"
    type "<EMAIL>", "event_email"
    click "save"

    assert_value "(541) 212-9000", "event_phone"
    assert_value "<EMAIL>", "event_email"

    open "/admin/people/#{candi.id}/edit"
    assert_value "(503) 555-1212", "person_home_phone"
    assert_value "<EMAIL>", "person_email"

    open "/admin/events?year=#{Date.today.year}"
    click :link_text => "Sausalito Criterium"

    type "Gentle Lovers", "team_auto_complete"
    gl = Team.find_by_name('Gentle Lovers')
    wait_for_element "team_#{gl.id}"
    wait_for_displayed "team_#{gl.id}"
    click :css => "li#team_#{gl.id} a"
    wait_for_value gl.id, "event_team_id"
    assert_value "Gentle Lovers", "team_auto_complete"

    click "save"

    assert_value gl.id, "event_team_id"
    assert_value "Gentle Lovers", "team_auto_complete"

    assert_value gl.id, "event_team_id"
    click "team_auto_complete"
    type "", "team_auto_complete"
    click "save"

    assert_value "", "event_team_id"
    assert_value "", "team_auto_complete"

    click :link_text => "Delete"

    assert_page_source "Deleted Sausalito Criterium"

    open "/admin/events?year=2004"
    assert_not_in_page_source "Sausalito Criterium"

    open "/admin/events?year=2003"

    click :link_text => "Kings Valley Road Race"
    assert_page_source "Senior Men Pro 1/2"
    assert_page_source "Senior Men 3"

    kings_valley = Event.find_by_name_and_date('Kings Valley Road Race', '2003-12-31')
    click "destroy_race_#{kings_valley.races.first.id}"

    open "/admin/events?year=2003"
    click :link_text => "Kings Valley Road Race"

    click_ok_on_confirm_dialog<commit_msg>Stricter test<commit_after>require "acceptance/webdriver_test_case"

# :stopdoc:
class EventsTest < WebDriverTestCase
  def test_events
    login_as :administrator

    click :link_text => "New Event"

    type "Sausalito Criterium", "event_name"
    click "save"
    assert_page_source "Created Sausalito Criterium"
    
    if Date.today.month == 12
      open "/admin/events?year=#{Date.today.year}"
    else
      open "/admin/events"
    end
    assert_page_source "Sausalito Criterium"
    click :link_text => "Sausalito Criterium"

    assert_value "", "event_promoter_id"
    assert_value "", "promoter_auto_complete"
    type "<NAME>", "promoter_auto_complete"

    click "save"
    assert_value(/\d+/, "event_promoter_id")
    assert_value "<NAME>", "promoter_auto_complete"

    open "/admin/events?year=#{Date.today.year}"
    assert_page_source "Sausalito Criterium"
    click :link_text => "Sausalito Criterium"
    assert_value(/\d+/, "event_promoter_id")
    assert_value "<NAME>", "promoter_auto_complete"

    click "edit_promoter_link"
    assert_title(/<NAME>$/)

    type "Tim", "person_first_name"
    click "save"

    click "back_to_event"

    assert_title(/Sausalito Criterium/)
    assert_value(/\d+/, "event_promoter_id")
    assert_value "<NAME>", "promoter_auto_complete"

    candi = Person.find_by_name('<NAME>')
    type "candi m", "promoter_auto_complete"
    wait_for_element "person_#{candi.id}"
    
    click :css => "li#person_#{candi.id} a"
    wait_for_value candi.id, "event_promoter_id"
    assert_value "<NAME>", "promoter_auto_complete"

    click "save"

    assert_value candi.id, "event_promoter_id"
    assert_value "<NAME>", "promoter_auto_complete"

    click "promoter_auto_complete"
    type "", "promoter_auto_complete"
    assert_value "", "promoter_auto_complete"
    click "save"

    assert_value "", "event_promoter_id"
    assert_value "", "promoter_auto_complete"

    assert_value "", "event_team_id"
    assert_value "", "team_auto_complete"

    assert_value "", "event_phone"
    assert_value "", "event_email"

    type "(541) 212-9000", "event_phone"
    type "<EMAIL>", "event_email"
    click "save"

    assert_value "(541) 212-9000", "event_phone"
    assert_value "<EMAIL>", "event_email"

    open "/admin/people/#{candi.id}/edit"
    assert_value "(503) 555-1212", "person_home_phone"
    assert_value "<EMAIL>", "person_email"

    open "/admin/events?year=#{Date.today.year}"
    click :link_text => "Sausalito Criterium"

    type "Gentle Lovers", "team_auto_complete"
    gl = Team.find_by_name('<NAME>')
    wait_for_element "team_#{gl.id}"
    wait_for_displayed "team_#{gl.id}"
    click :css => "li#team_#{gl.id} a"
    wait_for_value gl.id, "event_team_id"
    assert_value "Gentle Lovers", "team_auto_complete"

    click "save"

    assert_value gl.id, "event_team_id"
    assert_value "Gentle Lovers", "team_auto_complete"

    assert_value gl.id, "event_team_id"
    click "team_auto_complete"
    type "", "team_auto_complete"
    click "save"

    assert_value "", "event_team_id"
    assert_value "", "team_auto_complete"

    click :link_text => "Delete"

    assert_page_source "Deleted Sausalito Criterium"

    open "/admin/events?year=2004"
    assert_not_in_page_source "Sausalito Criterium"

    open "/admin/events?year=2003"

    wait_for_page_source "Import Schedule"
    click :link_text => "Kings Valley Road Race"
    wait_for_page_source "Senior Men Pro 1/2"
    assert_page_source "Senior Men 3"

    kings_valley = Event.find_by_name_and_date('Kings Valley Road Race', '2003-12-31')
    click "destroy_race_#{kings_valley.races.first.id}"

    open "/admin/events?year=2003"
    click :link_text => "Kings Valley Road Race"

    click_ok_on_confirm_dialog
{'fraction_non_alphanumeric': 0.12479957242116516, 'fraction_numerical': 0.01469802244788883, 'mean_word_length': 3.976728723404255, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 44, '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': '5308284', 'n_tokens_mistral': 2772, 'n_tokens_neox': 2603, 'n_words': 506}