Test that Trix-formatted messages render and survive editing

This commit is contained in:
Stanko K.R.
2026-09-26 10:21:40 +02:00
parent 1694accbf8
commit b5d3543e64
2 changed files with 33 additions and 0 deletions
+8
View File
@@ -158,6 +158,14 @@ class ContentFiltersTest < ActionView::TestCase
assert_match /<action-text-attachment sgid="#{users(:david).attachable_sgid}"/, filtered
end
test "message with formatting saved under Trix renders unchanged" do
body = %(<div>Hello <strong>bold</strong> <em>it</em> <del>gone</del> <a href="https://example.com/">link</a><br>second line</div><h1>Heading</h1><blockquote>quoted</blockquote><pre>line 1\nline 2</pre><ul><li>one</li></ul><ol><li>first</li></ol>)
message = Message.create! room: rooms(:pets), body: body, client_message_id: "0021", creator: users(:jason)
assert_equal body, ContentFilters::TextMessagePresentationFilters.apply(message.body.body).to_html
assert_includes message_presentation(message), body
end
test "message with a table keeps the table" do
body = "<figure class=\"lexxy-content__table-wrapper\"><table><tbody><tr><th><p>Name</p></th></tr><tr><td><p>Jason</p></td></tr></tbody></table></figure>"
message = Message.create! room: rooms(:pets), body: body, client_message_id: "0016", creator: users(:jason)
+25
View File
@@ -86,6 +86,31 @@ class ComposerTest < ApplicationSystemTestCase
assert_equal [ users(:jason) ], message.reload.mentionees
end
test "editing a formatted trix message keeps its formatting" do
body = %(<div>Hello <strong>bold</strong> <em>italic</em> <del>gone</del> <a href="https://example.com/">link</a><br>second line</div><h1>Heading</h1><blockquote>quoted</blockquote><pre>line 1\nline 2</pre><ul><li>one</li><li>two</li></ul><ol><li>first</li></ol>)
message = Message.create! room: rooms(:designers), body: body, client_message_id: "trix-formatted", creator: users(:jz)
join_room rooms(:designers)
within_message message do
reveal_message_actions
find(".message__edit-btn").click
assert_edit_editor_text "Heading"
click_on "Save changes"
end
assert_selector last_message_selector("strong"), text: "bold"
assert_selector last_message_selector("em"), text: "italic"
assert_selector last_message_selector("s, del"), text: "gone"
assert_selector last_message_selector(%(a[href="https://example.com/"])), text: "link"
assert_selector last_message_selector("h1"), text: "Heading"
assert_selector last_message_selector("blockquote"), text: "quoted"
assert_selector last_message_selector("pre"), text: /line 1\s*line 2/
assert_selector last_message_selector("ul li"), text: "two"
assert_selector last_message_selector("ol li"), text: "first"
assert_message_text /Hello bold italic gone link\s*second line/
end
test "editing a message whose mention was saved under Trix keeps the mention" do
body = %(<div>Hey <action-text-attachment sgid="#{users(:jason).attachable_sgid}" content-type="application/octet-stream"></action-text-attachment></div>)
message = Message.create! room: rooms(:designers), body: body, client_message_id: "trix-edited", creator: users(:jz)