<commit_before># frozen_string_literal: true

require 'test_helper'
require 'integration/concerns/geo'

class ChoosingLocationTest < ActionDispatch::IntegrationTest
  include Warden::Test::Helpers
  include Geo

  it 'redirects there when user logged in and no location set' do
    login_as create(:user, :stateless)
    visit root_path

    assert_selector 'h1', text: 'Cambia tu ciudad'
  end

  it 'suggests locations matching name' do
    create(:town, :tenerife)
    create(:town, name: 'Tenerife',
                  id: 369_486,
                  _state: :magdalena,
                  _country: :colombia)

    choose_location('tenerife')

    assert_text 'Santa Cruz de Tenerife, Islas Canarias, España (0 anuncios)'
    assert_text 'Tenerife, Magdalena, Colombia (0 anuncios)'
  end

  it 'shows a message when no matching locations are found' do
    choose_location('tenerifa')

    assert_text 'No se han encontrado ubicaciones con el nombre tenerifa'
  end

  it 'shows an error message when submitted without a search' do
    choose_location('')

    assert_text 'No se han encontrado ubicaciones con el nombre'
  end

  it 'chooses between locations matching name' do
    create(:town, :tenerife)
    create(:town, name: 'Tenerife',
                  id: 369_486,
                  _state: :magdalena,
                  _country: :colombia)

    choose_location('tenerife')

    select 'Santa Cruz de Tenerife, Islas Canarias, España (0 anuncios)'
    click_button 'Elige tu ubicación'

    assert_location_page 'Santa Cruz de Tenerife, Islas Canarias, España'
  end

  it "directly chooses location when there's a single match" do
    create(:town, :tenerife)
    choose_location('tenerife, islas canarias')

    assert_location_page 'Santa Cruz de Tenerife, Islas Canarias, España'
  end

  it 'directly chooses location through GET request' do
    create(:town, :tenerife)
    visit location_change_path(location: 'tenerife, islas canarias')

    assert_location_page 'Santa Cruz de Tenerife, Islas Canarias, España'
  end

  it 'matches town when searching town without accents' do
    create(:town, name: 'Leganés', id: 765_045)<commit_msg>Consolidate IP geolocalization tests<commit_after># frozen_string_literal: true

require 'test_helper'
require 'integration/concerns/geo'

class ChoosingLocationTest < ActionDispatch::IntegrationTest
  include Warden::Test::Helpers
  include Geo

  it 'redirects there when user logged in and no location set' do
    login_as create(:user, :stateless)
    visit root_path

    assert_selector 'h1', text: 'Cambia tu ciudad'
  end

  it 'suggests locations matching name' do
    create(:town, :tenerife)
    create(:town, name: 'Tenerife',
                  id: 369_486,
                  _state: :magdalena,
                  _country: :colombia)

    choose_location('tenerife')

    assert_text 'Santa Cruz de Tenerife, Islas Canarias, España (0 anuncios)'
    assert_text 'Tenerife, Magdalena, Colombia (0 anuncios)'
  end

  it 'shows a message when no matching locations are found' do
    choose_location('tenerifa')

    assert_text 'No se han encontrado ubicaciones con el nombre tenerifa'
  end

  it 'shows an error message when submitted without a search' do
    choose_location('')

    assert_text 'No se han encontrado ubicaciones con el nombre'
  end

  it 'chooses between locations matching name' do
    create(:town, :tenerife)
    create(:town, name: 'Tenerife',
                  id: 369_486,
                  _state: :magdalena,
                  _country: :colombia)

    choose_location('tenerife')

    select 'Santa Cruz de Tenerife, Islas Canarias, España (0 anuncios)'
    click_button 'Elige tu ubicación'

    assert_location_page 'Santa Cruz de Tenerife, Islas Canarias, España'
  end

  it "directly chooses location when there's a single match" do
    create(:town, :tenerife)
    choose_location('tenerife, islas canarias')

    assert_location_page 'Santa Cruz de Tenerife, Islas Canarias, España'
  end

  it 'matches town when searching town without accents' do
    create(:town, name: 'Leganés', id: 765_045)
{'fraction_non_alphanumeric': 0.0777479892761394, 'fraction_numerical': 0.010723860589812333, 'mean_word_length': 3.394004282655246, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '2223732', 'n_tokens_mistral': 1321, 'n_tokens_neox': 1230, 'n_words': 422}