22
33class PaginationTest < ActionDispatch ::IntegrationTest
44
5- test "shows pagination and its usable" do
6-
5+ def setup
6+ BlogPost . destroy_all
77 50 . times do
88 BlogPost . create! ( {
99 title : SecureRandom . uuid ,
@@ -12,20 +12,65 @@ class PaginationTest < ActionDispatch::IntegrationTest
1212 published_at : Time . current ,
1313 } )
1414 end
15+ end
1516
17+ def teardown
18+ BlogPost . destroy_all
19+ end
20+
21+ test "shows pagination and its usable" do
1622 sign_in_dummy_administrator!
1723 visit ( "/admin/blog_posts" )
1824 assert page . has_content? ( "Next" )
1925 assert page . has_content? ( "Last" )
2026 assert page . has_content? ( "3" )
21- visit ( "/admin/blog_posts?page =3" )
27+ visit ( "/admin/blog_posts?p =3" )
2228 assert page . has_content? ( "Next" )
2329 assert page . has_content? ( "Last" )
2430 assert page . has_content? ( "First" )
2531 assert page . has_content? ( "Prev" )
32+ end
2633
27- BlogPost . destroy_all
34+ test "after paginating index, should retain page on edit and back with crumb" do
35+ sign_in_dummy_administrator!
36+ visit ( "/admin/blog_posts?p=3" )
37+ first ( ".button.-edit" ) . click # Open the editor form for a random blog post
38+ first ( ".crumb a" ) . click
39+ assert page . current_url . include? ( "p=3" ) , "page should be retained"
40+ end
41+
42+ test "after paginating index, should retain page on edit and back with button" do
43+ sign_in_dummy_administrator!
44+ visit ( "/admin/blog_posts?p=3" )
45+ first ( ".button.-edit" ) . click # Open the editor form for a random blog post
46+ first ( ".button.-cancel" ) . click
47+ assert page . current_url . include? ( "p=3" ) , "page should be retained"
48+ end
2849
50+ test "after paginating index, should retain page on edit and save" do
51+ sign_in_dummy_administrator!
52+ visit ( "/admin/blog_posts?p=3" )
53+ first ( ".button.-edit" ) . click # Open the editor form for a random blog post
54+ first ( ".button.-save" ) . click
55+ assert page . current_url . include? ( "p=3" ) , "page should be retained"
56+ end
57+
58+ test "after paginating index, should retain page on edit and failed validation" do
59+ sign_in_dummy_administrator!
60+ visit ( "/admin/blog_posts?p=3" )
61+ first ( ".button.-edit" ) . click # Open the editor form for a random blog post
62+ fill_in ( "blog_post[title]" , with :"" )
63+ first ( ".button.-save" ) . click
64+ first ( ".button.-cancel" ) . click
65+ assert page . current_url . include? ( "p=3" ) , "page should be retained"
66+ end
67+
68+ test "after paginating index, should NOT retain page on save and review" do
69+ sign_in_dummy_administrator!
70+ visit ( "/admin/blog_posts?p=3" )
71+ first ( ".button.-edit" ) . click # Open the editor form for a random blog post
72+ first ( ".button.-save-and-review" ) . click
73+ assert page . current_url . exclude? ( "p=3" ) , "page should not have been retained"
2974 end
3075
3176end
0 commit comments