FIX: Don't collapse all oneboxes (#506)

FIX: Don’t collapse all oneboxes (#506)

diff --git a/assets/javascripts/discourse/components/chat-message-collapser.js b/assets/javascripts/discourse/components/chat-message-collapser.js
index d32a095..1670126 100644
--- a/assets/javascripts/discourse/components/chat-message-collapser.js
+++ b/assets/javascripts/discourse/components/chat-message-collapser.js
@@ -103,7 +103,9 @@ function externalImageOnebox(e) {
   return (
     e.firstElementChild &&
     e.firstElementChild.nodeName === "A" &&
-    e.firstElementChild.classList.contains("onebox")
+    e.firstElementChild.classList.contains("onebox") &&
+    e.firstElementChild.firstElementChild &&
+    e.firstElementChild.firstElementChild.nodeName === "IMG"
   );
 }
 
diff --git a/test/javascripts/components/chat-message-collapser-test.js b/test/javascripts/components/chat-message-collapser-test.js
index fc63574..dc027dc 100644
--- a/test/javascripts/components/chat-message-collapser-test.js
+++ b/test/javascripts/components/chat-message-collapser-test.js
@@ -24,9 +24,9 @@ const animatedImageCooked =
 
 const externalImageCooked =
   "<p>written text</p>" +
-  '<p><a href="http://cat1.com" class="onebox"></a></p>' +
+  '<p><a href="http://cat1.com" class="onebox"><img src=""></img></a></p>' +
   "<p>more written text</p>" +
-  '<p><a href="http://cat2.com" class="onebox"></a></p>' +
+  '<p><a href="http://cat2.com" class="onebox"><img src=""></img></a></p>' +
   "<p>and even more</p>";
 
 discourseModule(
diff --git a/test/javascripts/components/chat-message-text-test.js b/test/javascripts/components/chat-message-text-test.js
index 442ae31..5302aa1 100644
--- a/test/javascripts/components/chat-message-text-test.js
+++ b/test/javascripts/components/chat-message-text-test.js
@@ -36,6 +36,21 @@ discourseModule(
       },
     });
 
+    componentTest("does not collapse a non-image onebox", {
+      template: hbs`{{chat-message-text cooked=cooked}}`,
+
+      beforeEach() {
+        this.set(
+          "cooked",
+          '<p><a href="http://cat1.com" class="onebox"></a></p>'
+        );
+      },
+
+      async test(assert) {
+        assert.notOk(exists(".chat-message-collapser"));
+      },
+    });
+
     componentTest("is edited and shows that it's edited", {
       template: hbs`{{chat-message-text cooked=cooked uploads=uploads edited=edited}}`,
 

GitHub sha: fe422129b6ec7d539cc86d3b48e77bca8fdc1f42

This commit appears in #506 which was approved by pmusaraj. It was merged by nattsw.