Skip to content

Commit 2044084

Browse files
authored
Merge pull request rails#50414 from seanpdoyle/action-text-upload-system-test
Improve Action Text System Test coverage
2 parents a52df54 + a763678 commit 2044084

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# frozen_string_literal: true
2+
3+
require "application_system_test_case"
4+
5+
class ActionText::RichTextEditorTest < ApplicationSystemTestCase
6+
test "attaches and uploads image file" do
7+
image_file = file_fixture("racecar.jpg")
8+
9+
visit new_message_url
10+
attach_file image_file do
11+
click_button "Attach Files"
12+
end
13+
within :rich_text_area do
14+
assert_selector :element, "img", src: %r{/rails/active_storage/blobs/redirect/.*/#{image_file.basename}\Z}
15+
end
16+
click_button "Create Message"
17+
18+
within class: "trix-content" do
19+
assert_selector :element, "img", src: %r{/rails/active_storage/representations/redirect/.*/#{image_file.basename}\Z}
20+
end
21+
end
22+
end

actiontext/test/system/system_test_helper_test.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,31 @@ def setup
88
end
99

1010
test "filling in a rich-text area by ID" do
11-
assert_selector "trix-editor#message_content"
11+
assert_selector :element, "trix-editor", id: "message_content"
1212
fill_in_rich_textarea "message_content", with: "Hello world!"
1313
assert_selector :field, "message[content]", with: /Hello world!/, type: "hidden"
1414
end
1515

1616
test "filling in a rich-text area by placeholder" do
17-
assert_selector "trix-editor[placeholder='Your message here']"
17+
assert_selector :element, "trix-editor", placeholder: "Your message here"
1818
fill_in_rich_textarea "Your message here", with: "Hello world!"
1919
assert_selector :field, "message[content]", with: /Hello world!/, type: "hidden"
2020
end
2121

2222
test "filling in a rich-text area by aria-label" do
23-
assert_selector "trix-editor[aria-label='Message content aria-label']"
23+
assert_selector :element, "trix-editor", "aria-label": "Message content aria-label"
2424
fill_in_rich_textarea "Message content aria-label", with: "Hello world!"
2525
assert_selector :field, "message[content]", with: /Hello world!/, type: "hidden"
2626
end
2727

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

3434
test "filling in a rich-text area by input name" do
35-
assert_selector "trix-editor[input]"
35+
assert_selector :element, "trix-editor", input: true
3636
fill_in_rich_textarea "message[content]", with: "Hello world!"
3737
assert_selector :field, "message[content]", with: /Hello world!/, type: "hidden"
3838
end

0 commit comments

Comments
 (0)