diff options
Diffstat (limited to 'test/unit/content_test.rb')
-rw-r--r-- | test/unit/content_test.rb | 84 |
1 files changed, 42 insertions, 42 deletions
diff --git a/test/unit/content_test.rb b/test/unit/content_test.rb index 8f32a85110..c0b8ad024c 100644 --- a/test/unit/content_test.rb +++ b/test/unit/content_test.rb @@ -62,46 +62,46 @@ class ActionText::ContentTest < ActiveSupport::TestCase assert_equal ActionText::Attachables::MissingAttachable, content.attachments.first.attachable end - # test "extracts missing attachables" do - # html = %Q(<action-text-attachment sgid="missing"></action-text-attachment>) - # content = ActionText::Content.new(html) - # assert_equal 1, content.attachments.size - # assert_equal ActionText::Attachables::MissingAttachable, content.attachments.first.attachable - # end - # - # test "converts Trix-formatted attachments" do - # html = %Q(<figure data-trix-attachment='{"sgid":"123","contentType":"text/plain","width":100,"height":100}' data-trix-attributes='{"caption":"Captioned"}'></figure>) - # content = ActionText::Content.new(html) - # assert_equal 1, content.attachments.size - # assert_equal %Q(<action-text-attachment sgid="123" content-type="text/plain" width="100" height="100" caption="Captioned"></action-text-attachment>), content.to_html - # end - # - # test "ignores Trix-formatted attachments with malformed JSON" do - # html = %Q(<div data-trix-attachment='{"sgid":"garbage...'></div>) - # content = ActionText::Content.new(html) - # assert_equal 0, content.attachments.size - # end - # - # test "minifies attachment markup" do - # html = %Q(<action-text-attachment sgid="123"><div>HTML</div></action-text-attachment>) - # assert_equal %Q(<action-text-attachment sgid="123"></action-text-attachment>), ActionText::Content.new(html).to_html - # end - # - # test "canonicalizes attachment gallery markup" do - # attachment_html = %Q(<action-text-attachment sgid="1" presentation="gallery"></action-text-attachment><action-text-attachment sgid="2" presentation="gallery"></action-text-attachment>) - # html = %Q(<div class="attachment-gallery attachment-gallery--2">#{attachment_html}</div>) - # assert_equal %Q(<div>#{attachment_html}</div>), ActionText::Content.new(html).to_html - # end - # - # test "canonicalizes attachment gallery markup with whitespace" do - # attachment_html = %Q(\n <action-text-attachment sgid="1" presentation="gallery"></action-text-attachment>\n <action-text-attachment sgid="2" presentation="gallery"></action-text-attachment>\n) - # html = %Q(<div class="attachment-gallery attachment-gallery--2">#{attachment_html}</div>) - # assert_equal %Q(<div>#{attachment_html}</div>), ActionText::Content.new(html).to_html - # end - # - # test "canonicalizes nested attachment gallery markup" do - # attachment_html = %Q(<action-text-attachment sgid="1" presentation="gallery"></action-text-attachment><action-text-attachment sgid="2" presentation="gallery"></action-text-attachment>) - # html = %Q(<blockquote><div class="attachment-gallery attachment-gallery--2">#{attachment_html}</div></blockquote>) - # assert_equal %Q(<blockquote><div>#{attachment_html}</div></blockquote>), ActionText::Content.new(html).to_html - # end + test "extracts missing attachables" do + html = %Q(<action-text-attachment sgid="missing"></action-text-attachment>) + content = ActionText::Content.new(html) + assert_equal 1, content.attachments.size + assert_equal ActionText::Attachables::MissingAttachable, content.attachments.first.attachable + end + + test "converts Trix-formatted attachments" do + html = %Q(<figure data-trix-attachment='{"sgid":"123","contentType":"text/plain","width":100,"height":100}' data-trix-attributes='{"caption":"Captioned"}'></figure>) + content = ActionText::Content.new(html) + assert_equal 1, content.attachments.size + assert_equal %Q(<action-text-attachment sgid="123" content-type="text/plain" width="100" height="100" caption="Captioned"></action-text-attachment>), content.to_html + end + + test "ignores Trix-formatted attachments with malformed JSON" do + html = %Q(<div data-trix-attachment='{"sgid":"garbage...'></div>) + content = ActionText::Content.new(html) + assert_equal 0, content.attachments.size + end + + test "minifies attachment markup" do + html = %Q(<action-text-attachment sgid="123"><div>HTML</div></action-text-attachment>) + assert_equal %Q(<action-text-attachment sgid="123"></action-text-attachment>), ActionText::Content.new(html).to_html + end + + test "canonicalizes attachment gallery markup" do + attachment_html = %Q(<action-text-attachment sgid="1" presentation="gallery"></action-text-attachment><action-text-attachment sgid="2" presentation="gallery"></action-text-attachment>) + html = %Q(<div class="attachment-gallery attachment-gallery--2">#{attachment_html}</div>) + assert_equal %Q(<div>#{attachment_html}</div>), ActionText::Content.new(html).to_html + end + + test "canonicalizes attachment gallery markup with whitespace" do + attachment_html = %Q(\n <action-text-attachment sgid="1" presentation="gallery"></action-text-attachment>\n <action-text-attachment sgid="2" presentation="gallery"></action-text-attachment>\n) + html = %Q(<div class="attachment-gallery attachment-gallery--2">#{attachment_html}</div>) + assert_equal %Q(<div>#{attachment_html}</div>), ActionText::Content.new(html).to_html + end + + test "canonicalizes nested attachment gallery markup" do + attachment_html = %Q(<action-text-attachment sgid="1" presentation="gallery"></action-text-attachment><action-text-attachment sgid="2" presentation="gallery"></action-text-attachment>) + html = %Q(<blockquote><div class="attachment-gallery attachment-gallery--2">#{attachment_html}</div></blockquote>) + assert_equal %Q(<blockquote><div>#{attachment_html}</div></blockquote>), ActionText::Content.new(html).to_html + end end |