Ensure backwards compatibility with Trix

This commit is contained in:
Stanko K.R.
2026-07-20 17:56:05 +02:00
parent a3d2939569
commit bfb57a23f9
8 changed files with 86 additions and 9 deletions
+23
View File
@@ -0,0 +1,23 @@
require "test_helper"
class RichTextHelperTest < ActionView::TestCase
include ActionText::ContentHelper
test "editable_body renders legacy opengraph embeds into the content attribute" do
body = %(<div>https://example.com/ <action-text-attachment content-type="application/vnd.actiontext.opengraph-embed" url="https://example.com/image.png" href="https://example.com/" filename="Example title" caption="Example description"></action-text-attachment></div>)
message = Message.create! room: rooms(:pets), body: body, client_message_id: "0017", creator: users(:jason)
node = editable_body(message).body.fragment.find_all("action-text-attachment").first
content = Nokogiri::HTML.fragment(node["content"])
assert_equal "Example title", content.at_css(".og-embed__title a").text.strip
assert_equal "https://example.com/", content.at_css(".og-embed__title a")["href"]
assert_equal "Example description", content.at_css(".og-embed__description").text.strip
assert_equal "https://example.com/image.png", content.at_css(".og-embed__image img")["src"]
end
test "editable_body leaves bodies without legacy embeds unchanged" do
message = Message.create! room: rooms(:pets), body: "<p>Plain text</p>", client_message_id: "0018", creator: users(:jason)
assert_equal message.body.body.to_html, editable_body(message).body.to_html
end
end
+18
View File
@@ -68,6 +68,24 @@ class ComposerTest < ApplicationSystemTestCase
assert_equal [ users(:jason) ], message.reload.mentionees
end
test "editing a legacy trix message keeps its mention and embed" do
body = %(<div>Hey #{mention_attachment_for(:jason)} check <action-text-attachment content-type="application/vnd.actiontext.opengraph-embed" url="https://example.com/image.png" href="https://example.com/" filename="Example title" caption="Example description"></action-text-attachment></div>)
message = Message.create! room: rooms(:designers), body: body, client_message_id: "legacy", creator: users(:jz)
join_room rooms(:designers)
within_message message do
reveal_message_actions
find(".message__edit-btn").click
assert_edit_editor_text "Jason"
click_on "Save changes"
end
assert_selector last_message_selector(".mention"), text: "Jason"
assert_selector last_message_selector(%(.og-embed__title a[href="https://example.com/"])), text: "Example title"
assert_equal [ users(:jason) ], message.reload.mentionees
end
test "replying quotes the original message with attribution" do
within_message messages(:third) do
reveal_message_actions