about summary refs log tree commit diff
path: root/spec/helpers/admin/dashboard_helper_spec.rb
blob: 59062e48396b9dca2ee36b241f1a98270b20c0bf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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