about summary refs log tree commit diff
path: root/spec/helpers
diff options
context:
space:
mode:
authorMatt Jankowski <matt@jankowski.online>2023-03-02 09:30:40 -0500
committerGitHub <noreply@github.com>2023-03-02 15:30:40 +0100
commit35dff48edf19a344cbf192b510033ba6785c367b (patch)
treef7d47b1aafb7863f920783da0173a01294d6c7e0 /spec/helpers
parent59f42c262b4faab3df7ec5fe2742f7707d58c285 (diff)
Add spec coverage for Admin::Trends::StatusesHelper (#23898)
Diffstat (limited to 'spec/helpers')
-rw-r--r--spec/helpers/admin/trends/statuses_helper_spec.rb54
1 files changed, 54 insertions, 0 deletions
diff --git a/spec/helpers/admin/trends/statuses_helper_spec.rb b/spec/helpers/admin/trends/statuses_helper_spec.rb
new file mode 100644
index 000000000..92caae690
--- /dev/null
+++ b/spec/helpers/admin/trends/statuses_helper_spec.rb
@@ -0,0 +1,54 @@
+# frozen_string_literal: true
+
+require 'rails_helper'
+
+describe Admin::Trends::StatusesHelper do
+  describe '.one_line_preview' do
+    before do
+      allow(helper).to receive(:current_user).and_return(Fabricate.build(:user))
+    end
+
+    context 'with a local status' do
+      let(:status) { Fabricate.build(:status, text: 'Test local status') }
+
+      it 'renders a correct preview text' do
+        result = helper.one_line_preview(status)
+
+        expect(result).to eq 'Test local status'
+      end
+    end
+
+    context 'with a remote status' do
+      let(:status) { Fabricate.build(:status, uri: 'https://sfd.sdf', text: '<html><body><p>Test remote status</p><p>text</p></body></html>') }
+
+      it 'renders a correct preview text' do
+        result = helper.one_line_preview(status)
+
+        expect(result).to eq 'Test remote status'
+      end
+    end
+
+    context 'with a status that has empty text' do
+      let(:status) { Fabricate.build(:status, text: '') }
+
+      it 'renders a correct preview text' do
+        result = helper.one_line_preview(status)
+
+        expect(result).to eq ''
+      end
+    end
+
+    context 'with a status that has emoji' do
+      before { Fabricate(:custom_emoji, shortcode: 'florpy') }
+
+      let(:status) { Fabricate(:status, text: 'hello there :florpy:') }
+
+      it 'renders a correct preview text' do
+        result = helper.one_line_preview(status)
+
+        expect(result).to match 'hello there'
+        expect(result).to match '<img rel="emoji"'
+      end
+    end
+  end
+end