2016-10-11 20:44:41 +00:00
|
|
|
|
# frozen_string_literal: true
|
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}" }
|
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
|
|
|
|
|
2016-11-23 11:15:56 +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
|
2011-02-27 11:28:00 +00:00
|
|
|
|
click_link 'Next ›'
|
2011-02-08 02:21:39 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2016-11-23 11:15:56 +00:00
|
|
|
|
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
|
2011-02-27 11:28:00 +00:00
|
|
|
|
within 'span.last' do
|
|
|
|
|
click_link 'Last »'
|
2011-02-08 02:21:39 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2016-11-23 11:15:56 +00:00
|
|
|
|
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
|
2011-02-27 11:28:00 +00:00
|
|
|
|
click_link '‹ Prev'
|
2011-02-08 02:21:39 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2016-11-23 11:15:56 +00:00
|
|
|
|
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
|
2011-02-27 11:28:00 +00:00
|
|
|
|
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'
|
2011-02-27 11:28:00 +00:00
|
|
|
|
end
|
2011-02-08 02:21:39 +00:00
|
|
|
|
end
|
2016-11-23 11:10:28 +00:00
|
|
|
|
|
|
|
|
|
within 'div.info' do
|
|
|
|
|
assert page.has_text? 'Displaying users 1'
|
|
|
|
|
end
|
2011-02-07 13:37:31 +00:00
|
|
|
|
end
|
|
|
|
|
end
|