Skip to content

Commit 5c0edab

Browse files
committed
Forward fill_in_rich_text_area options to Capybara
Capybara supports a range of global [selectors][]: > All Selectors below support the listed selector specific filters in > addition to the following system-wide filters > * `:id` (String, Regexp, XPath::Expression) - Matches the id attribute > * `:class` (String, Array, Regexp, XPath::Expression) - Matches the class(es) provided > * `:style` (String, Regexp, Hash) - Match on elements style > * `:above` (Element) - Match elements above the passed element on the page > * `:below` (Element) - Match elements below the passed element on the page > * `:left_of` (Element) - Match elements left of the passed element on the page > * `:right_of` (Element) - Match elements right of the passed element on the page > * `:near` (Element) - Match elements near (within 50px) the passed element on the page > * `:focused` (Boolean) - Match elements with focus (requires driver support) While the Action Text-provided `#fill_in_rich_text_area` System Test helper is capable of resolving `<trix-editor>` elements (through the `:rich_textarea` custom Capybara selector), it doesn't support additional options (except for `:with`). This commit forwards any available options to the underlying call to [find][] as filters. This enables combining `<label>`-based locator text alongside global filters like `:focused` or `:id`: ```ruby fill_in_rich_text_area "Label text with [id]", id: "trix_editor_1", with: "Hello" fill_in_rich_text_area "Label text matching :focus", focused: true, with: "Hello" fill_in_rich_text_area "Label text not matching :focus", focused: false, with: "Hello" ``` [selectors]: https://rubydoc.info/github/teamcapybara/capybara/master/Capybara/Selector [find]: https://rubydoc.info/github/teamcapybara/capybara/master/Capybara/Node/Finders:find
1 parent 6025230 commit 5c0edab

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

actiontext/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
* Forward `fill_in_rich_text_area` options to Capybara
2+
3+
```ruby
4+
fill_in_rich_textarea "Rich text editor", id: "trix_editor_1", with: "Hello world!"
5+
```
6+
7+
*Sean Doyle*
8+
19
* Attachment upload progress accounts for server processing time.
210

311
*Jeremy Daer*

actiontext/lib/action_text/system_test_helper.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ module SystemTestHelper
1414
# * its `aria-label`
1515
# * the `name` of its input
1616
#
17+
# Additional options are forwarded to Capybara as filters
1718
#
1819
# Examples:
1920
#
@@ -33,8 +34,8 @@ module SystemTestHelper
3334
# # <input id="trix_input_1" name="message[content]" type="hidden">
3435
# # <trix-editor input="trix_input_1"></trix-editor>
3536
# fill_in_rich_textarea "message[content]", with: "Hello <em>world!</em>"
36-
def fill_in_rich_textarea(locator = nil, with:)
37-
find(:rich_textarea, locator).execute_script("this.editor.loadHTML(arguments[0])", with.to_s)
37+
def fill_in_rich_textarea(locator = nil, with:, **)
38+
find(:rich_textarea, locator, **).execute_script("this.editor.loadHTML(arguments[0])", with.to_s)
3839
end
3940
alias_method :fill_in_rich_text_area, :fill_in_rich_textarea
4041
end

actiontext/test/system/system_test_helper_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def setup
2727

2828
test "filling in a rich-text area by label" do
2929
assert_selector :label, "Message content label", for: "message_content"
30-
fill_in_rich_textarea "Message content label", with: "Hello world!"
30+
fill_in_rich_textarea "Message content label", id: "message_content", with: "Hello world!"
3131
assert_selector :field, "message[content]", with: /Hello world!/, type: "hidden"
3232
end
3333

0 commit comments

Comments
 (0)