<commit_before>require 'test_helper'

class FacetedBrowsingTest < ActionController::IntegrationTest

  ASSETS_WITH_FACET = Seek::Config.facet_enable_for_pages.keys

  def setup
    User.current_user = Factory(:user, :login => 'test')
    post '/session', :login => 'test', :password => '<PASSWORD>'
  end

  test 'turn off the faceted browsing' do
    with_config_value :faceted_browsing_enabled,false do
      ASSETS_WITH_FACET.each do |type_name|
        get "/#{type_name}"
        assert_select "table[id='exhibit']", :count => 0
        assert_select "div.alphabetcal_pagination"
      end
    end

  end

  test 'turn on the faceted browsing' do
    with_config_value :faceted_browsing_enabled,true do
      ASSETS_WITH_FACET.each do |type_name|
        with_config_value :facet_enable_for_pages,{type_name=>true} do
          get "/#{type_name}"
          assert_select "div[id='exhibit']"
          assert_select "div.alphabetcal_pagination", :count => 0
        end
      end
    end

  end

  test 'partly turn on the faceted browsing' do
    with_config_value :faceted_browsing_enabled,true do
      facet_enabled_pages = {}
      facet_disabled_pages = {}
      Seek::Config.facet_enable_for_pages.each do |key,value|
        if value == true
          facet_enabled_pages[key] = value
        else
          facet_disabled_pages[key] = value
        end
      end

      assert !facet_enabled_pages.blank?
      assert !facet_disabled_pages.blank?

      facet_enabled_pages.keys.each do |type_name|
        get "/#{type_name}"
        assert_select "div[id='exhibit']"
        assert_select "div.alphabetcal_pagination", :count => 0
      end

      facet_disabled_pages.keys.each do |type_name|
        get "/#{type_name}"
        assert_select "div[id='exhibit']", :count => 0
        assert_select "div.alphabetcal_pagination"
      end
    end

  end

  test 'facet config for Assay' do
    Factory(:assay, :policy => Factory(:public_policy))
    with_config_value :faceted_browsing_enabled,true do
      get "/assays"
      record_body
      assert_select "div[data-ex-facet-class='TextSearch']", :count => 1
      assert_select "div[data-ex-role='facet'][data-ex-expression='.organism']", :count => 1
      assert_select "div[data-ex-role='facet'][data-ex-expression='.assay_type'][data-ex-facet-class='Exhibit.HierarchicalFacet']", :count => 1
      #these facets are not defined in test/fixtures/files/facets.txt
      assert_select "div[data-ex-role='facet'][data-ex-expression='.technology_type'][data-ex-facet-class='Exhibit.HierarchicalFacet']", :count => 0
      assert_select "div[data-ex-role='facet'][data-ex-expression='.project']", :count => 0
    end



  end

  test 'content config for Assay' do
    with_config_value :faceted_browsing_enabled,true do
      get "/assays"
      assert_select "div[data-ex-role='exhibit-view'][data-ex-label='Tiles'][data-ex-paginate='true'][data-ex-page-size='10']", :count => 1
    end
  end

  test 'show only authorized items' do
    with_config_value :faceted_browsing_enabled,true do
      assay1 = Factory(:assay, :policy => Factory(:public_policy))
      assay2 = Factory(:assay, :policy => Factory(:private_policy))
      assert assay1.can_view?
      assert !assay2.can_view?

      xhr(:post, "/assays/items_for_result",{:items => "Assay_#{assay1.id},Assay_#{assay2.id}", :item_ids => [assay1.id,assay2.id]})
      items_for_result =  ActiveSupport::JSON.decode(@response.body)['items_for_result']
      assert items_for_result.include?(assay1.title)
      assert !items_for_result.include?(assay2.title)
    end
  end<commit_msg>fix a fb test because of changing the config file path<commit_after>require 'test_helper'

class FacetedBrowsingTest < ActionController::IntegrationTest

  ASSETS_WITH_FACET = Seek::Config.facet_enable_for_pages.keys

  def setup
    User.current_user = Factory(:user, :login => 'test')
    post '/session', :login => 'test', :password => '<PASSWORD>'
  end

  test 'turn off the faceted browsing' do
    with_config_value :faceted_browsing_enabled,false do
      ASSETS_WITH_FACET.each do |type_name|
        get "/#{type_name}"
        assert_select "table[id='exhibit']", :count => 0
        assert_select "div.alphabetcal_pagination"
      end
    end

  end

  test 'turn on the faceted browsing' do
    with_config_value :faceted_browsing_enabled,true do
      ASSETS_WITH_FACET.each do |type_name|
        with_config_value :facet_enable_for_pages,{type_name=>true} do
          get "/#{type_name}"
          assert_select "div[id='exhibit']"
          assert_select "div.alphabetcal_pagination", :count => 0
        end
      end
    end

  end

  test 'partly turn on the faceted browsing' do
    with_config_value :faceted_browsing_enabled,true do
      facet_enabled_pages = {}
      facet_disabled_pages = {}
      Seek::Config.facet_enable_for_pages.each do |key,value|
        if value == true
          facet_enabled_pages[key] = value
        else
          facet_disabled_pages[key] = value
        end
      end

      assert !facet_enabled_pages.blank?
      assert !facet_disabled_pages.blank?

      facet_enabled_pages.keys.each do |type_name|
        get "/#{type_name}"
        assert_select "div[id='exhibit']"
        assert_select "div.alphabetcal_pagination", :count => 0
      end

      facet_disabled_pages.keys.each do |type_name|
        get "/#{type_name}"
        assert_select "div[id='exhibit']", :count => 0
        assert_select "div.alphabetcal_pagination"
      end
    end

  end

  test 'facet config for Assay' do
    Factory(:assay, :policy => Factory(:public_policy))
    with_config_value :faceted_browsing_enabled,true do
      get "/assays"
      record_body
      assert_select "div[data-ex-facet-class='TextSearch']", :count => 1
      assert_select "div[data-ex-role='facet'][data-ex-expression='.organism']", :count => 1
      assert_select "div[data-ex-role='facet'][data-ex-expression='.assay_type'][data-ex-facet-class='Exhibit.HierarchicalFacet']", :count => 1
      assert_select "div[data-ex-role='facet'][data-ex-expression='.technology_type'][data-ex-facet-class='Exhibit.HierarchicalFacet']", :count => 1
      assert_select "div[data-ex-role='facet'][data-ex-expression='.project']", :count => 1
      assert_select "div[data-ex-role='facet'][data-ex-expression='.project']", :count => 1
      assert_select "div[data-ex-role='facet'][data-ex-expression='.for_test']", :count => 0
    end
  end

  test 'content config for Assay' do
    with_config_value :faceted_browsing_enabled,true do
      get "/assays"
      assert_select "div[data-ex-role='exhibit-view'][data-ex-label='Tiles'][data-ex-paginate='true'][data-ex-page-size='10']", :count => 1
    end
  end

  test 'show only authorized items' do
    with_config_value :faceted_browsing_enabled,true do
      assay1 = Factory(:assay, :policy => Factory(:public_policy))
      assay2 = Factory(:assay, :policy => Factory(:private_policy))
      assert assay1.can_view?
      assert !assay2.can_view?

      xhr(:post, "/assays/items_for_result",{:items => "Assay_#{assay1.id},Assay_#{assay2.id}", :item_ids => [assay1.id,assay2.id]})
      items_for_result =  ActiveSupport::JSON.decode(@response.body)['items_for_result']
      assert items_for_result.include?(assay1.title)
      assert !items_for_result.include?(assay2.title)
    end
  end
{'fraction_non_alphanumeric': 0.12688288777310355, 'fraction_numerical': 0.006242366671190121, 'mean_word_length': 3.540973505853358, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 45, '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': '6190076', 'n_tokens_mistral': 2537, 'n_tokens_neox': 2452, 'n_words': 456}