提交 339be65d 编写于 作者: G George Claghorn

Allow filling in the only rich-text area without a locator

上级 a0b10299
......@@ -24,7 +24,7 @@ module SystemTestHelper
# # <input id="trix_input_1" name="message[content]" type="hidden">
# # <trix-editor input="trix_input_1"></trix-editor>
# fill_in_rich_text_area "message[content]", with: "Hello <em>world!</em>"
def fill_in_rich_text_area(locator, with:)
def fill_in_rich_text_area(locator = nil, with:)
find(:rich_text_area, locator).execute_script("this.editor.loadHTML(arguments[0])", with.to_s)
end
end
......@@ -33,12 +33,16 @@ def fill_in_rich_text_area(locator, with:)
Capybara.add_selector :rich_text_area do
label "rich-text area"
xpath do |locator|
input_located_by_name = XPath.anywhere(:input).where(XPath.attr(:name) == locator).attr(:id)
if locator.nil?
XPath.descendant(:"trix-editor")
else
input_located_by_name = XPath.anywhere(:input).where(XPath.attr(:name) == locator).attr(:id)
XPath.descendant(:"trix-editor").where \
XPath.attr(:id).equals(locator) |
XPath.attr(:placeholder).equals(locator) |
XPath.attr(:"aria-label").equals(locator) |
XPath.attr(:input).equals(input_located_by_name)
XPath.descendant(:"trix-editor").where \
XPath.attr(:id).equals(locator) |
XPath.attr(:placeholder).equals(locator) |
XPath.attr(:"aria-label").equals(locator) |
XPath.attr(:input).equals(input_located_by_name)
end
end
end
......@@ -30,4 +30,10 @@ class ActionText::SystemTestHelperTest < ApplicationSystemTestCase
fill_in_rich_text_area "message[content]", with: "Hello world!"
assert_selector :field, "message[content]", with: /Hello world!/, type: "hidden"
end
test "filling in the first rich-text area" do
visit new_message_url
fill_in_rich_text_area with: "Hello world!"
assert_selector :field, "message[content]", with: /Hello world!/, type: "hidden"
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册