diff options
Diffstat (limited to 'test/template')
-rw-r--r-- | test/template/form_helper_test.rb | 78 |
1 files changed, 50 insertions, 28 deletions
diff --git a/test/template/form_helper_test.rb b/test/template/form_helper_test.rb index 18b5edbee5..cb900ffc36 100644 --- a/test/template/form_helper_test.rb +++ b/test/template/form_helper_test.rb @@ -5,45 +5,67 @@ require 'test_helper' class ActionText::FormHelperTest < ActionView::TestCase tests ActionText::TagHelper - def form_with(*) - @output_buffer = super + 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="✓" />' \ + '<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 "rich_text_area doesn't raise when attributes don't exist in the model" do - assert_nothing_raised do - form_with(model: Message.new, scope: :message, id: "create-message") do |form| - form.rich_text_area(:not_an_attribute) - 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_match "message[not_an_attribute]", output_buffer + assert_dom_equal \ + '<form action="/messages" accept-charset="UTF-8" data-remote="true" method="post">' \ + '<input name="utf8" type="hidden" value="✓" />' \ + '<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" do - expected = '<form id="create-message" action="/messages" accept-charset="UTF-8" data-remote="true" method="post">'\ - '<input name="utf8" type="hidden" value="✓" />'\ - '<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>' - - form_with(model: Message.new, scope: :message, id: "create-message") do |form| - form.rich_text_area(:content) + 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 expected, output_buffer + assert_dom_equal \ + '<form action="/messages" accept-charset="UTF-8" data-remote="true" method="post">' \ + '<input name="utf8" type="hidden" value="✓" />' \ + '<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 "form with rich_text_area providing class option" do - expected = '<form id="create-message" action="/messages" accept-charset="UTF-8" data-remote="true" method="post">'\ - '<input name="utf8" type="hidden" value="✓" />'\ - '<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>' - - form_with(model: Message.new, scope: :message, id: "create-message") do |form| - form.rich_text_area(:content, class: "custom-class") + 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 expected, output_buffer + assert_dom_equal \ + '<form action="/messages" accept-charset="UTF-8" data-remote="true" method="post">' \ + '<input name="utf8" type="hidden" value="✓" />' \ + '<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 |