<commit_before># frozen_string_literal: true

require_relative "../acceptance_test"

module Competitions
  # :stopdoc:
  class PublicPagesAcceptanceTest < AcceptanceTest
    test "popular pages" do
      create_results

      Ironman.calculate!

      visit "/ironman"
      assert_page_has_content "Ironman"

      visit "/rider_rankings"
      assert_page_has_content "WSBA is using the default USA Cycling ranking system from 2012 onward"

      visit "/cat4_womens_race_series"
      assert_page_has_content "No results for #{RacingAssociation.current.effective_year}"

      visit "/oregon_cup"
      assert_page_has_content "Oregon Cup"
    end

    test "bar" do
      FactoryBot.create(:discipline, name: "Overall")
      FactoryBot.create(:discipline, name: "Mountain Bike")
      age_graded = FactoryBot.create(:discipline, name: "Age Graded")
      masters_men = FactoryBot.create(:category, name: "Masters Men")
      masters_30_34 = FactoryBot.create(:category, name: "Masters Men 30-34", ages: 30..34, parent: masters_men)
      FactoryBot.create(:category, name: "Masters Men 35-39", ages: 35..39, parent: masters_men)
      age_graded.bar_categories << masters_30_34

      road = FactoryBot.create(:discipline, name: "Road")
      road.bar_categories << masters_men

      # Masters 30-34 result. (32)
      weaver = FactoryBot.create(:person, date_of_birth: Date.new(1977))
      banana_belt_1 = FactoryBot.create(:event, date: Date.new(2009, 3))

      Timecop.freeze(2009, 4) do
        banana_belt_masters_30_34 = banana_belt_1.races.create!(category: masters_30_34)
        banana_belt_masters_30_34.results.create!(person: weaver, place: "10")

        Bar.calculate! 2009
        OverallBar.calculate! 2009
        AgeGradedBar.calculate! 2009
      end

      Bar.calculate!
      OverallBar.calculate!
      AgeGradedBar.calculate!

      visit "/bar"
      assert_page_has_content "BAR"
      assert_page_has_content "Oregon Best All-Around Rider"

      visit "/bar/2009"
      page.has_css?("title", text: /BAR/)

      visit "/bar/2009/age_graded"
      assert_page_has_content "Masters Men 30-34"

      visit "/bar/#{Time.zone.today.year}"
      assert_page_has_content "Overall"

      visit "/bar/#{Time.zone.today.year}/age_graded"
      page.has_css?("title", text: /Age Graded/)
    end

    private
<commit_msg>Fix acceptance test<commit_after># frozen_string_literal: true

require_relative "../acceptance_test"

module Competitions
  # :stopdoc:
  class PublicPagesAcceptanceTest < AcceptanceTest
    test "popular pages" do
      create_results

      Calculations::V3::Calculation.create!(
        key: :ironman,
        members_only: true,
        name: "Ironman",
        points_for_place: 1
      ).calculate!

      calculation = Calculations::V3::Calculation.create!(
        key: :oregon_cup,
        name: "<NAME>",
        members_only: true,
        points_for_place: [100, 75, 60, 50, 45, 40, 35, 30, 25, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10],
        specific_events: true
      )

      calculation.calculation_categories.create!(category: Category.find_by(name: "Senior Men"))
      calculation.calculations_events.create!(event: @new_event, multiplier: 1)
      calculation.calculate!

      visit "/ironman"
      assert_page_has_content "Ironman"

      visit "/oregon_cup"
      assert_page_has_content "Oregon Cup"
    end

    test "bar" do
      overall_discipline = FactoryBot.create(:discipline, name: "Overall")
      FactoryBot.create(:discipline, name: "Mountain Bike")
      age_graded = FactoryBot.create(:discipline, name: "Age Graded")
      masters_men = FactoryBot.create(:category, name: "Masters Men")
      masters_30_34 = FactoryBot.create(:category, name: "Masters Men 30-34", ages: 30..34, parent: masters_men)
      FactoryBot.create(:category, name: "Masters Men 35-39", ages: 35..39, parent: masters_men)

      road = FactoryBot.create(:discipline, name: "Road")

      calculation = Calculations::V3::Calculation.create!(
        disciplines: [road],
        field_size_bonus: true,
        members_only: true,
        key: :road_bar,
        name: "Road BAR",
        points_for_place: [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],
        weekday_events: false,
        year: 2009
      )
      calculation.categories << masters_men

      calculation = Calculations::V3::Calculation.create!(
        discipline: overall_discipline,
        event_notes: "Oregon Best All-Around Rider",
        key: "overall_bar",
        members_only: true,
        name: "Overall BAR",
        points_for_place: (1..300).to_a.reverse,
        source_event_keys: %w[road_bar],
        weekday_events: true,
        year: 2009
      )
      calculation.categories << masters_men

      calculation = Calculations::V3::Calculation.create!(
        discipline: age_graded,
        group_by: :age,
        members_only: true,
        name: "<NAME>",
        source_event_keys: %w[overall_bar],
        weekday_events: true,
        year: 2009
      )
      calculation.categories << masters_30_34

      # Masters 30-34 result. (32)
      weaver = FactoryBot.create(:person, date_of_birth: Date.new(1977))
      banana_belt_1 = FactoryBot.create(:event, date: Date.new(2009, 3))

      Timecop.freeze(2009, 4) do
        banana_belt_masters_30_34 = banana_belt_1.races.create!(category: masters_30_34)
        banana_belt_masters_30_34.results.create!(person: weaver, place: "10")

        calculation.calculate!
      end

      calculation.calculate!

      visit "/bar"
      assert_page_has_content "BAR"
      assert_page_has_content "Oregon Best All-Around Rider"

      visit "/bar/2009"
      page.has_css?("title", text: /BAR/)

      visit "/bar/2009/age_graded"
      assert_page_has_content "Masters Men"

      visit "/bar/#{Time.zone.today.year}"
      assert_page_has_content "Overall"

      visit "/bar/#{Time.zone.today.year}/age_graded"
      page.has_css?("title", text: /Age Graded/)
    end

    private

{'fraction_non_alphanumeric': 0.11257285595337219, 'fraction_numerical': 0.04029975020815987, 'mean_word_length': 2.974851091992058, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6542452', 'n_tokens_mistral': 2168, 'n_tokens_neox': 1904, 'n_words': 419}