Sha256: 37cf2bbd2ca332dd022a459a6de028842b6e23aaec68b90f4491c986db810ca7

Contents?: true

Size: 1.92 KB

Versions: 17

Compression:

Stored size: 1.92 KB

Contents

require 'test_helper'

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

      class Paginate
        include Query
        include Pagination
        document Search::Storefront
      end

      def test_page
        assert_equal(1, Paginate.new.page)
        assert_equal(2, Paginate.new(page: 2).page)
        assert_equal(1, Paginate.new(page: -1).page)
        assert_equal(1, Paginate.new(page: 0).page)
        assert_equal(1, Paginate.new(page: 'asdf').page)
      end

      def test_per_page
        assert_equal(Workarea.config.per_page, Paginate.new.per_page)
        assert_equal(2, Paginate.new(per_page: 2).per_page)
        assert_equal(Workarea.config.per_page, Paginate.new(per_page: -1).per_page)
        assert_equal(Workarea.config.per_page, Paginate.new(per_page: 0).per_page)
        assert_equal(3, Paginate.new(per_page: '3').per_page)
        assert_equal(Workarea.config.per_page, Paginate.new(per_page: 'asdf').per_page)
      end

      def test_from
        Workarea.config.per_page = 30
        assert_equal(0, Paginate.new(page: 1).from)

        Workarea.config.per_page = 15
        assert_equal(15, Paginate.new(page: 2).from)

        Workarea.config.per_page = 45
        assert_equal(90, Paginate.new(page: 3).from)
      end

      def test_size
        Workarea.config.per_page = 30

        search = Paginate.new(page: 2)
        assert_equal(30, search.size)
      end

      def test_each_by
        product_one = create_product(name: 'Foo 1')
        product_two = create_product(name: 'Foo 2')

        IndexProduct.perform(product_one)
        IndexProduct.perform(product_two)

        [1, 2, 3].each do |by|
          calls = []
          Paginate.new(q: 'foo').each_by(by) { |p| calls << p }

          assert_equal(2, calls.size)
          assert(calls.include?(product_one))
          assert(calls.include?(product_two))
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
workarea-core-3.5.27 test/queries/workarea/search/pagination_test.rb
workarea-core-3.5.26 test/queries/workarea/search/pagination_test.rb
workarea-core-3.5.25 test/queries/workarea/search/pagination_test.rb
workarea-core-3.5.23 test/queries/workarea/search/pagination_test.rb
workarea-core-3.5.22 test/queries/workarea/search/pagination_test.rb
workarea-core-3.5.21 test/queries/workarea/search/pagination_test.rb
workarea-core-3.5.20 test/queries/workarea/search/pagination_test.rb
workarea-core-3.5.19 test/queries/workarea/search/pagination_test.rb
workarea-core-3.5.18 test/queries/workarea/search/pagination_test.rb
workarea-core-3.5.17 test/queries/workarea/search/pagination_test.rb
workarea-core-3.5.16 test/queries/workarea/search/pagination_test.rb
workarea-core-3.5.15 test/queries/workarea/search/pagination_test.rb
workarea-core-3.5.14 test/queries/workarea/search/pagination_test.rb
workarea-core-3.5.13 test/queries/workarea/search/pagination_test.rb
workarea-core-3.5.12 test/queries/workarea/search/pagination_test.rb
workarea-core-3.5.11 test/queries/workarea/search/pagination_test.rb
workarea-core-3.5.10 test/queries/workarea/search/pagination_test.rb