aboutsummaryrefslogtreecommitdiffstats
path: root/actiontext/test/template
diff options
context:
space:
mode:
authorGeorge Claghorn <george@basecamp.com>2019-01-04 19:43:11 -0500
committerGeorge Claghorn <george@basecamp.com>2019-01-04 22:22:49 -0500
commit0decd2ddc4a94cf522fc8ea8e6c73b9deedfdd93 (patch)
tree91b8ddcf86b15356cd8d3dee235bf53a1778572b /actiontext/test/template
parent8a23a0e8c20c0cccf0073906d7dd7f809bfa836d (diff)
parentcfe4674d3637c746cdb3c2b5131e2de498775529 (diff)
downloadrails-0decd2ddc4a94cf522fc8ea8e6c73b9deedfdd93.tar.gz
rails-0decd2ddc4a94cf522fc8ea8e6c73b9deedfdd93.tar.bz2
rails-0decd2ddc4a94cf522fc8ea8e6c73b9deedfdd93.zip
Import Action Text
Diffstat (limited to 'actiontext/test/template')
-rw-r--r--actiontext/test/template/form_helper_test.rb71
1 files changed, 71 insertions, 0 deletions
diff --git a/actiontext/test/template/form_helper_test.rb b/actiontext/test/template/form_helper_test.rb
new file mode 100644
index 0000000000..63ef7f0d7e
--- /dev/null
+++ b/actiontext/test/template/form_helper_test.rb
@@ -0,0 +1,71 @@
+# frozen_string_literal: true
+
+require "test_helper"
+
+class ActionText::FormHelperTest < ActionView::TestCase
+ tests ActionText::TagHelper
+
+ test "form with rich text area" do
+ form_with model: Message.new, scope: :message do |form|
+ form.rich_text_area :content
+ end
+
+ assert_dom_equal \
+ '<form action="/messages" accept-charset="UTF-8" data-remote="true" method="post">' \
+ '<input name="utf8" type="hidden" value="&#x2713;" />' \
+ '<input type="hidden" name="message[content]" id="message_content_trix_input_message" />' \
+ '<trix-editor id="message_content" input="message_content_trix_input_message" 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/:signed_id/:filename">' \
+ "</trix-editor>" \
+ "</form>",
+ output_buffer
+ end
+
+ test "form with rich text area having class" do
+ form_with model: Message.new, scope: :message do |form|
+ form.rich_text_area :content, class: "custom-class"
+ end
+
+ assert_dom_equal \
+ '<form action="/messages" accept-charset="UTF-8" data-remote="true" method="post">' \
+ '<input name="utf8" type="hidden" value="&#x2713;" />' \
+ '<input type="hidden" name="message[content]" id="message_content_trix_input_message" />' \
+ '<trix-editor id="message_content" input="message_content_trix_input_message" class="custom-class" data-direct-upload-url="http://test.host/rails/active_storage/direct_uploads" data-blob-url-template="http://test.host/rails/active_storage/blobs/:signed_id/:filename">' \
+ "</trix-editor>" \
+ "</form>",
+ output_buffer
+ end
+
+ test "form with rich text area for non-attribute" do
+ form_with model: Message.new, scope: :message do |form|
+ form.rich_text_area :not_an_attribute
+ end
+
+ assert_dom_equal \
+ '<form action="/messages" accept-charset="UTF-8" data-remote="true" method="post">' \
+ '<input name="utf8" type="hidden" value="&#x2713;" />' \
+ '<input type="hidden" name="message[not_an_attribute]" id="message_not_an_attribute_trix_input_message" />' \
+ '<trix-editor id="message_not_an_attribute" input="message_not_an_attribute_trix_input_message" 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/:signed_id/:filename">' \
+ "</trix-editor>" \
+ "</form>",
+ output_buffer
+ end
+
+ test "modelless form with rich text area" do
+ form_with url: "/messages", scope: :message do |form|
+ form.rich_text_area :content
+ end
+
+ assert_dom_equal \
+ '<form action="/messages" accept-charset="UTF-8" data-remote="true" method="post">' \
+ '<input name="utf8" type="hidden" value="&#x2713;" />' \
+ '<input type="hidden" name="message[content]" id="trix_input_1" />' \
+ '<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/:signed_id/:filename">' \
+ "</trix-editor>" \
+ "</form>",
+ output_buffer
+ end
+
+ def form_with(*)
+ @output_buffer = super
+ end
+end