Skip to content

Commit

Permalink
Add test coverage for rich_text_area helper
Browse files Browse the repository at this point in the history
Follow-up to [rails#50252][]

Similar to the reliance on a `FormBuilder` in the helper methods
documentation examples, the template test coverage for `#rich_text_area`
relied on invocations through a `FormBuilder` instance.

This commit adds explicit coverage for calling the `#rich_text_area`
helper method directly with both an `object_name` and `method_name`
positional arguments.

[rails#50252]: rails#50252
  • Loading branch information
seanpdoyle committed Dec 3, 2023
1 parent da871cc commit 16c28d0
Showing 1 changed file with 27 additions and 9 deletions.
36 changes: 27 additions & 9 deletions actiontext/test/template/form_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,37 @@ def form_with(*, **)
)
end

test "rich text area tag" do
test "#rich_text_area_tag helper" do
message = Message.new

form_with model: message, scope: :message do |form|
rich_text_area_tag :content, message.content, { input: "trix_input_1" }
end
concat rich_text_area_tag :content, message.content, { input: "trix_input_1" }

assert_dom_equal \
'<form action="/messages" accept-charset="UTF-8" method="post">' \
'<input type="hidden" name="content" id="trix_input_1" autocomplete="off" />' \
'<trix-editor input="trix_input_1" class="trix-content" data-direct-upload-url="http://test.host/rails/active_storage/direct_uploads" data-blob-url-template="http://test.host/rails/active_storage/blobs/redirect/:signed_id/:filename">' \
"</trix-editor>" \
"</form>",
'<input type="hidden" name="content" id="trix_input_1" autocomplete="off" />' \
'<trix-editor input="trix_input_1" class="trix-content" data-direct-upload-url="http://test.host/rails/active_storage/direct_uploads" data-blob-url-template="http://test.host/rails/active_storage/blobs/redirect/:signed_id/:filename">' \
"</trix-editor>",
output_buffer
end

test "#rich_text_area helper" do
concat rich_text_area :message, :content, input: "trix_input_1"

assert_dom_equal \
'<input type="hidden" name="message[content]" id="trix_input_1" autocomplete="off" />' \
'<trix-editor id="message_content" input="trix_input_1" class="trix-content" data-direct-upload-url="http://test.host/rails/active_storage/direct_uploads" data-blob-url-template="http://test.host/rails/active_storage/blobs/redirect/:signed_id/:filename">' \
"</trix-editor>",
output_buffer
end

test "#rich_text_area helper renders the :value argument into the hidden field" do
message = Message.new content: "<h1>hello world</h1>"

concat rich_text_area :message, :title, value: message.content, input: "trix_input_1"

assert_dom_equal \
'<input type="hidden" name="message[title]" id="trix_input_1" value="&lt;h1&gt;hello world&lt;/h1&gt;" autocomplete="off" />' \
'<trix-editor id="message_title" input="trix_input_1" class="trix-content" data-direct-upload-url="http://test.host/rails/active_storage/direct_uploads" data-blob-url-template="http://test.host/rails/active_storage/blobs/redirect/:signed_id/:filename">' \
"</trix-editor>",
output_buffer
end

Expand Down

0 comments on commit 16c28d0

Please sign in to comment.