Skip to content

Commit 04921ac

Browse files
committed
Merge branch 'main' into add-tests-and-kwargs-support-for-remaining-actions
2 parents 5c6ce8f + 210cbba commit 04921ac

File tree

4 files changed

+52
-0
lines changed

4 files changed

+52
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ import 'controllers'
149149

150150
### Browser History Actions
151151

152+
* `turbo_stream.history_back(**attributes)`
153+
* `turbo_stream.history_forward(**attributes)`
152154
* `turbo_stream.history_go(delta = 0, **attributes)`
153155
* `turbo_stream.push_state(url, title = "", state = {}, **attributes)`
154156
* `turbo_stream.replace_state(url, title = "", state = {}, **attributes)`

lib/turbo_power/stream_helper.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,14 @@ def set_title(title = nil, **attributes)
184184

185185
# Browser History Actions
186186

187+
def history_back(**attributes)
188+
custom_action :history_back, attributes: attributes
189+
end
190+
191+
def history_forward(**attributes)
192+
custom_action :history_forward, attributes: attributes
193+
end
194+
187195
def history_go(delta = 0, **attributes)
188196
custom_action :history_go, attributes: attributes.reverse_merge(delta: delta)
189197
end
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# frozen_string_literal: true
2+
3+
require "test_helper"
4+
5+
module TurboPower
6+
module StreamHelper
7+
class HistoryBackTest < StreamHelperTestCase
8+
test "history_back" do
9+
stream = %(<turbo-stream action="history_back"><template></template></turbo-stream>)
10+
11+
assert_dom_equal stream, turbo_stream.history_back
12+
end
13+
14+
test "history_back with additional arguments" do
15+
stream = %(<turbo-stream action="history_back" something="else"><template></template></turbo-stream>)
16+
17+
assert_dom_equal stream, turbo_stream.history_back(something: "else")
18+
end
19+
end
20+
end
21+
end
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# frozen_string_literal: true
2+
3+
require "test_helper"
4+
5+
module TurboPower
6+
module StreamHelper
7+
class HistoryForwardTest < StreamHelperTestCase
8+
test "history_forward" do
9+
stream = %(<turbo-stream action="history_forward"><template></template></turbo-stream>)
10+
11+
assert_dom_equal stream, turbo_stream.history_forward
12+
end
13+
14+
test "history_forward with additional attributes" do
15+
stream = %(<turbo-stream action="history_forward" something="else"><template></template></turbo-stream>)
16+
17+
assert_dom_equal stream, turbo_stream.history_forward(something: "else")
18+
end
19+
end
20+
end
21+
end

0 commit comments

Comments
 (0)