Skip to content

Commit 4b1e7fc

Browse files
committed
Update tests
1 parent ce4d740 commit 4b1e7fc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+853
-677
lines changed

.simplecov

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ SimpleCov.start do
2727
add_group 'Calendar', %w[gem/lib/pagy/calendar
2828
gem/lib/pagy/extras/calendar.rb]
2929
add_group 'Keyset', %w[gem/lib/pagy/keyset.rb
30+
gem/lib/pagy/keyset_for_ui.rb
3031
gem/lib/pagy/keyset/active_record.rb
3132
gem/lib/pagy/keyset/sequel.rb
32-
gem/lib/pagy/extras/keyset.rb]
33+
gem/lib/pagy/extras/keyset.rb
34+
gem/lib/pagy/extras/keyset_for_ui.rb]
3335
add_group 'Tests', %w[test]
3436
end

e2e/cypress/e2e/demo.cy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ for (const path of paths) {
1919
testComboNav(app, "#combo-nav-js");
2020
testInfo(app, "#pagy-info", path);
2121
if (path === "/pagy") {
22-
testLimitSelector(app, "#limit-selector-js", path, true); // trim true
22+
testLimitSelector(app, "#limit-selector-js", path);
2323
}
2424
});
2525
}

e2e/cypress/e2e/rails.cy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ describe(`[${app}] Test helpers`, () => {
1010
testNav(app, "#nav", {pages: ["3"]});
1111
testNav(app, "#nav-js", {pages: ["3"]});
1212
testComboNav(app, "#combo-nav-js");
13-
testLimitSelector(app, "#limit-selector-js"); // no style, no trim
13+
testLimitSelector(app, "#limit-selector-js");
1414
testInfo(app, "#pagy-info");
1515
});

e2e/cypress/e2e/repro.cy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ describe(`[${app}] Test helpers`, () => {
1111
testNav(app, "#nav-js-responsive", {rjs: true});
1212
testComboNav(app, "#combo-nav-js");
1313
testInfo(app, "#pagy-info");
14-
testLimitSelector(app, "#limit-selector-js"); // no style, no trim
14+
testLimitSelector(app, "#limit-selector-js");
1515
});

e2e/snapshots.js

Lines changed: 159 additions & 177 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/helpers/nav_tests.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# frozen_string_literal: true
22

33
require 'pagy/extras/countless'
4+
require 'pagy/extras/keyset_for_ui'
45
require_relative '../mock_helpers/pagy_buggy'
56
require_relative '../mock_helpers/app'
7+
require_relative '../files/models'
68

79
module NavTests
810
def app
@@ -12,12 +14,15 @@ def app
1214
def nav_tests(prefix)
1315
method = :"pagy#{prefix}_nav"
1416
[1, 20, 50].each do |page|
15-
pagy = Pagy.new(count: 1000, page: page)
17+
pagy = Pagy.new(count: 1000, page: page)
1618
pagyx = Pagy.new(count: 1000, page: page)
1719
_(app.send(method, pagy)).must_rematch :"plain_#{page}"
1820
_(app.send(method, pagyx, id: 'test-nav-id', anchor_string: 'anchor_string')).must_rematch :"extras_#{page}"
1921
end
2022
_ { app.send(method, PagyBuggy.new(count: 100)) }.must_raise Pagy::InternalError
23+
pagyk = Pagy::KeysetForUI.new(Pet.order(:animal, :name, :id),
24+
page: ['key', 2, 2, ["cat", "Ella", 18], nil])
25+
_(app.send(method, pagyk)).must_rematch :keyset
2126
end
2227

2328
def nav_js_tests(prefix) # e.g. pagy_bootstrap_nav_js

test/mock_helpers/app.rb

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@
88

99
# Backend and Frontend poor man mock app
1010
class MockApp
11-
attr_reader :params, :request, :response
11+
attr_reader :request, :response
1212

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

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

2424
def test_i18n_call
@@ -29,6 +29,9 @@ def set_pagy_locale(locale) # rubocop:disable Naming/AccessorMethodName
2929
@pagy_locale = locale
3030
end
3131

32+
include Pagy::Backend
33+
include Pagy::Frontend
34+
3235
class Calendar < MockApp
3336
def pagy_calendar_period(collection)
3437
starting = collection.minimum(:time)

test/pagy/backend_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
_(pagy).must_be_instance_of Pagy
1818
_(pagy.count).must_equal 1000
1919
_(pagy.limit).must_equal Pagy::DEFAULT[:limit]
20-
_(pagy.page).must_equal app.params[:page]
20+
_(pagy.page).must_equal app.params[:page].to_i
2121
_(records.count).must_equal Pagy::DEFAULT[:limit]
2222
_(records).must_equal [41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60]
2323
end

test/pagy/extras/arel_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
_(pagy).must_be_instance_of Pagy
2020
_(pagy.count).must_equal 1000
2121
_(pagy.limit).must_equal Pagy::DEFAULT[:limit]
22-
_(pagy.page).must_equal app.params[:page]
22+
_(pagy.page).must_equal app.params[:page].to_i
2323
_(records.size).must_equal Pagy::DEFAULT[:limit]
2424
_(records).must_equal [41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60]
2525
end

test/pagy/extras/array_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
_(pagy).must_be_instance_of Pagy
1818
_(pagy.count).must_equal 1000
1919
_(pagy.limit).must_equal Pagy::DEFAULT[:limit]
20-
_(pagy.page).must_equal app.params[:page]
20+
_(pagy.page).must_equal app.params[:page].to_i
2121
_(records.count).must_equal Pagy::DEFAULT[:limit]
2222
_(records).must_equal [41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60]
2323
end

0 commit comments

Comments
 (0)