Sha256: f355070d0a26a824b45104b852fcf3d9234283d99b112c6cc1e3802e1cc66067

Contents?: true

Size: 1.52 KB

Versions: 34

Compression:

Stored size: 1.52 KB

Contents

require 'test_helper'

module Workarea
  module Storefront
    class CategoryViewModelTest < TestCase
      include SearchIndexing
      include ProductBrowsingViewModelTest

      def product_browsing_view_model_class
        CategoryViewModel
      end

      setup :set_category

      def set_category
        @category = create_category(default_sort: 'top_sellers')
      end

      def test_browser_title
        create_taxon(name: 'Foo', navigable: @category)
        view_model = CategoryViewModel.new(@category)
        assert_equal('Home - Foo', view_model.browser_title)
      end

      def test_products
        products = [
          create_product(name: 'Foo 1', filters: { 'color' => 'Red' }),
          create_product(name: 'Foo 2', filters: { 'color' => 'Green' })
        ]

        BulkIndexProducts.perform_by_models(products)
        @category.product_rules.create!(
          name: 'search',
          operator: 'equals',
          value: 'foo'
        )
        view_model = CategoryViewModel.new(@category)

        assert_equal('top_sellers', view_model.sort)

        assert(
          view_model
            .products
            .first
            .instance_of?(ProductViewModel)
        )
      end

      def test_sorts
        view_model = CategoryViewModel.new(@category)
        refute_includes(view_model.sorts.map(&:last), :featured)

        @category.product_ids = %w(1 2 3)
        view_model = CategoryViewModel.new(@category)
        assert_includes(view_model.sorts.map(&:last), :featured)
      end
    end
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
workarea-storefront-3.4.45 test/view_models/workarea/storefront/category_view_model_test.rb
workarea-storefront-3.4.44 test/view_models/workarea/storefront/category_view_model_test.rb
workarea-storefront-3.4.43 test/view_models/workarea/storefront/category_view_model_test.rb
workarea-storefront-3.4.42 test/view_models/workarea/storefront/category_view_model_test.rb
workarea-storefront-3.4.41 test/view_models/workarea/storefront/category_view_model_test.rb
workarea-storefront-3.4.40 test/view_models/workarea/storefront/category_view_model_test.rb
workarea-storefront-3.4.39 test/view_models/workarea/storefront/category_view_model_test.rb
workarea-storefront-3.4.38 test/view_models/workarea/storefront/category_view_model_test.rb
workarea-storefront-3.4.37 test/view_models/workarea/storefront/category_view_model_test.rb
workarea-storefront-3.4.36 test/view_models/workarea/storefront/category_view_model_test.rb
workarea-storefront-3.4.35 test/view_models/workarea/storefront/category_view_model_test.rb
workarea-storefront-3.4.34 test/view_models/workarea/storefront/category_view_model_test.rb
workarea-storefront-3.4.33 test/view_models/workarea/storefront/category_view_model_test.rb
workarea-storefront-3.4.32 test/view_models/workarea/storefront/category_view_model_test.rb
workarea-storefront-3.4.31 test/view_models/workarea/storefront/category_view_model_test.rb
workarea-storefront-3.4.30 test/view_models/workarea/storefront/category_view_model_test.rb
workarea-storefront-3.4.29 test/view_models/workarea/storefront/category_view_model_test.rb
workarea-storefront-3.4.28 test/view_models/workarea/storefront/category_view_model_test.rb
workarea-storefront-3.4.27 test/view_models/workarea/storefront/category_view_model_test.rb
workarea-storefront-3.4.26 test/view_models/workarea/storefront/category_view_model_test.rb