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/dashboard_helper_spec.rb69
2 files changed, 73 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/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