kaminari--kaminari/kaminari-core/test/requests/navigation_test.rb

81 lines
1.7 KiB
Ruby
Raw Normal View History

2016-10-11 20:44:41 +00:00
# frozen_string_literal: true
2018-11-10 22:54:07 +00:00
2016-11-19 07:51:21 +00:00
require 'test_helper'
2011-02-07 13:37:31 +00:00
2016-11-19 07:51:21 +00:00
class NavigationTest < Test::Unit::TestCase
include Capybara::DSL
setup do
2016-11-22 13:16:57 +00:00
1.upto(100) {|i| User.create! name: "user#{'%03d' % i}" }
Capybara.current_driver = :rack_test
2011-02-08 02:21:39 +00:00
end
2016-11-19 07:51:21 +00:00
teardown do
Capybara.reset_sessions!
Capybara.use_default_driver
User.delete_all
end
test 'navigating by pagination links' do
2011-12-10 17:56:19 +00:00
visit '/users'
2011-02-08 02:21:39 +00:00
assert page.has_no_content? 'previous page'
assert page.has_content? 'next page'
2011-02-08 02:25:43 +00:00
within 'nav.pagination' do
2011-02-08 02:21:39 +00:00
within 'span.page.current' do
2016-11-19 07:51:21 +00:00
assert page.has_content? '1'
2011-02-08 02:21:39 +00:00
end
within 'span.next' do
click_link 'Next '
2011-02-08 02:21:39 +00:00
end
end
assert page.has_content? 'previous page'
assert page.has_content? 'next page'
2011-02-08 02:25:43 +00:00
within 'nav.pagination' do
2011-02-08 02:21:39 +00:00
within 'span.page.current' do
2016-11-19 07:51:21 +00:00
assert page.has_content? '2'
2011-02-08 02:21:39 +00:00
end
within 'span.last' do
click_link 'Last »'
2011-02-08 02:21:39 +00:00
end
end
assert page.has_content? 'previous page'
assert page.has_no_content? 'next page'
2011-02-08 02:25:43 +00:00
within 'nav.pagination' do
2011-02-08 02:21:39 +00:00
within 'span.page.current' do
2016-11-19 07:51:21 +00:00
assert page.has_content? '4'
2011-02-08 02:21:39 +00:00
end
within 'span.prev' do
click_link ' Prev'
2011-02-08 02:21:39 +00:00
end
end
assert page.has_content? 'previous page'
assert page.has_content? 'next page'
2011-02-08 02:25:43 +00:00
within 'nav.pagination' do
2011-02-08 02:21:39 +00:00
within 'span.page.current' do
2016-11-19 07:51:21 +00:00
assert page.has_content? '3'
2011-02-08 02:21:39 +00:00
end
within 'span.first' do
click_link '« First'
end
end
within 'nav.pagination' do
within 'span.page.current' do
2016-11-19 07:51:21 +00:00
assert page.has_content? '1'
end
2011-02-08 02:21:39 +00:00
end
within 'div.info' do
assert page.has_text? 'Displaying users 1'
end
2011-02-07 13:37:31 +00:00
end
end