Sha256: 27c35c536b7e06f84372299a497f615ca9d616f3ca880a233ab96bffe26b84ad

Contents?: true

Size: 1.71 KB

Versions: 62

Compression:

Stored size: 1.71 KB

Contents

require 'test_helper'

module Workarea
  module Search
    class FacetMatchesTest < TestCase
      include TestCase::SearchIndexing

      setup :set_search

      def set_search
        create_product(filters: { color: %w(Red Green Blue), size: 'M' })
        create_product(filters: { color: %w(Green Blue), size: 'S' })
        create_product(filters: { color: %w(Blue), size: 'Blue' })

        BulkIndexProducts.perform
        @search = Search::ProductSearch.new(q: '*', terms_facets: %w(color size))
      end

      def test_matches_has_params_for_matching_queries
        facet_matches = FacetMatches.new(
          @search.params.merge(q: 'red dress'),
          @search.facets
        )
        assert_equal({ 'color' => ['Red'] }, facet_matches.matches)

        facet_matches = FacetMatches.new(
          @search.params.merge(q: 'dresses that are red'),
          @search.facets
        )
        assert_equal({ 'color' => ['Red'] }, facet_matches.matches)

        facet_matches = FacetMatches.new(
          @search.params.merge(q: 'some red dresses'),
          @search.facets
        )
        assert_equal({ 'color' => ['Red'] }, facet_matches.matches)
      end

      def test_params_merges_with_matches
        params = @search.params.merge(q: 'red dresses')

        facet_matches = FacetMatches.new(params, @search.facets)
        assert_equal('red dresses', facet_matches.params[:q])
        assert_equal(['Red'], facet_matches.params[:color])
      end

      def test_matches_only_returns_params_when_there_is_one_match
        params = @search.params.merge(q: 'blue dresses')

        facet_matches = FacetMatches.new(params, @search.facets)
        assert_equal(params, facet_matches.params)
      end
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
workarea-core-3.5.27 test/queries/workarea/search/facet_matches_test.rb
workarea-core-3.5.26 test/queries/workarea/search/facet_matches_test.rb
workarea-core-3.4.45 test/queries/workarea/search/facet_matches_test.rb
workarea-core-3.5.25 test/queries/workarea/search/facet_matches_test.rb
workarea-core-3.5.23 test/queries/workarea/search/facet_matches_test.rb
workarea-core-3.4.44 test/queries/workarea/search/facet_matches_test.rb
workarea-core-3.5.22 test/queries/workarea/search/facet_matches_test.rb
workarea-core-3.4.43 test/queries/workarea/search/facet_matches_test.rb
workarea-core-3.5.21 test/queries/workarea/search/facet_matches_test.rb
workarea-core-3.4.42 test/queries/workarea/search/facet_matches_test.rb
workarea-core-3.5.20 test/queries/workarea/search/facet_matches_test.rb
workarea-core-3.4.41 test/queries/workarea/search/facet_matches_test.rb
workarea-core-3.5.19 test/queries/workarea/search/facet_matches_test.rb
workarea-core-3.4.40 test/queries/workarea/search/facet_matches_test.rb
workarea-core-3.5.18 test/queries/workarea/search/facet_matches_test.rb
workarea-core-3.4.39 test/queries/workarea/search/facet_matches_test.rb
workarea-core-3.5.17 test/queries/workarea/search/facet_matches_test.rb
workarea-core-3.4.38 test/queries/workarea/search/facet_matches_test.rb
workarea-core-3.5.16 test/queries/workarea/search/facet_matches_test.rb
workarea-core-3.4.37 test/queries/workarea/search/facet_matches_test.rb