@@ -14,7 +14,7 @@ def response
1414 transition path : :page1_path do
1515 button text : "Page 1"
1616 end
17- transition path : :page2_path do
17+ transition path : :page2_path , params : { some_other_param : "bar" } do
1818 button text : "Page 2"
1919 end
2020 end
@@ -37,6 +37,7 @@ def response
3737 div id : "my-div-on-page-1" do
3838 heading size : 2 , text : "This is Page 1"
3939 plain "#{ DateTime . now . strftime ( '%Q' ) } "
40+ plain "#{ context [ :params ] [ :some_param ] } "
4041 end
4142 }
4243 end
@@ -53,6 +54,7 @@ def response
5354 end
5455 transition path : :page1_path do
5556 button text : "Back to Page 1"
57+ plain "#{ context [ :params ] [ :some_other_param ] } "
5658 end
5759 }
5860 end
@@ -157,6 +159,53 @@ def page2
157159 expect ( page ) . to have_selector ( "body.not-reloaded" )
158160 end
159161
162+ it "Example 3 - Perform transition from one page to another without page reload when using page history buttons" do
163+
164+ visit "/my_example_app/page1?some_param=foo"
165+
166+ expect ( page ) . to have_content ( "My Example App Layout" )
167+ expect ( page ) . to have_button ( "Page 1" )
168+ expect ( page ) . to have_button ( "Page 2" )
169+
170+ expect ( page ) . to have_content ( "This is Page 1" )
171+ expect ( page ) . to have_content ( "foo" )
172+ expect ( page ) . not_to have_content ( "This is Page 2" )
173+
174+ element = page . find ( "#my-div-on-page-1" )
175+ first_content_on_page_1 = element . text
176+
177+ page . evaluate_script ( 'document.body.classList.add("not-reloaded")' )
178+ expect ( page ) . to have_selector ( "body.not-reloaded" )
179+
180+ click_button ( "Page 2" )
181+
182+ expect ( page ) . to have_content ( "My Example App Layout" )
183+ expect ( page ) . not_to have_content ( "This is Page 1" )
184+ expect ( page ) . not_to have_content ( "foo" )
185+ expect ( page ) . to have_content ( "This is Page 2" )
186+ expect ( page ) . to have_content ( "bar" )
187+ expect ( page ) . to have_selector ( "body.not-reloaded" )
188+
189+ page . go_back
190+
191+ expect ( page ) . to have_content ( "My Example App Layout" )
192+ expect ( page ) . to have_content ( "This is Page 1" )
193+ expect ( page ) . to have_content ( "foo" )
194+ expect ( page ) . not_to have_content ( "This is Page 2" )
195+ expect ( page ) . not_to have_content ( "bar" )
196+ expect ( page ) . to have_selector ( "body.not-reloaded" )
197+ expect ( page ) . to have_no_content ( first_content_on_page_1 )
198+
199+ page . go_forward
200+
201+ expect ( page ) . to have_content ( "My Example App Layout" )
202+ expect ( page ) . not_to have_content ( "This is Page 1" )
203+ expect ( page ) . not_to have_content ( "foo" )
204+ expect ( page ) . to have_content ( "This is Page 2" )
205+ expect ( page ) . to have_content ( "bar" )
206+ expect ( page ) . to have_selector ( "body.not-reloaded" )
207+ end
208+
160209 # supposed to work, but doesn't. Suspect Vue is the culprint here
161210 # it "Example 2 - Perform transition from one page to another by providing route as string (not recommended)" do
162211 #
0 commit comments