Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ddnexus committed Dec 26, 2024
1 parent c2d429c commit 17a00a7
Show file tree
Hide file tree
Showing 39 changed files with 865 additions and 670 deletions.
4 changes: 3 additions & 1 deletion .simplecov
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ SimpleCov.start do
add_group 'Calendar', %w[gem/lib/pagy/calendar
gem/lib/pagy/extras/calendar.rb]
add_group 'Keyset', %w[gem/lib/pagy/keyset.rb
gem/lib/pagy/keyset_for_ui.rb
gem/lib/pagy/keyset/active_record.rb
gem/lib/pagy/keyset/sequel.rb
gem/lib/pagy/extras/keyset.rb]
gem/lib/pagy/extras/keyset.rb
gem/lib/pagy/extras/keyset_for_ui.rb]
add_group 'Tests', %w[test]
end
2 changes: 1 addition & 1 deletion e2e/cypress/e2e/demo.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ for (const path of paths) {
testComboNav(app, "#combo-nav-js");
testInfo(app, "#pagy-info", path);
if (path === "/pagy") {
testLimitSelector(app, "#limit-selector-js", path, true); // trim true
testLimitSelector(app, "#limit-selector-js", path);
}
});
}
2 changes: 1 addition & 1 deletion e2e/cypress/e2e/rails.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ describe(`[${app}] Test helpers`, () => {
testNav(app, "#nav", {pages: ["3"]});
testNav(app, "#nav-js", {pages: ["3"]});
testComboNav(app, "#combo-nav-js");
testLimitSelector(app, "#limit-selector-js"); // no style, no trim
testLimitSelector(app, "#limit-selector-js");
testInfo(app, "#pagy-info");
});
2 changes: 1 addition & 1 deletion e2e/cypress/e2e/repro.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ describe(`[${app}] Test helpers`, () => {
testNav(app, "#nav-js-responsive", {rjs: true});
testComboNav(app, "#combo-nav-js");
testInfo(app, "#pagy-info");
testLimitSelector(app, "#limit-selector-js"); // no style, no trim
testLimitSelector(app, "#limit-selector-js");
});
336 changes: 159 additions & 177 deletions e2e/snapshots.js

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion test/helpers/nav_tests.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# frozen_string_literal: true

require 'pagy/extras/countless'
require 'pagy/extras/keyset_for_ui'
require_relative '../mock_helpers/pagy_buggy'
require_relative '../mock_helpers/app'
require_relative '../files/models'

module NavTests
def app
Expand All @@ -12,12 +14,16 @@ def app
def nav_tests(prefix)
method = :"pagy#{prefix}_nav"
[1, 20, 50].each do |page|
pagy = Pagy.new(count: 1000, page: page)
pagy = Pagy.new(count: 1000, page: page)
pagyx = Pagy.new(count: 1000, page: page)
_(app.send(method, pagy)).must_rematch :"plain_#{page}"
_(app.send(method, pagyx, id: 'test-nav-id', anchor_string: 'anchor_string')).must_rematch :"extras_#{page}"
end
_ { app.send(method, PagyBuggy.new(count: 100)) }.must_raise Pagy::InternalError
pagyk = Pagy::KeysetForUI.new(Pet.order(:animal, :name, :id),
cutoffs: ['key', 2, ["cat", "Ella", 18], nil],
page: 2)
_(app.send(method, pagyk)).must_rematch :keyset
end

def nav_js_tests(prefix) # e.g. pagy_bootstrap_nav_js
Expand Down
21 changes: 12 additions & 9 deletions test/mock_helpers/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@

# Backend and Frontend poor man mock app
class MockApp
attr_reader :params, :request, :response
attr_reader :request, :response

include Pagy::Backend
include Pagy::Frontend
def initialize(url: 'http://example.com:3000/foo', params: { page: 3 }, cookie: nil)
env = Rack::MockRequest.env_for(url, params: params)
env["HTTP_COOKIE"] = cookie if cookie
@request = Rack::Request.new(env)
@response = Rack::Response.new
end

# App params are merged into the @request.params (and are all strings)
# @params are taken from @request.params and merged with app params (which fixes symbols and strings in params)
def initialize(url: 'http://example.com:3000/foo', params: { page: 3 })
@request = Rack::Request.new(Rack::MockRequest.env_for(url, params: params))
@params = ActiveSupport::HashWithIndifferentAccess.new(@request.params).merge(params)
@response = Rack::Response.new
def params
ActiveSupport::HashWithIndifferentAccess.new(@request.params)
end

def test_i18n_call
Expand All @@ -29,6 +29,9 @@ def set_pagy_locale(locale) # rubocop:disable Naming/AccessorMethodName
@pagy_locale = locale
end

include Pagy::Backend
include Pagy::Frontend

class Calendar < MockApp
def pagy_calendar_period(collection)
starting = collection.minimum(:time)
Expand Down
2 changes: 1 addition & 1 deletion test/pagy/backend_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
_(pagy).must_be_instance_of Pagy
_(pagy.count).must_equal 1000
_(pagy.limit).must_equal Pagy::DEFAULT[:limit]
_(pagy.page).must_equal app.params[:page]
_(pagy.page).must_equal app.params[:page].to_i
_(records.count).must_equal Pagy::DEFAULT[:limit]
_(records).must_equal [41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60]
end
Expand Down
2 changes: 1 addition & 1 deletion test/pagy/extras/arel_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
_(pagy).must_be_instance_of Pagy
_(pagy.count).must_equal 1000
_(pagy.limit).must_equal Pagy::DEFAULT[:limit]
_(pagy.page).must_equal app.params[:page]
_(pagy.page).must_equal app.params[:page].to_i
_(records.size).must_equal Pagy::DEFAULT[:limit]
_(records).must_equal [41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60]
end
Expand Down
2 changes: 1 addition & 1 deletion test/pagy/extras/array_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
_(pagy).must_be_instance_of Pagy
_(pagy.count).must_equal 1000
_(pagy.limit).must_equal Pagy::DEFAULT[:limit]
_(pagy.page).must_equal app.params[:page]
_(pagy.page).must_equal app.params[:page].to_i
_(records.count).must_equal Pagy::DEFAULT[:limit]
_(records).must_equal [41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60]
end
Expand Down
1 change: 1 addition & 0 deletions test/pagy/extras/bootstrap_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require_relative '../../test_helper'
require_relative '../../helpers/nav_tests'

EXTRA = 'bootstrap'
PREFIX = '_bootstrap'
Expand Down
Loading

0 comments on commit 17a00a7

Please sign in to comment.