-
Notifications
You must be signed in to change notification settings - Fork 345
Add turbo frame assertion test helpers #742
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -79,5 +79,76 @@ def assert_no_turbo_stream(action:, target: nil, targets: nil) | |||||||||||||||||||||||||||||
selector << %([targets="#{targets}"]) if targets | ||||||||||||||||||||||||||||||
assert_select selector, count: 0 | ||||||||||||||||||||||||||||||
end | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
# Assert that the rendered fragment of HTML contains a `<turbo-frame>` | ||||||||||||||||||||||||||||||
# element. | ||||||||||||||||||||||||||||||
# | ||||||||||||||||||||||||||||||
# ==== Options | ||||||||||||||||||||||||||||||
# | ||||||||||||||||||||||||||||||
# * <tt>:id</tt> [String] matches the element's <tt>[id]</tt> attribute | ||||||||||||||||||||||||||||||
# * <tt>:loading</tt> [String] matches the element's <tt>[loading]</tt> | ||||||||||||||||||||||||||||||
# attribute | ||||||||||||||||||||||||||||||
# * <tt>:src</tt> [String] matches the element's <tt>[src]</tt> attribute | ||||||||||||||||||||||||||||||
# * <tt>:target</tt> [String] matches the element's <tt>[target]</tt> | ||||||||||||||||||||||||||||||
# attribute | ||||||||||||||||||||||||||||||
# * <tt>:count</tt> [Integer] indicates how many turbo frames are expected. | ||||||||||||||||||||||||||||||
# Defaults to <tt>1</tt>. | ||||||||||||||||||||||||||||||
# | ||||||||||||||||||||||||||||||
# Given the following HTML fragment: | ||||||||||||||||||||||||||||||
# | ||||||||||||||||||||||||||||||
# <turbo-frame id="example" target="_top"></turbo-frame> | ||||||||||||||||||||||||||||||
# | ||||||||||||||||||||||||||||||
# The following assertion would pass: | ||||||||||||||||||||||||||||||
# | ||||||||||||||||||||||||||||||
# assert_turbo_frame id: "example", target: "_top" | ||||||||||||||||||||||||||||||
# | ||||||||||||||||||||||||||||||
# You can also pass a block make assertions about the contents of the | ||||||||||||||||||||||||||||||
# element. Given the following HTML fragment: | ||||||||||||||||||||||||||||||
# | ||||||||||||||||||||||||||||||
# <turbo-frame id="example"> | ||||||||||||||||||||||||||||||
# <p>Hello!</p> | ||||||||||||||||||||||||||||||
# </turbo-frame> | ||||||||||||||||||||||||||||||
# | ||||||||||||||||||||||||||||||
# The following assertion would pass: | ||||||||||||||||||||||||||||||
# | ||||||||||||||||||||||||||||||
# assert_turbo_frame id: "example" do | ||||||||||||||||||||||||||||||
# assert_select "p", text: "Hello!" | ||||||||||||||||||||||||||||||
# end | ||||||||||||||||||||||||||||||
# | ||||||||||||||||||||||||||||||
def assert_turbo_frame(id:, loading: nil, src: nil, target: nil, count: 1, &block) | ||||||||||||||||||||||||||||||
selector = %(turbo-frame[id="#{id}"]) | ||||||||||||||||||||||||||||||
selector << %([loading="#{loading}"]) if loading | ||||||||||||||||||||||||||||||
selector << %([src="#{src}"]) if src | ||||||||||||||||||||||||||||||
selector << %([target="#{target}"]) if target | ||||||||||||||||||||||||||||||
assert_select selector, count: count, &block | ||||||||||||||||||||||||||||||
end | ||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think about omitting the
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since frames IDs should be unique, I thought it might make sense to set count to 1 instead of unset which matches 1 or more. |
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
# Assert that the rendered fragment of HTML does not contain a `<turbo-frame>` | ||||||||||||||||||||||||||||||
# element. | ||||||||||||||||||||||||||||||
# | ||||||||||||||||||||||||||||||
# ==== Options | ||||||||||||||||||||||||||||||
# | ||||||||||||||||||||||||||||||
# * <tt>:id</tt> [String] matches the element's <tt>[id]</tt> attribute | ||||||||||||||||||||||||||||||
# * <tt>:loading</tt> [String] matches the element's <tt>[loading]</tt> | ||||||||||||||||||||||||||||||
# attribute | ||||||||||||||||||||||||||||||
# * <tt>:src</tt> [String] matches the element's <tt>[src]</tt> attribute | ||||||||||||||||||||||||||||||
# * <tt>:target</tt> [String] matches the element's <tt>[target]</tt> | ||||||||||||||||||||||||||||||
# attribute | ||||||||||||||||||||||||||||||
# | ||||||||||||||||||||||||||||||
# Given the following HTML fragment: | ||||||||||||||||||||||||||||||
# | ||||||||||||||||||||||||||||||
# <turbo-frame id="example" target="_top"></turbo-frame> | ||||||||||||||||||||||||||||||
# | ||||||||||||||||||||||||||||||
# The following assertion would fail: | ||||||||||||||||||||||||||||||
# | ||||||||||||||||||||||||||||||
# assert_no_turbo_frame id: "example", target: "_top" | ||||||||||||||||||||||||||||||
# | ||||||||||||||||||||||||||||||
def assert_no_turbo_frame(id:, loading: nil, src: nil, target: nil) | ||||||||||||||||||||||||||||||
selector = %(turbo-frame[id="#{id}"]) | ||||||||||||||||||||||||||||||
selector << %([loading="#{loading}"]) if loading | ||||||||||||||||||||||||||||||
selector << %([src="#{src}"]) if src | ||||||||||||||||||||||||||||||
selector << %([target="#{target}"]) if target | ||||||||||||||||||||||||||||||
assert_select selector, count: 0 | ||||||||||||||||||||||||||||||
end | ||||||||||||||||||||||||||||||
excid3 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||
end | ||||||||||||||||||||||||||||||
end |
Uh oh!
There was an error while loading. Please reload this page.