about summary refs log tree commit diff
path: root/spec/helpers/admin
diff options
context:
space:
mode:
Diffstat (limited to 'spec/helpers/admin')
-rw-r--r--spec/helpers/admin/account_moderation_notes_helper_spec.rb10
-rw-r--r--spec/helpers/admin/action_logs_helper_spec.rb (renamed from spec/helpers/admin/action_log_helper_spec.rb)0
-rw-r--r--spec/helpers/admin/dashboard_helper_spec.rb69
-rw-r--r--spec/helpers/admin/filter_helper_spec.rb2
-rw-r--r--spec/helpers/admin/trends/statuses_helper_spec.rb54
5 files changed, 129 insertions, 6 deletions
diff --git a/spec/helpers/admin/account_moderation_notes_helper_spec.rb b/spec/helpers/admin/account_moderation_notes_helper_spec.rb
index 622ce8806..e01eba51d 100644
--- a/spec/helpers/admin/account_moderation_notes_helper_spec.rb
+++ b/spec/helpers/admin/account_moderation_notes_helper_spec.rb
@@ -42,13 +42,11 @@ RSpec.describe Admin::AccountModerationNotesHelper, type: :helper do
       let(:account) { Fabricate(:account) }
 
       it 'calls #link_to' do
-        expect(helper).to receive(:link_to).with(
-          admin_account_path(account.id),
-          class: name_tag_classes(account, true),
-          title: account.acct
-        )
+        result = helper.admin_account_inline_link_to(account)
 
-        helper.admin_account_inline_link_to(account)
+        expect(result).to match(name_tag_classes(account, true))
+        expect(result).to match(account.acct)
+        expect(result).to match(admin_account_path(account.id))
       end
     end
   end
diff --git a/spec/helpers/admin/action_log_helper_spec.rb b/spec/helpers/admin/action_logs_helper_spec.rb
index 9d7ed4ab7..9d7ed4ab7 100644
--- a/spec/helpers/admin/action_log_helper_spec.rb
+++ b/spec/helpers/admin/action_logs_helper_spec.rb
diff --git a/spec/helpers/admin/dashboard_helper_spec.rb b/spec/helpers/admin/dashboard_helper_spec.rb
new file mode 100644
index 000000000..59062e483
--- /dev/null
+++ b/spec/helpers/admin/dashboard_helper_spec.rb
@@ -0,0 +1,69 @@
+# frozen_string_literal: true
+
+require 'rails_helper'
+
+describe Admin::DashboardHelper do
+  describe 'relevant_account_timestamp' do
+    context 'with an account with older sign in' do
+      let(:account) { Fabricate(:account) }
+      let(:stamp) { 10.days.ago }
+
+      it 'returns a time element' do
+        account.user.update(current_sign_in_at: stamp)
+        result = helper.relevant_account_timestamp(account)
+
+        expect(result).to match('time-ago')
+        expect(result).to match(I18n.l(stamp))
+      end
+    end
+
+    context 'with an account with newer sign in' do
+      let(:account) { Fabricate(:account) }
+
+      it 'returns a time element' do
+        account.user.update(current_sign_in_at: 10.hours.ago)
+        result = helper.relevant_account_timestamp(account)
+
+        expect(result).to eq(I18n.t('generic.today'))
+      end
+    end
+
+    context 'with an account where the user is pending' do
+      let(:account) { Fabricate(:account) }
+
+      it 'returns a time element' do
+        account.user.update(current_sign_in_at: nil)
+        account.user.update(approved: false)
+        result = helper.relevant_account_timestamp(account)
+
+        expect(result).to match('time-ago')
+        expect(result).to match(I18n.l(account.user.created_at))
+      end
+    end
+
+    context 'with an account with a last status value' do
+      let(:account) { Fabricate(:account) }
+      let(:stamp) { 5.minutes.ago }
+
+      it 'returns a time element' do
+        account.user.update(current_sign_in_at: nil)
+        account.account_stat.update(last_status_at: stamp)
+        result = helper.relevant_account_timestamp(account)
+
+        expect(result).to match('time-ago')
+        expect(result).to match(I18n.l(stamp))
+      end
+    end
+
+    context 'with an account without sign in or last status or pending' do
+      let(:account) { Fabricate(:account) }
+
+      it 'returns a time element' do
+        account.user.update(current_sign_in_at: nil)
+        result = helper.relevant_account_timestamp(account)
+
+        expect(result).to eq('-')
+      end
+    end
+  end
+end
diff --git a/spec/helpers/admin/filter_helper_spec.rb b/spec/helpers/admin/filter_helper_spec.rb
index 9d4ea2829..bbf90a996 100644
--- a/spec/helpers/admin/filter_helper_spec.rb
+++ b/spec/helpers/admin/filter_helper_spec.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 require 'rails_helper'
 
 describe Admin::FilterHelper do
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