<commit_before># encoding: UTF-8
require "spec_helper"

feature("Search Views") do
  background do
    # Setup BG Stuff
  end

  scenario("Nav Bar") do
    # it("TODO(jon): Write this test")
  end

  scenario("Pagination") do
    visit("/upmin/m/User")

    # Make sure some basic pagination exits
    within(".pagination:first-of-type") do
      within(".active, .current") do
        expect(page).to(have_content("1"))
      end

      expect(page).to(have_content("Next"))
      click_link("Next")
    end

    within(".pagination:nth-of-type(2)") do
      within(".active, .current") do
        expect(page).to(have_content("2"))
      end

      expect(page).to(have_content("Next"))
      expect(page).to(have_content("Prev"))

      click_link("3")
    end

    within(".pagination:last-of-type") do
      within(".active, .current") do
        expect(page).to(have_content("3"))
      end
    end
  end

  scenario("Search via integer") do
    visit("/upmin/m/User")

    expect(page).to(have_selector("a.search-result-link", count: 30))

    fill_in("q_id_gteq", with: 1)
    fill_in("q_id_lteq", with: 5)
    click_button("Search")

    expect(page).to(have_selector("a.search-result-link", count: 5))
  end

  scenario("Search via string") do
    expected_user = User.first

    visit("/upmin/m/User")

    fill_in("q_name_cont", with: expected_user.name)
    click_button("Search")

    expect(page).to(have_selector("a.search-result-link", minimum: 1))
    expect(page).to(have_content(expected_user.name))
  end

  scenario("Search via string") do
    expected_user = User.first

    visit("/upmin/m/User")

    fill_in("q_name_cont", with: expected_user.name)
    click_button("Search")

    expect(page).to(have_selector("a.search-result-link", minimum: 1))
    expect(page).to(have_content(expected_user.name))
  end

  scenario("config.items_per_page") do
    Upmin.configuration.items_per_page = 25

    visit("/upmin/m/Order")

    # Global config of 25 should override default of 30
    expect(page).to(have_selector("a.search-result-link", count: 25))

    # Reset this.
    Upmin.configuration = Upmin::Configuration.new
  end

  scenario("Model items_per_page with config.items_per_page") do
    Upmin.configuration.items_per_page = 25

    visit("/upmin/m/Shipment")<commit_msg>remove duplicate test, fix randomly failing test<commit_after># encoding: UTF-8
require "spec_helper"

feature("Search Views") do
  background do
    # Setup BG Stuff
  end

  scenario("Nav Bar") do
    # it("TODO(jon): Write this test")
  end

  scenario("Pagination") do
    visit("/upmin/m/User")

    # Make sure some basic pagination exits
    within(".pagination:first-of-type") do
      within(".active, .current") do
        expect(page).to(have_content("1"))
      end

      expect(page).to(have_content("Next"))
      click_link("Next")
    end

    within(".pagination:nth-of-type(2)") do
      within(".active, .current") do
        expect(page).to(have_content("2"))
      end

      expect(page).to(have_content("Next"))
      expect(page).to(have_content("Prev"))

      click_link("3")
    end

    within(".pagination:last-of-type") do
      within(".active, .current") do
        expect(page).to(have_content("3"))
      end
    end
  end

  scenario("Search via integer") do
    visit("/upmin/m/User")

    expect(page).to(have_selector("a.search-result-link", count: 30))

    fill_in("q_id_gteq", with: 2)
    fill_in("q_id_lteq", with: 5)
    click_button("Search")

    expect(page).to(have_selector("a.search-result-link", count: 4))
  end

  scenario("Search via string") do
    expected_user = User.first

    visit("/upmin/m/User")

    fill_in("q_name_cont", with: expected_user.name)
    click_button("Search")

    expect(page).to(have_selector("a.search-result-link", minimum: 1))
    expect(page).to(have_content(expected_user.name))
  end

  scenario("config.items_per_page") do
    Upmin.configuration.items_per_page = 25

    visit("/upmin/m/Order")

    # Global config of 25 should override default of 30
    expect(page).to(have_selector("a.search-result-link", count: 25))

    # Reset this.
    Upmin.configuration = Upmin::Configuration.new
  end

  scenario("Model items_per_page with config.items_per_page") do
    Upmin.configuration.items_per_page = 25

    visit("/upmin/m/Shipment")
{'fraction_non_alphanumeric': 0.1488576044311101, 'fraction_numerical': 0.010385414262635588, 'mean_word_length': 3.4, 'pattern_counts': {'":': 0, '<': 3, '<?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': '5873113', 'n_tokens_mistral': 1503, 'n_tokens_neox': 1432, 'n_words': 273}