Skip to content

Commit 67a4ac6

Browse files
committed
Focus editor after calling fill_in_rich_text_area
When System Tests call `fill_in_rich_text_area`, they interact with `<trix-editor>` elements by changing the contents programmatically. This is unlike how end-users will interact with the element. Overhauling the test helper to more accurately reflect Real World usage would require a sizable effort. With that being said, leaving the `<trix-editor>` with focus after populating its contents is a minor change that makes it a more genuine recreation.
1 parent 59fe981 commit 67a4ac6

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

actiontext/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* Focus rich-text editor after calling `fill_in_rich_text_area`
2+
3+
*Sean Doyle*
4+
15
* Support `strict_loading:` option for `has_rich_text` declaration
26

37
*Sean Doyle*

actiontext/lib/action_text/system_test_helper.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ module SystemTestHelper
3030
# # <trix-editor input="trix_input_1"></trix-editor>
3131
# fill_in_rich_text_area "message[content]", with: "Hello <em>world!</em>"
3232
def fill_in_rich_text_area(locator = nil, with:)
33-
find(:rich_text_area, locator).execute_script("this.editor.loadHTML(arguments[0])", with.to_s)
33+
javascript = <<~JS
34+
this.editor.loadHTML(arguments[0])
35+
this.editor.focus()
36+
JS
37+
find(:rich_text_area, locator).execute_script(javascript, with.to_s)
3438
end
3539
end
3640
end

actiontext/test/system/system_test_helper_test.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
require "application_system_test_case"
44

55
class ActionText::SystemTestHelperTest < ApplicationSystemTestCase
6+
test "filling in a rich-text area focuses the trix-editor" do
7+
visit new_message_url
8+
9+
fill_in_rich_text_area "message_content", with: "Hello world!"
10+
11+
assert_selector(:rich_text_area, "message[content]", &:focused?)
12+
end
13+
614
test "filling in a rich-text area by ID" do
715
visit new_message_url
816
assert_selector "trix-editor#message_content"

0 commit comments

Comments
 (0)