diff --git a/lib/pagy/extras/bootstrap.rb b/lib/pagy/extras/bootstrap.rb index 3a7442e99..ecde0d0c0 100644 --- a/lib/pagy/extras/bootstrap.rb +++ b/lib/pagy/extras/bootstrap.rb @@ -8,18 +8,20 @@ class Pagy # :nodoc: # The resulting code may not look very elegant, but produces the best benchmarks module BootstrapExtra # Pagination for bootstrap: it returns the html with the series of links to the pages - def pagy_bootstrap_nav(pagy, pagy_id: nil, link_extra: '', **vars) + def pagy_bootstrap_nav(pagy, pagy_id: nil, link_extra: '', + page_label: nil, page_i18n_key: nil, **vars) p_id = %( id="#{pagy_id}") if pagy_id link = pagy_link_proc(pagy, link_extra: %(class="page-link" #{link_extra})) - html = +%( +pagy/extras/bootstrap::#pagy_bootstrap_nav#test_0001_renders first page: + :plain: + :extras: diff --git a/test/pagy/extras/bulma_test.rb b/test/pagy/extras/bulma_test.rb index 20d1d87bc..197a729ad 100644 --- a/test/pagy/extras/bulma_test.rb +++ b/test/pagy/extras/bulma_test.rb @@ -8,22 +8,17 @@ describe 'pagy/extras/bulma' do let(:app) { MockApp.new } + include NavTests describe '#pagy_bulma_nav' do it 'renders first page' do - pagy = Pagy.new(size: [1, 4, 4, 1], count: 1000, page: 1) - _(app.pagy_bulma_nav(pagy, pagy_id: 'test-nav-id')).must_rematch - _(app.pagy_bulma_nav_js(pagy, pagy_id: 'test-nav-id', link_extra: 'link-extra')).must_rematch :extras + nav_check :pagy_bulma_nav, Pagy.new(size: [1, 4, 4, 1], count: 1000, page: 1) end it 'renders intermediate page' do - pagy = Pagy.new(size: [1, 4, 4, 1], count: 1000, page: 20) - _(app.pagy_bulma_nav(pagy)).must_rematch :plain - _(app.pagy_bulma_nav_js(pagy, pagy_id: 'test-nav-id', link_extra: 'link-extra')).must_rematch :extras + nav_check :pagy_bulma_nav, Pagy.new(size: [1, 4, 4, 1], count: 1000, page: 20) end it 'renders last page' do - pagy = Pagy.new(size: [1, 4, 4, 1], count: 1000, page: 50) - _(app.pagy_bulma_nav(pagy)).must_rematch :plain - _(app.pagy_bulma_nav_js(pagy, pagy_id: 'test-nav-id', link_extra: 'link-extra')).must_rematch :extras + nav_check :pagy_bulma_nav, Pagy.new(size: [1, 4, 4, 1], count: 1000, page: 50) end it 'should raise for wrong series' do _ { app.pagy_bulma_nav(PagyBuggy.new(count: 100)) }.must_raise Pagy::InternalError @@ -32,36 +27,21 @@ describe '#pagy_bulma_nav_js' do it 'renders first page' do - pagy = Pagy.new(size: [1, 4, 4, 1], count: 1000, page: 1) - _(app.pagy_bulma_nav_js(pagy)).must_rematch :plain - _(app.pagy_bulma_nav_js(pagy, pagy_id: 'test-nav-id', link_extra: 'link-extra', - steps: { 0 => [1, 2, 2, 1], 600 => [1, 3, 3, 1] })).must_rematch :extras + nav_js_check :pagy_bulma_nav_js, Pagy.new(size: [1, 4, 4, 1], count: 1000, page: 1) end it 'renders first page when used with Pagy::Countless' do require 'pagy/extras/countless' - pagy, = Pagy::Countless.new(page: 1).finalize(0) - _(app.pagy_bulma_nav_js(pagy)).must_rematch :plain - _(app.pagy_bulma_nav_js(pagy, pagy_id: 'test-nav-id', link_extra: 'link-extra', - steps: { 0 => [1, 2, 2, 1], 600 => [1, 3, 3, 1] })).must_rematch :extras + nav_js_check :pagy_bulma_nav_js, Pagy::Countless.new(page: 1).finalize(0) end it 'renders intermediate page' do - pagy = Pagy.new(size: [1, 4, 4, 1], count: 1000, page: 20) - _(app.pagy_bulma_nav_js(pagy)).must_rematch :plain - _(app.pagy_bulma_nav_js(pagy, pagy_id: 'test-nav-id', link_extra: 'link-extra', - steps: { 0 => [1, 2, 2, 1], 600 => [1, 3, 3, 1] })).must_rematch :extras + nav_js_check :pagy_bulma_nav_js, Pagy.new(size: [1, 4, 4, 1], count: 1000, page: 20) end it 'renders last page' do - pagy = Pagy.new(size: [1, 4, 4, 1], count: 1000, page: 50) - _(app.pagy_bulma_nav_js(pagy)).must_rematch :plain - _(app.pagy_bulma_nav_js(pagy, pagy_id: 'test-nav-id', link_extra: 'link-extra', - steps: { 0 => [1, 2, 2, 1], 600 => [1, 3, 3, 1] })).must_rematch :extras + nav_js_check :pagy_bulma_nav_js, Pagy.new(size: [1, 4, 4, 1], count: 1000, page: 50) end it 'renders with :steps' do - pagy = Pagy.new(count: 1000, page: 20, steps: { 0 => [1, 2, 2, 1], 500 => [2, 3, 3, 2] }) - _(app.pagy_bulma_nav_js(pagy)).must_rematch :plain - _(app.pagy_bulma_nav_js(pagy, pagy_id: 'test-nav-id', link_extra: 'link-extra', - steps: { 0 => [1, 2, 2, 1], 600 => [1, 3, 3, 1] })).must_rematch :extras + nav_js_check :pagy_bulma_nav_js, Pagy.new(count: 1000, page: 20, steps: { 0 => [1, 2, 2, 1], 500 => [2, 3, 3, 2] }) end it 'raises with missing step 0' do pagy = Pagy.new(count: 1000, page: 20, steps: { 0 => [1, 2, 2, 1], 600 => [1, 3, 3, 1] }) @@ -71,19 +51,13 @@ describe '#pagy_bulma_combo_nav_js' do it 'renders first page' do - pagy = Pagy.new(count: 103, page: 1) - _(app.pagy_bulma_combo_nav_js(pagy)).must_rematch :plain - _(app.pagy_bulma_combo_nav_js(pagy, pagy_id: 'test-nav-id', link_extra: 'link-extra')).must_rematch :extras + combo_nav_js_check :pagy_bulma_combo_nav_js, Pagy.new(count: 103, page: 1) end it 'renders intermediate page' do - pagy = Pagy.new(count: 103, page: 3) - _(app.pagy_bulma_combo_nav_js(pagy)).must_rematch :plain - _(app.pagy_bulma_combo_nav_js(pagy, pagy_id: 'test-nav-id', link_extra: 'link-extra')).must_rematch :extras + combo_nav_js_check :pagy_bulma_combo_nav_js, Pagy.new(count: 103, page: 3) end it 'renders last page' do - pagy = Pagy.new(count: 103, page: 6) - _(app.pagy_bulma_combo_nav_js(pagy)).must_rematch :plain - _(app.pagy_bulma_combo_nav_js(pagy, pagy_id: 'test-nav-id', link_extra: 'link-extra')).must_rematch :extras + combo_nav_js_check :pagy_bulma_combo_nav_js, Pagy.new(count: 103, page: 6) end end end diff --git a/test/pagy/extras/bulma_test.rb.rematch b/test/pagy/extras/bulma_test.rb.rematch index c027fe6d0..258f6c71b 100644 --- a/test/pagy/extras/bulma_test.rb.rematch +++ b/test/pagy/extras/bulma_test.rb.rematch @@ -1,4 +1,49 @@ --- +pagy/extras/bulma::#pagy_bulma_combo_nav_js#test_0002_renders intermediate page: + :plain: '' + :extras: '' +pagy/extras/bulma::#pagy_bulma_combo_nav_js#test_0001_renders first page: + :plain: '' + :extras: '' +pagy/extras/bulma::#pagy_bulma_combo_nav_js#test_0003_renders last page: + :plain: '' + :extras: '' pagy/extras/bulma::#pagy_bulma_nav#test_0002_renders intermediate page: :plain: - :extras: + :extras: pagy/extras/bulma::#pagy_bulma_nav#test_0001_renders first page: - ! '': - :extras: + :extras: pagy/extras/bulma::#pagy_bulma_nav#test_0003_renders last page: :plain: - :extras: -pagy/extras/bulma::#pagy_bulma_nav_js#test_0002_renders first page when used with Pagy::Countless: - :plain: - :extras: + :extras: pagy/extras/bulma::#pagy_bulma_nav_js#test_0004_renders last page: :plain: :extras: +pagy/extras/bulma::#pagy_bulma_nav_js#test_0002_renders first page when used with Pagy::Countless: + :plain: + :extras: pagy/extras/bulma::#pagy_bulma_nav_js#test_0005_renders with :steps: :plain: @@ -70,48 +149,3 @@ pagy/extras/bulma::#pagy_bulma_nav_js#test_0003_renders intermediate page: data-pagy="WyJuYXYiLHsiYmVmb3JlIjoiPGEgaHJlZj1cIi9mb28/cGFnZT0xOVwiICAgcmVsPVwicHJldlwiIGNsYXNzPVwicGFnaW5hdGlvbi1wcmV2aW91c1wiIGFyaWEtbGFiZWw9XCJwcmV2aW91cyBwYWdlXCI+JmxzYXF1bzsmbmJzcDtQcmV2PC9hPjxhIGhyZWY9XCIvZm9vP3BhZ2U9MjFcIiAgIHJlbD1cIm5leHRcIiBjbGFzcz1cInBhZ2luYXRpb24tbmV4dFwiIGFyaWEtbGFiZWw9XCJuZXh0IHBhZ2VcIj5OZXh0Jm5ic3A7JnJzYXF1bzs8L2E+PHVsIGNsYXNzPVwicGFnaW5hdGlvbi1saXN0XCI+IiwibGluayI6IjxsaT48YSBocmVmPVwiL2Zvbz9wYWdlPV9fcGFneV9wYWdlX19cIiAgIGNsYXNzPVwicGFnaW5hdGlvbi1saW5rXCIgYXJpYS1sYWJlbD1cImdvdG8gcGFnZSBfX3BhZ3lfcGFnZV9fXCI+X19wYWd5X2xhYmVsX188L2E+PC9saT4iLCJhY3RpdmUiOiI8bGk+PGEgaHJlZj1cIi9mb28/cGFnZT1fX3BhZ3lfcGFnZV9fXCIgICBjbGFzcz1cInBhZ2luYXRpb24tbGluayBpcy1jdXJyZW50XCIgYXJpYS1jdXJyZW50PVwicGFnZVwiIGFyaWEtbGFiZWw9XCJwYWdlIF9fcGFneV9wYWdlX19cIj5fX3BhZ3lfbGFiZWxfXzwvYT48L2xpPiIsImdhcCI6IjxsaT48c3BhbiBjbGFzcz1cInBhZ2luYXRpb24tZWxsaXBzaXNcIj4maGVsbGlwOzwvc3Bhbj48L2xpPiIsImFmdGVyIjoiPC91bD4ifSx7IjAiOlsxLCJnYXAiLDE2LDE3LDE4LDE5LCIyMCIsMjEsMjIsMjMsMjQsImdhcCIsNTBdfSxudWxsXQ=="> :extras: -pagy/extras/bulma::#pagy_bulma_combo_nav_js#test_0001_renders first page: - :plain: '' - :extras: '' -pagy/extras/bulma::#pagy_bulma_combo_nav_js#test_0002_renders intermediate page: - :plain: '' - :extras: '' -pagy/extras/bulma::#pagy_bulma_combo_nav_js#test_0003_renders last page: - :plain: '' - :extras: '' diff --git a/test/pagy/extras/foundation_test.rb b/test/pagy/extras/foundation_test.rb index 96b61962a..42394c017 100644 --- a/test/pagy/extras/foundation_test.rb +++ b/test/pagy/extras/foundation_test.rb @@ -8,22 +8,17 @@ describe 'pagy/extras/foundation' do let(:app) { MockApp.new } + include NavTests describe '#pagy_foundation_nav' do it 'renders first page' do - pagy = Pagy.new(size: [1, 4, 4, 1], count: 1000, page: 1) - _(app.pagy_foundation_nav(pagy)).must_rematch :plain - _(app.pagy_foundation_nav(pagy, pagy_id: 'test-nav-id', link_extra: 'link-extra')).must_rematch :extras + nav_check :pagy_foundation_nav, Pagy.new(size: [1, 4, 4, 1], count: 1000, page: 1) end it 'renders intermediate page' do - pagy = Pagy.new(size: [1, 4, 4, 1], count: 1000, page: 20) - _(app.pagy_foundation_nav(pagy)).must_rematch :plain - _(app.pagy_foundation_nav(pagy, pagy_id: 'test-nav-id', link_extra: 'link-extra')).must_rematch :extras + nav_check :pagy_foundation_nav, Pagy.new(size: [1, 4, 4, 1], count: 1000, page: 20) end it 'renders last page' do - pagy = Pagy.new(size: [1, 4, 4, 1], count: 1000, page: 50) - _(app.pagy_foundation_nav(pagy)).must_rematch :plain - _(app.pagy_foundation_nav(pagy, pagy_id: 'test-nav-id', link_extra: 'link-extra')).must_rematch :extras + nav_check :pagy_foundation_nav, Pagy.new(size: [1, 4, 4, 1], count: 1000, page: 50) end it 'should raise for wrong series' do _ { app.pagy_foundation_nav(PagyBuggy.new(count: 100)) }.must_raise Pagy::InternalError @@ -32,36 +27,21 @@ describe '#pagy_foundation_nav_js' do it 'renders first page' do - pagy = Pagy.new(size: [1, 4, 4, 1], count: 1000, page: 1) - _(app.pagy_foundation_nav_js(pagy)).must_rematch :plain - _(app.pagy_foundation_nav_js(pagy, pagy_id: 'test-nav-id', link_extra: 'link-extra', - steps: { 0 => [1, 2, 2, 1], 600 => [1, 3, 3, 1] })).must_rematch :extras + nav_js_check :pagy_foundation_nav_js, Pagy.new(size: [1, 4, 4, 1], count: 1000, page: 1) end it 'renders first page when used with Pagy::Countless' do require 'pagy/extras/countless' - pagy, = Pagy::Countless.new(page: 1).finalize(0) - _(app.pagy_foundation_nav_js(pagy)).must_rematch :plain - _(app.pagy_foundation_nav_js(pagy, pagy_id: 'test-nav-id', link_extra: 'link-extra', - steps: { 0 => [1, 2, 2, 1], 600 => [1, 3, 3, 1] })).must_rematch :extras + nav_js_check :pagy_foundation_nav_js, Pagy::Countless.new(page: 1).finalize(0) end it 'renders intermediate page' do - pagy = Pagy.new(size: [1, 4, 4, 1], count: 1000, page: 20) - _(app.pagy_foundation_nav_js(pagy)).must_rematch :plain - _(app.pagy_foundation_nav_js(pagy, pagy_id: 'test-nav-id', link_extra: 'link-extra', - steps: { 0 => [1, 2, 2, 1], 600 => [1, 3, 3, 1] })).must_rematch :extras + nav_js_check :pagy_foundation_nav_js, Pagy.new(size: [1, 4, 4, 1], count: 1000, page: 20) end it 'renders last page' do - pagy = Pagy.new(size: [1, 4, 4, 1], count: 1000, page: 50) - _(app.pagy_foundation_nav_js(pagy)).must_rematch :plain - _(app.pagy_foundation_nav_js(pagy, pagy_id: 'test-nav-id', link_extra: 'link-extra', - steps: { 0 => [1, 2, 2, 1], 600 => [1, 3, 3, 1] })).must_rematch :extras + nav_js_check :pagy_foundation_nav_js, Pagy.new(size: [1, 4, 4, 1], count: 1000, page: 50) end it 'renders with :steps' do - pagy = Pagy.new(count: 1000, page: 20, steps: { 0 => [1, 2, 2, 1], 500 => [2, 3, 3, 2] }) - _(app.pagy_foundation_nav_js(pagy)).must_rematch :plain - _(app.pagy_foundation_nav_js(pagy, pagy_id: 'test-nav-id', link_extra: 'link-extra', - steps: { 0 => [1, 2, 2, 1], 600 => [1, 3, 3, 1] })).must_rematch :extras + nav_js_check :pagy_foundation_nav_js, Pagy.new(count: 1000, page: 20, steps: { 0 => [1, 2, 2, 1], 500 => [2, 3, 3, 2] }) end it 'raises with missing step 0' do pagy = Pagy.new(count: 1000, page: 20, steps: { 0 => [1, 2, 2, 1], 600 => [1, 3, 3, 1] }) @@ -71,19 +51,13 @@ describe '#pagy_foundation_combo_nav_js' do it 'renders first page' do - pagy = Pagy.new(count: 103, page: 1) - _(app.pagy_foundation_combo_nav_js(pagy)).must_rematch :plain - _(app.pagy_foundation_combo_nav_js(pagy, pagy_id: 'test-nav-id', link_extra: 'link-extra')).must_rematch :extras + combo_nav_js_check :pagy_foundation_combo_nav_js, Pagy.new(count: 103, page: 1) end it 'renders intermediate page' do - pagy = Pagy.new(count: 103, page: 3) - _(app.pagy_foundation_combo_nav_js(pagy)).must_rematch :plain - _(app.pagy_foundation_combo_nav_js(pagy, pagy_id: 'test-nav-id', link_extra: 'link-extra')).must_rematch :extras + combo_nav_js_check :pagy_foundation_combo_nav_js, Pagy.new(count: 103, page: 3) end it 'renders last page' do - pagy = Pagy.new(count: 103, page: 6) - _(app.pagy_foundation_combo_nav_js(pagy)).must_rematch :plain - _(app.pagy_foundation_combo_nav_js(pagy, pagy_id: 'test-nav-id', link_extra: 'link-extra')).must_rematch :extras + combo_nav_js_check :pagy_foundation_combo_nav_js, Pagy.new(count: 103, page: 6) end end end diff --git a/test/pagy/extras/materialize_test.rb b/test/pagy/extras/materialize_test.rb index 9404083a3..7c1c0c21d 100644 --- a/test/pagy/extras/materialize_test.rb +++ b/test/pagy/extras/materialize_test.rb @@ -8,22 +8,17 @@ describe 'pagy/extras/materialize' do let(:app) { MockApp.new } + include NavTests describe '#pagy_materialize_nav' do it 'renders first page' do - pagy = Pagy.new(size: [1, 4, 4, 1], count: 1000, page: 1) - _(app.pagy_materialize_nav(pagy)).must_rematch :plain - _(app.pagy_materialize_nav(pagy, pagy_id: 'test-nav-id', link_extra: 'link-extra')).must_rematch :extras + nav_check :pagy_materialize_nav, Pagy.new(size: [1, 4, 4, 1], count: 1000, page: 1) end it 'renders intermediate page' do - pagy = Pagy.new(size: [1, 4, 4, 1], count: 1000, page: 20) - _(app.pagy_materialize_nav(pagy)).must_rematch :plain - _(app.pagy_materialize_nav(pagy, pagy_id: 'test-nav-id', link_extra: 'link-extra')).must_rematch :extras + nav_check :pagy_materialize_nav, Pagy.new(size: [1, 4, 4, 1], count: 1000, page: 20) end it 'renders last page' do - pagy = Pagy.new(size: [1, 4, 4, 1], count: 1000, page: 50) - _(app.pagy_materialize_nav(pagy)).must_rematch :plain - _(app.pagy_materialize_nav(pagy, pagy_id: 'test-nav-id', link_extra: 'link-extra')).must_rematch :extras + nav_check :pagy_materialize_nav, Pagy.new(size: [1, 4, 4, 1], count: 1000, page: 50) end it 'should raise for wrong series' do _ { app.pagy_materialize_nav(PagyBuggy.new(count: 100)) }.must_raise Pagy::InternalError @@ -32,36 +27,21 @@ describe '#pagy_materialize_nav_js' do it 'renders first page' do - pagy = Pagy.new(size: [1, 4, 4, 1], count: 1000, page: 1) - _(app.pagy_materialize_nav_js(pagy)).must_rematch :plain - _(app.pagy_materialize_nav_js(pagy, pagy_id: 'test-nav-id', link_extra: 'link-extra', - steps: { 0 => [1, 2, 2, 1], 600 => [1, 3, 3, 1] })).must_rematch :extras + nav_js_check :pagy_materialize_nav_js, Pagy.new(size: [1, 4, 4, 1], count: 1000, page: 1) end it 'renders first page when used with Pagy::Countless' do require 'pagy/extras/countless' - pagy, = Pagy::Countless.new(page: 1).finalize(0) - _(app.pagy_materialize_nav_js(pagy)).must_rematch :plain - _(app.pagy_materialize_nav_js(pagy, pagy_id: 'test-nav-id', link_extra: 'link-extra', - steps: { 0 => [1, 2, 2, 1], 600 => [1, 3, 3, 1] })).must_rematch :extras + nav_js_check :pagy_materialize_nav_js, Pagy::Countless.new(page: 1).finalize(0) end it 'renders intermediate page' do - pagy = Pagy.new(size: [1, 4, 4, 1], count: 1000, page: 20) - _(app.pagy_materialize_nav_js(pagy)).must_rematch :plain - _(app.pagy_materialize_nav_js(pagy, pagy_id: 'test-nav-id', link_extra: 'link-extra', - steps: { 0 => [1, 2, 2, 1], 600 => [1, 3, 3, 1] })).must_rematch :extras + nav_js_check :pagy_materialize_nav_js, Pagy.new(size: [1, 4, 4, 1], count: 1000, page: 20) end it 'renders last page' do - pagy = Pagy.new(size: [1, 4, 4, 1], count: 1000, page: 50) - _(app.pagy_materialize_nav_js(pagy)).must_rematch :plain - _(app.pagy_materialize_nav_js(pagy, pagy_id: 'test-nav-id', link_extra: 'link-extra', - steps: { 0 => [1, 2, 2, 1], 600 => [1, 3, 3, 1] })).must_rematch :extras + nav_js_check :pagy_materialize_nav_js, Pagy.new(size: [1, 4, 4, 1], count: 1000, page: 50) end it 'renders with :steps' do - pagy = Pagy.new(count: 1000, page: 20, steps: { 0 => [1, 2, 2, 1], 500 => [2, 3, 3, 2] }) - _(app.pagy_materialize_nav_js(pagy)).must_rematch :plain - _(app.pagy_materialize_nav_js(pagy, pagy_id: 'test-nav-id', link_extra: 'link-extra', - steps: { 0 => [1, 2, 2, 1], 600 => [1, 3, 3, 1] })).must_rematch :extras + nav_js_check :pagy_materialize_nav_js, Pagy.new(count: 1000, page: 20, steps: { 0 => [1, 2, 2, 1], 500 => [2, 3, 3, 2] }) end it 'raises with missing step 0' do pagy = Pagy.new(count: 1000, page: 20, steps: { 0 => [1, 2, 2, 1], 600 => [1, 3, 3, 1] }) @@ -71,19 +51,13 @@ describe '#pagy_materialize_combo_nav_js' do it 'renders first page' do - pagy = Pagy.new(count: 103, page: 1) - _(app.pagy_materialize_combo_nav_js(pagy)).must_rematch :plain - _(app.pagy_materialize_combo_nav_js(pagy, pagy_id: 'test-nav-id', link_extra: 'link-extra')).must_rematch :extras + combo_nav_js_check :pagy_materialize_combo_nav_js, Pagy.new(count: 103, page: 1) end it 'renders intermediate page' do - pagy = Pagy.new(count: 103, page: 3) - _(app.pagy_materialize_combo_nav_js(pagy)).must_rematch :plain - _(app.pagy_materialize_combo_nav_js(pagy, pagy_id: 'test-nav-id', link_extra: 'link-extra')).must_rematch :extras + combo_nav_js_check :pagy_materialize_combo_nav_js, Pagy.new(count: 103, page: 3) end it 'renders last page' do - pagy = Pagy.new(count: 103, page: 6) - _(app.pagy_materialize_combo_nav_js(pagy)).must_rematch :plain - _(app.pagy_materialize_combo_nav_js(pagy, pagy_id: 'test-nav-id', link_extra: 'link-extra')).must_rematch :extras + combo_nav_js_check :pagy_materialize_combo_nav_js, Pagy.new(count: 103, page: 6) end end end diff --git a/test/pagy/extras/navs_test.rb b/test/pagy/extras/navs_test.rb index cd975dd20..66de2d909 100644 --- a/test/pagy/extras/navs_test.rb +++ b/test/pagy/extras/navs_test.rb @@ -7,47 +7,32 @@ describe 'pagy/extras/navs' do let(:app) { MockApp.new } + include NavTests describe '#pagy_nav_js' do it 'renders first page' do pagy = Pagy.new(size: [1, 4, 4, 1], count: 1000, page: 1) - _(app.pagy_nav_js(pagy)).must_rematch :plain - _(app.pagy_nav_js(pagy, pagy_id: 'test-nav-id', link_extra: 'link-extra', - steps: { 0 => [1, 2, 2, 1], 600 => [1, 3, 3, 1] })).must_rematch :extras + nav_js_check(:pagy_nav_js, pagy) end it 'renders single page when used with Pagy::Countless' do require 'pagy/extras/countless' pagy, = Pagy::Countless.new(page: 1).finalize(0) - _(app.pagy_nav_js(pagy)).must_rematch :plain - _(app.pagy_nav_js(pagy, pagy_id: 'test-nav-id', link_extra: 'link-extra', - steps: { 0 => [1, 2, 2, 1], 600 => [1, 3, 3, 1] })).must_rematch :extras + nav_js_check(:pagy_nav_js, pagy) end it 'renders first page of multiple when used with Pagy::Countless' do require 'pagy/extras/countless' - pagy, = Pagy::Countless.new(page: 1).finalize(23) - _(app.pagy_nav_js(pagy)).must_rematch :plain - _(app.pagy_nav_js(pagy, pagy_id: 'test-nav-id', link_extra: 'link-extra', - steps: { 0 => [1, 2, 2, 1], 600 => [1, 3, 3, 1] })).must_rematch :extras + nav_js_check :pagy_nav_js, Pagy::Countless.new(page: 1).finalize(23) end it 'renders intermediate page' do - pagy = Pagy.new(size: [1, 4, 4, 1], count: 1000, page: 20) - _(app.pagy_nav_js(pagy)).must_rematch :plain - _(app.pagy_nav_js(pagy, pagy_id: 'test-nav-id', link_extra: 'link-extra', - steps: { 0 => [1, 2, 2, 1], 600 => [1, 3, 3, 1] })).must_rematch :extras + nav_js_check :pagy_nav_js, Pagy.new(size: [1, 4, 4, 1], count: 1000, page: 20) end it 'renders last page' do - pagy = Pagy.new(size: [1, 4, 4, 1], count: 1000, page: 50) - _(app.pagy_nav_js(pagy)).must_rematch :plain - _(app.pagy_nav_js(pagy, pagy_id: 'test-nav-id', link_extra: 'link-extra', - steps: { 0 => [1, 2, 2, 1], 600 => [1, 3, 3, 1] })).must_rematch :extras + nav_js_check :pagy_nav_js, Pagy.new(size: [1, 4, 4, 1], count: 1000, page: 50) end it 'renders with :steps' do - pagy = Pagy.new(count: 1000, page: 20, steps: { 0 => [1, 2, 2, 1], 500 => [2, 3, 3, 2] }) - _(app.pagy_nav_js(pagy)).must_rematch :plain - _(app.pagy_nav_js(pagy, pagy_id: 'test-nav-id', link_extra: 'link-extra', - steps: { 0 => [1, 2, 2, 1], 600 => [1, 3, 3, 1] })).must_rematch :extras + nav_js_check :pagy_nav_js, Pagy.new(count: 1000, page: 20, steps: { 0 => [1, 2, 2, 1], 500 => [2, 3, 3, 2] }) end it 'raises with missing step 0' do pagy = Pagy.new(count: 1000, page: 20, steps: { 0 => [1, 2, 2, 1], 600 => [1, 3, 3, 1] }) @@ -57,19 +42,13 @@ describe '#pagy_combo_nav_js' do it 'renders first page' do - pagy = Pagy.new(count: 103, page: 1) - _(app.pagy_combo_nav_js(pagy)).must_rematch :plain - _(app.pagy_combo_nav_js(pagy, pagy_id: 'test-nav-id', link_extra: 'link-extra')).must_rematch :extras + combo_nav_js_check :pagy_combo_nav_js, Pagy.new(count: 103, page: 1) end it 'renders intermediate page' do - pagy = Pagy.new(count: 103, page: 3) - _(app.pagy_combo_nav_js(pagy)).must_rematch :plain - _(app.pagy_combo_nav_js(pagy, pagy_id: 'test-nav-id', link_extra: 'link-extra')).must_rematch :extras + combo_nav_js_check :pagy_combo_nav_js, Pagy.new(count: 103, page: 3) end it 'renders last page' do - pagy = Pagy.new(count: 103, page: 6) - _(app.pagy_combo_nav_js(pagy)).must_rematch :plain - _(app.pagy_combo_nav_js(pagy, pagy_id: 'test-nav-id', link_extra: 'link-extra')).must_rematch :extras + combo_nav_js_check :pagy_combo_nav_js, Pagy.new(count: 103, page: 6) end end end diff --git a/test/pagy/extras/semantic_test.rb b/test/pagy/extras/semantic_test.rb index 638cb95bd..0d6a5e03b 100644 --- a/test/pagy/extras/semantic_test.rb +++ b/test/pagy/extras/semantic_test.rb @@ -8,22 +8,17 @@ describe 'pagy/extras/semantic' do let(:app) { MockApp.new } + include NavTests describe '#pagy_semantic_nav' do it 'renders first page' do - pagy = Pagy.new(size: [1, 4, 4, 1], count: 1000, page: 1) - _(app.pagy_semantic_nav(pagy)).must_rematch :plain - _(app.pagy_semantic_nav(pagy, pagy_id: 'test-nav-id', link_extra: 'link-extra')).must_rematch :extras + nav_check :pagy_semantic_nav, Pagy.new(size: [1, 4, 4, 1], count: 1000, page: 1) end it 'renders intermediate page' do - pagy = Pagy.new(size: [1, 4, 4, 1], count: 1000, page: 20) - _(app.pagy_semantic_nav(pagy)).must_rematch :plain - _(app.pagy_semantic_nav(pagy, pagy_id: 'test-nav-id', link_extra: 'link-extra')).must_rematch :extras + nav_check :pagy_semantic_nav, Pagy.new(size: [1, 4, 4, 1], count: 1000, page: 20) end it 'renders last page' do - pagy = Pagy.new(size: [1, 4, 4, 1], count: 1000, page: 50) - _(app.pagy_semantic_nav(pagy)).must_rematch :plain - _(app.pagy_semantic_nav(pagy, pagy_id: 'test-nav-id', link_extra: 'link-extra')).must_rematch :extras + nav_check :pagy_semantic_nav, Pagy.new(size: [1, 4, 4, 1], count: 1000, page: 50) end it 'should raise for wrong series' do _ { app.pagy_semantic_nav(PagyBuggy.new(count: 100)) }.must_raise Pagy::InternalError @@ -32,36 +27,21 @@ describe '#pagy_semantic_nav_js' do it 'renders first page' do - pagy = Pagy.new(size: [1, 4, 4, 1], count: 1000, page: 1) - _(app.pagy_semantic_nav_js(pagy)).must_rematch :plain - _(app.pagy_semantic_nav_js(pagy, pagy_id: 'test-nav-id', link_extra: 'link-extra', - steps: { 0 => [1, 2, 2, 1], 600 => [1, 3, 3, 1] })).must_rematch :extras + nav_js_check :pagy_semantic_nav_js, Pagy.new(size: [1, 4, 4, 1], count: 1000, page: 1) end it 'renders first page when used with Pagy::Countless' do require 'pagy/extras/countless' - pagy, = Pagy::Countless.new(page: 1).finalize(0) - _(app.pagy_semantic_nav_js(pagy)).must_rematch :plain - _(app.pagy_semantic_nav_js(pagy, pagy_id: 'test-nav-id', link_extra: 'link-extra', - steps: { 0 => [1, 2, 2, 1], 600 => [1, 3, 3, 1] })).must_rematch :extras + nav_js_check :pagy_semantic_nav_js, Pagy::Countless.new(page: 1).finalize(0) end it 'renders intermediate page' do - pagy = Pagy.new(size: [1, 4, 4, 1], count: 1000, page: 20) - _(app.pagy_semantic_nav_js(pagy)).must_rematch :plain - _(app.pagy_semantic_nav_js(pagy, pagy_id: 'test-nav-id', link_extra: 'link-extra', - steps: { 0 => [1, 2, 2, 1], 600 => [1, 3, 3, 1] })).must_rematch :extras + nav_js_check :pagy_semantic_nav_js, Pagy.new(size: [1, 4, 4, 1], count: 1000, page: 20) end it 'renders last page' do - pagy = Pagy.new(size: [1, 4, 4, 1], count: 1000, page: 50) - _(app.pagy_semantic_nav_js(pagy)).must_rematch :plain - _(app.pagy_semantic_nav_js(pagy, pagy_id: 'test-nav-id', link_extra: 'link-extra', - steps: { 0 => [1, 2, 2, 1], 600 => [1, 3, 3, 1] })).must_rematch :extras + nav_js_check :pagy_semantic_nav_js, Pagy.new(size: [1, 4, 4, 1], count: 1000, page: 50) end it 'renders with :steps' do - pagy = Pagy.new(count: 1000, page: 20, steps: { 0 => [1, 2, 2, 1], 500 => [2, 3, 3, 2] }) - _(app.pagy_semantic_nav_js(pagy)).must_rematch :plain - _(app.pagy_semantic_nav_js(pagy, pagy_id: 'test-nav-id', link_extra: 'link-extra', - steps: { 0 => [1, 2, 2, 1], 600 => [1, 3, 3, 1] })).must_rematch :extras + nav_js_check :pagy_semantic_nav_js, Pagy.new(count: 1000, page: 20, steps: { 0 => [1, 2, 2, 1], 500 => [2, 3, 3, 2] }) end it 'raises with missing step 0' do pagy = Pagy.new(count: 1000, page: 20, steps: { 0 => [1, 2, 2, 1], 600 => [1, 3, 3, 1] }) @@ -71,19 +51,13 @@ describe '#pagy_semantic_combo_nav_js' do it 'renders first page' do - pagy = Pagy.new(count: 103, page: 1) - _(app.pagy_semantic_combo_nav_js(pagy)).must_rematch :plain - _(app.pagy_semantic_combo_nav_js(pagy, pagy_id: 'test-nav-id', link_extra: 'link-extra')).must_rematch :extras + combo_nav_js_check :pagy_semantic_combo_nav_js, Pagy.new(count: 103, page: 1) end it 'renders intermediate page' do - pagy = Pagy.new(count: 103, page: 3) - _(app.pagy_semantic_combo_nav_js(pagy)).must_rematch :plain - _(app.pagy_semantic_combo_nav_js(pagy, pagy_id: 'test-nav-id', link_extra: 'link-extra')).must_rematch :extras + combo_nav_js_check :pagy_semantic_combo_nav_js, Pagy.new(count: 103, page: 3) end it 'renders last page' do - pagy = Pagy.new(count: 103, page: 6) - _(app.pagy_semantic_combo_nav_js(pagy)).must_rematch :plain - _(app.pagy_semantic_combo_nav_js(pagy, pagy_id: 'test-nav-id', link_extra: 'link-extra')).must_rematch :extras + combo_nav_js_check :pagy_semantic_combo_nav_js, Pagy.new(count: 103, page: 6) end end end diff --git a/test/pagy/extras/trim_test.rb b/test/pagy/extras/trim_test.rb index 95fcbe49e..f5d715f7a 100644 --- a/test/pagy/extras/trim_test.rb +++ b/test/pagy/extras/trim_test.rb @@ -30,11 +30,12 @@ pagy = Pagy.new(count: 1000, page: page) link = app.pagy_link_proc(pagy) - _(link.call(page)).must_equal("#{page}") + aria = 'aria-current="page" ' if pagy.page == page + _(link.call(page)).must_equal("#{page}") pagy = Pagy.new(count: 1000, page: page, trim_extra: false) link = app.pagy_link_proc(pagy) - _(link.call(page)).must_equal("#{page}") + _(link.call(page)).must_equal("#{page}") end end end diff --git a/test/pagy/extras/uikit_test.rb b/test/pagy/extras/uikit_test.rb index 5aaf2ebbb..997df04d6 100644 --- a/test/pagy/extras/uikit_test.rb +++ b/test/pagy/extras/uikit_test.rb @@ -8,22 +8,17 @@ describe 'pagy/extras/uikit' do let(:app) { MockApp.new } + include NavTests describe '#pagy_uikit_nav' do it 'renders first page' do - pagy = Pagy.new(size: [1, 4, 4, 1], count: 1000, page: 1) - _(app.pagy_uikit_nav(pagy)).must_rematch :plain - _(app.pagy_uikit_nav(pagy, pagy_id: 'test-nav-id', link_extra: 'link-extra')).must_rematch :extras + nav_check :pagy_uikit_nav, Pagy.new(size: [1, 4, 4, 1], count: 1000, page: 1) end it 'renders intermediate page' do - pagy = Pagy.new(size: [1, 4, 4, 1], count: 1000, page: 20) - _(app.pagy_uikit_nav(pagy)).must_rematch :plain - _(app.pagy_uikit_nav(pagy, pagy_id: 'test-nav-id', link_extra: 'link-extra')).must_rematch :extras + nav_check :pagy_uikit_nav, Pagy.new(size: [1, 4, 4, 1], count: 1000, page: 20) end it 'renders last page' do - pagy = Pagy.new(size: [1, 4, 4, 1], count: 1000, page: 50) - _(app.pagy_uikit_nav(pagy)).must_rematch :plain - _(app.pagy_uikit_nav(pagy, pagy_id: 'test-nav-id', link_extra: 'link-extra')).must_rematch :extras + nav_check :pagy_uikit_nav, Pagy.new(size: [1, 4, 4, 1], count: 1000, page: 50) end it 'should raise for wrong series' do _ { app.pagy_uikit_nav(PagyBuggy.new(count: 100)) }.must_raise Pagy::InternalError @@ -32,36 +27,21 @@ describe '#pagy_uikit_nav_js' do it 'renders first page' do - pagy = Pagy.new(size: [1, 4, 4, 1], count: 1000, page: 1) - _(app.pagy_uikit_nav_js(pagy)).must_rematch :plain - _(app.pagy_uikit_nav_js(pagy, pagy_id: 'test-nav-id', link_extra: 'link-extra', - steps: { 0 => [1, 2, 2, 1], 600 => [1, 3, 3, 1] })).must_rematch :extras + nav_js_check :pagy_uikit_nav_js, Pagy.new(size: [1, 4, 4, 1], count: 1000, page: 1) end it 'renders first page when used with Pagy::Countless' do require 'pagy/extras/countless' - pagy, = Pagy::Countless.new(page: 1).finalize(0) - _(app.pagy_uikit_nav_js(pagy)).must_rematch :plain - _(app.pagy_uikit_nav_js(pagy, pagy_id: 'test-nav-id', link_extra: 'link-extra', - steps: { 0 => [1, 2, 2, 1], 600 => [1, 3, 3, 1] })).must_rematch :extras + nav_js_check :pagy_uikit_nav_js, Pagy::Countless.new(page: 1).finalize(0) end it 'renders intermediate page' do - pagy = Pagy.new(size: [1, 4, 4, 1], count: 1000, page: 20) - _(app.pagy_uikit_nav_js(pagy)).must_rematch :plain - _(app.pagy_uikit_nav_js(pagy, pagy_id: 'test-nav-id', link_extra: 'link-extra', - steps: { 0 => [1, 2, 2, 1], 600 => [1, 3, 3, 1] })).must_rematch :extras + nav_js_check :pagy_uikit_nav_js, Pagy.new(size: [1, 4, 4, 1], count: 1000, page: 20) end it 'renders last page' do - pagy = Pagy.new(size: [1, 4, 4, 1], count: 1000, page: 50) - _(app.pagy_uikit_nav_js(pagy)).must_rematch :plain - _(app.pagy_uikit_nav_js(pagy, pagy_id: 'test-nav-id', link_extra: 'link-extra', - steps: { 0 => [1, 2, 2, 1], 600 => [1, 3, 3, 1] })).must_rematch :extras + nav_js_check :pagy_uikit_nav_js, Pagy.new(size: [1, 4, 4, 1], count: 1000, page: 50) end it 'renders with :steps' do - pagy = Pagy.new(count: 1000, page: 20, steps: { 0 => [1, 2, 2, 1], 500 => [2, 3, 3, 2] }) - _(app.pagy_uikit_nav_js(pagy)).must_rematch :plain - _(app.pagy_uikit_nav_js(pagy, pagy_id: 'test-nav-id', link_extra: 'link-extra', - steps: { 0 => [1, 2, 2, 1], 600 => [1, 3, 3, 1] })).must_rematch :extras + nav_js_check :pagy_uikit_nav_js, Pagy.new(count: 1000, page: 20, steps: { 0 => [1, 2, 2, 1], 500 => [2, 3, 3, 2] }) end it 'raises with missing step 0' do pagy = Pagy.new(count: 1000, page: 20, steps: { 0 => [1, 2, 2, 1], 600 => [1, 3, 3, 1] }) @@ -71,19 +51,13 @@ describe '#pagy_uikit_combo_nav' do it 'renders first page' do - pagy = Pagy.new(count: 1000, page: 1) - _(app.pagy_uikit_combo_nav_js(pagy)).must_rematch :plain - _(app.pagy_uikit_combo_nav_js(pagy, pagy_id: 'test-nav-id', link_extra: 'link-extra')).must_rematch :extras + combo_nav_js_check :pagy_uikit_combo_nav_js, Pagy.new(count: 1000, page: 1) end it 'renders intermediate page' do - pagy = Pagy.new(count: 1000, page: 20) - _(app.pagy_uikit_combo_nav_js(pagy)).must_rematch :plain - _(app.pagy_uikit_combo_nav_js(pagy, pagy_id: 'test-nav-id', link_extra: 'link-extra')).must_rematch :extras + combo_nav_js_check :pagy_uikit_combo_nav_js, Pagy.new(count: 1000, page: 20) end it 'renders last page' do - pagy = Pagy.new(count: 1000, page: 50) - _(app.pagy_uikit_combo_nav_js(pagy)).must_rematch :plain - _(app.pagy_uikit_combo_nav_js(pagy, pagy_id: 'test-nav-id', link_extra: 'link-extra')).must_rematch :extras + combo_nav_js_check :pagy_uikit_combo_nav_js, Pagy.new(count: 1000, page: 50) end end end diff --git a/test/pagy/frontend_test.rb b/test/pagy/frontend_test.rb index 73e40e3cd..e5f818cf6 100644 --- a/test/pagy/frontend_test.rb +++ b/test/pagy/frontend_test.rb @@ -51,7 +51,7 @@ def i18n_load(*locales) describe '#pagy_link_proc' do it 'renders with extras' do pagy = Pagy.new count: 103, page: 1 - _(app.pagy_link_proc(pagy, link_extra: "X").call(1)).must_equal '1' + _(app.pagy_link_proc(pagy, link_extra: "X").call(3)).must_equal '3' end end diff --git a/test/test_helper.rb b/test/test_helper.rb index 44d534c36..b41e22382 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -16,13 +16,5 @@ require 'pagy' require 'minitest/autorun' -module PagyCalendarWarningFilter - def warn(message, category: nil, **kwargs) - if message.match?('Calendar#page_at') - # ignore - else - super - end - end -end -Warning.extend PagyCalendarWarningFilter +require_relative 'helper/warning_filters' +require_relative 'helper/nav_tests'