views: fix deprecated calls to ViewComponent#with_variant.
This commit is contained in:
@@ -1,12 +1,16 @@
|
||||
require "test_helper"
|
||||
|
||||
class PaginatorComponentTest < ViewComponent::TestCase
|
||||
def render_paginator(variant, records, page: 1, limit: 3, page_limit: 100)
|
||||
with_variant(variant) do
|
||||
records = records.paginate(page, limit: limit, page_limit: page_limit)
|
||||
params = ActionController::Parameters.new(controller: records.model_name.plural, action: :index)
|
||||
return render_inline(PaginatorComponent.new(records: records, params: params))
|
||||
end
|
||||
def render_sequential_paginator(records, page: 1, limit: 3, page_limit: 100)
|
||||
records = records.paginate(page, limit: limit, page_limit: page_limit)
|
||||
params = ActionController::Parameters.new(controller: records.model_name.plural, action: :index)
|
||||
return render_inline(SequentialPaginatorComponent.new(records: records, params: params))
|
||||
end
|
||||
|
||||
def render_numbered_paginator(records, page: 1, limit: 3, page_limit: 100)
|
||||
records = records.paginate(page, limit: limit, page_limit: page_limit)
|
||||
params = ActionController::Parameters.new(controller: records.model_name.plural, action: :index)
|
||||
return render_inline(NumberedPaginatorComponent.new(records: records, params: params))
|
||||
end
|
||||
|
||||
def assert_page(expected_page, link)
|
||||
@@ -24,14 +28,14 @@ class PaginatorComponentTest < ViewComponent::TestCase
|
||||
end
|
||||
|
||||
should "work with an aN page" do
|
||||
html = render_paginator(:sequential, Tag.all, page: "a#{@tags[5].id}", limit: 3)
|
||||
html = render_sequential_paginator(Tag.all, page: "a#{@tags[5].id}", limit: 3)
|
||||
|
||||
assert_page("a#{@tags[5+3].id}", html.css("a[rel=prev]"))
|
||||
assert_page("b#{@tags[5+1].id}", html.css("a[rel=next]"))
|
||||
end
|
||||
|
||||
should "work with a bN page" do
|
||||
html = render_paginator(:sequential, Tag.all, page: "b#{@tags[5].id}", limit: 3)
|
||||
html = render_sequential_paginator(Tag.all, page: "b#{@tags[5].id}", limit: 3)
|
||||
|
||||
assert_page("a#{@tags[5-1].id}", html.css("a[rel=prev]"))
|
||||
assert_page("b#{@tags[5-3].id}", html.css("a[rel=next]"))
|
||||
@@ -45,21 +49,21 @@ class PaginatorComponentTest < ViewComponent::TestCase
|
||||
end
|
||||
|
||||
should "work for page 1" do
|
||||
html = render_paginator(:numbered, Tag.all, page: 1, limit: 3)
|
||||
html = render_numbered_paginator(Tag.all, page: 1, limit: 3)
|
||||
|
||||
assert_css("span.paginator-prev")
|
||||
assert_page("2", html.css("a.paginator-next"))
|
||||
end
|
||||
|
||||
should "work for page 2" do
|
||||
html = render_paginator(:numbered, Tag.all, page: 2, limit: 3)
|
||||
html = render_numbered_paginator(Tag.all, page: 2, limit: 3)
|
||||
|
||||
assert_page("1", html.css("a.paginator-prev"))
|
||||
assert_page("3", html.css("a.paginator-next"))
|
||||
end
|
||||
|
||||
should "work for page 4" do
|
||||
html = render_paginator(:numbered, Tag.all, page: 4, limit: 3)
|
||||
html = render_numbered_paginator(Tag.all, page: 4, limit: 3)
|
||||
|
||||
assert_page("3", html.css("a.paginator-prev"))
|
||||
assert_css("span.paginator-next")
|
||||
@@ -68,7 +72,7 @@ class PaginatorComponentTest < ViewComponent::TestCase
|
||||
|
||||
context "for a search with zero results" do
|
||||
should "work for page 1" do
|
||||
html = render_paginator(:numbered, Tag.none, page: 1, limit: 3)
|
||||
html = render_numbered_paginator(Tag.none, page: 1, limit: 3)
|
||||
|
||||
assert_css("span.paginator-current", text: "1")
|
||||
assert_css("span.paginator-prev")
|
||||
@@ -81,7 +85,7 @@ class PaginatorComponentTest < ViewComponent::TestCase
|
||||
should "show the unlimited paginator" do
|
||||
@tags = Tag.all
|
||||
@tags.stubs(:total_count).returns(Float::INFINITY)
|
||||
html = render_paginator(:numbered, @tags, page: 1, limit: 200)
|
||||
html = render_numbered_paginator(@tags, page: 1, limit: 200)
|
||||
|
||||
assert_css("span.paginator-current", text: "1")
|
||||
assert_css("span.paginator-prev")
|
||||
|
||||
Reference in New Issue
Block a user