<commit_before>require 'spec_helper'

feature "results page search", :js=>true do

  background do
    page.set_rack_session('aggregate_locations' => [])
    search_from_home(:keyword=>"asdfg")
  end

  # test filter fieldset legend toggling across all filters
  xscenario 'when location filter has no cached values and legend is toggled', :vcr do
    test_filter_legend("location")
  end
  xscenario 'when service-area filter has no cached values and legend is toggled', :vcr do
    test_filter_legend("service-area","San Mateo County, CA")
  end
  xscenario 'when kind filter has no cached values and legend is toggled', :vcr do
    test_filter_legend("kind", "Human Services",13)
  end
  xscenario 'when agency filter has no cached values and legend is toggled', :vcr do
    test_filter_legend("org-name")
  end

  # test filter fieldset toggle toggling across all filters
  xscenario 'when location filter has no cached values and toggle is toggled', :vcr do
    test_filter_toggle("location")
  end
  xscenario 'when service-area filter has no cached values and toggle is toggled', :vcr do
    test_filter_toggle("service-area","San Mateo County, CA")
  end
  xscenario 'when kind filter has no cached values and toggle is toggled', :vcr do
    test_filter_toggle("kind", "Human Services",13)
  end
  xscenario 'when agency filter has no cached values and toggle is toggled', :vcr do
    test_filter_toggle("org-name")
  end

  # test adding custom value to filters that accept custom values
  xscenario 'when location filter has no cached values and custom value is added', :vcr do
    test_filter_custom_value("location")
  end
  xscenario 'when agency filter has no cached values and custom value is added', :vcr do
    test_filter_custom_value("org-name")
  end

  # test adding custom value to filters and retrieving no results
  xscenario 'when location filter has custom value and no results', :vcr do
    test_filter_custom_value_no_results("location","San Mateo, CA")
  end
  xscenario 'when agency filter has custom value and no results', :vcr do
    test_filter_custom_value_no_results("org-name","United States Government")
  end

  # test adding custom value to filters and retrieving results
  xscenario 'when location filter has custom value and has results', :vcr do
    name = "location"
    field = "San Mateo, CA"
    set_filter(name,field)
    fill_in('keyword', :with => '') # clear keyword

    find('#update-btn').click

    within("##{name}-options") do
      find(".closed").click
      find(".available-options").should have_css(".toggle-group", :count=>3)
      page.should_not have_css("##{name}-option-input")
    end
  end
  xscenario 'when agency filter has custom value and has results', :vcr do
    name = "org-name"
    field = "United States Government"
    set_filter(name,field)
    fill_in('keyword', :with => '') # clear keyword

    find('#update-btn').click

    within("##{name}-options") do
      find(".closed").click
      find(".available-options").should have_css(".toggle-group", :count=>3)
      page.should_not have_css("##{name}-option-input")
    end
  end

  # test filter selection across all filters
  xscenario 'when location filter has cached values and new option is selected', :vcr do
    fill_in('keyword', :with => '') # clear keyword
    find('#update-btn').click
    set_filter("location","San Francisco, CA",false)
    find('#update-btn').click
    expect(all("#location-options .current-option label").last).to have_content("San Francisco, CA")
  end
  xscenario 'when service-area filter has cached values and new option is selected', :vcr do
    fill_in('keyword', :with => '') # clear keyword
    find('#update-btn').click
    set_filter("service-area","All",false)
    find('#update-btn').click
    expect(all("#service-area-options .current-option label").last).to have_content("All")
  end
  xscenario 'when kind filter has cached values and new option is selected', :vcr do
    fill_in('keyword', :with => '') # clear keyword
    find('#update-btn').click
    set_filter("kind","Other",false)
    find('#update-btn').click
    expect(all("#kind-options .current-option label").last).to have_content("Other")
  end
  xscenario 'when agency filter has cached values and new option is selected', :vcr do
    fill_in('keyword', :with => '') # clear keyword<commit_msg>Enables disabled filter tests<commit_after>require 'spec_helper'

feature "results page search", :js=>true do

  background do
    page.set_rack_session('aggregate_locations' => [])
    search_from_home(:keyword=>"asdfg")
  end

  # test filter fieldset legend toggling across all filters
  scenario 'when location filter has no cached values and legend is toggled', :vcr do
    test_filter_legend("location")
  end
  scenario 'when service-area filter has no cached values and legend is toggled', :vcr do
    test_filter_legend("service-area","San Mateo County, CA")
  end
  scenario 'when kind filter has no cached values and legend is toggled', :vcr do
    test_filter_legend("kind", "Human Services",13)
  end
  scenario 'when agency filter has no cached values and legend is toggled', :vcr do
    test_filter_legend("org-name")
  end

  # test filter fieldset toggle toggling across all filters
  scenario 'when location filter has no cached values and toggle is toggled', :vcr do
    test_filter_toggle("location")
  end
  scenario 'when service-area filter has no cached values and toggle is toggled', :vcr do
    test_filter_toggle("service-area","San Mateo County, CA")
  end
  scenario 'when kind filter has no cached values and toggle is toggled', :vcr do
    test_filter_toggle("kind", "Human Services",13)
  end
  scenario 'when agency filter has no cached values and toggle is toggled', :vcr do
    test_filter_toggle("org-name")
  end

  # test adding custom value to filters that accept custom values
  scenario 'when location filter has no cached values and custom value is added', :vcr do
    test_filter_custom_value("location")
  end
  scenario 'when agency filter has no cached values and custom value is added', :vcr do
    test_filter_custom_value("org-name")
  end

  # test adding custom value to filters and retrieving no results
  scenario 'when location filter has custom value and no results', :vcr do
    test_filter_custom_value_no_results("location","San Mateo, CA")
  end
  scenario 'when agency filter has custom value and no results', :vcr do
    test_filter_custom_value_no_results("org-name","United States Government")
  end

  # test adding custom value to filters and retrieving results
  scenario 'when location filter has custom value and has results', :vcr do
    name = "location"
    field = "San Mateo, CA"
    set_filter(name,field)
    fill_in('keyword', :with => '') # clear keyword

    find('#update-btn').click

    within("##{name}-options") do
      find(".closed").click
      find(".available-options").should have_css(".toggle-group", :count=>3)
      page.should_not have_css("##{name}-option-input")
    end
  end
  scenario 'when agency filter has custom value and has results', :vcr do
    name = "org-name"
    field = "United States Government"
    set_filter(name,field)
    fill_in('keyword', :with => '') # clear keyword

    find('#update-btn').click

    within("##{name}-options") do
      find(".closed").click
      find(".available-options").should have_css(".toggle-group", :count=>3)
      page.should_not have_css("##{name}-option-input")
    end
  end

  # test filter selection across all filters
  scenario 'when location filter has cached values and new option is selected', :vcr do
    fill_in('keyword', :with => '') # clear keyword
    find('#update-btn').click
    set_filter("location","San Francisco, CA",false)
    find('#update-btn').click
    expect(all("#location-options .current-option label").last).to have_content("San Francisco, CA")
  end
  scenario 'when service-area filter has cached values and new option is selected', :vcr do
    fill_in('keyword', :with => '') # clear keyword
    find('#update-btn').click
    set_filter("service-area","All",false)
    find('#update-btn').click
    expect(all("#service-area-options .current-option label").last).to have_content("All")
  end
  scenario 'when kind filter has cached values and new option is selected', :vcr do
    fill_in('keyword', :with => '') # clear keyword
    find('#update-btn').click
    set_filter("kind","Other",false)
    find('#update-btn').click
    expect(all("#kind-options .current-option label").last).to have_content("Other")
  end
  scenario 'when agency filter has cached values and new option is selected', :vcr do
    fill_in('keyword', :with => '') # clear keyword
{'fraction_non_alphanumeric': 0.11267281105990784, 'fraction_numerical': 0.0013824884792626728, 'mean_word_length': 4.148873072360617, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, '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': '3936023', 'n_tokens_mistral': 2507, 'n_tokens_neox': 2484, 'n_words': 874}