From 339be65d669c83fd4c64541a9e82086dc5e64682 Mon Sep 17 00:00:00 2001 From: George Claghorn Date: Sun, 19 May 2019 01:54:08 -0400 Subject: Allow filling in the only rich-text area without a locator --- actiontext/lib/action_text/system_test_helper.rb | 18 +++++++++++------- actiontext/test/system/system_test_helper_test.rb | 6 ++++++ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/actiontext/lib/action_text/system_test_helper.rb b/actiontext/lib/action_text/system_test_helper.rb index 7b01c4f0b7..77fc9eb50b 100644 --- a/actiontext/lib/action_text/system_test_helper.rb +++ b/actiontext/lib/action_text/system_test_helper.rb @@ -24,7 +24,7 @@ module ActionText # # # # # fill_in_rich_text_area "message[content]", with: "Hello world!" - 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 @@ end 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 diff --git a/actiontext/test/system/system_test_helper_test.rb b/actiontext/test/system/system_test_helper_test.rb index b00bbafa74..460769c480 100644 --- a/actiontext/test/system/system_test_helper_test.rb +++ b/actiontext/test/system/system_test_helper_test.rb @@ -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 -- cgit v1.2.3