1
0

dashboard_helper_spec.rb 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe Admin::DashboardHelper do
  4. describe 'relevant_account_timestamp' do
  5. context 'with an account with older sign in' do
  6. let(:account) { Fabricate(:account) }
  7. let(:stamp) { 10.days.ago }
  8. it 'returns a time element' do
  9. account.user.update(current_sign_in_at: stamp)
  10. result = helper.relevant_account_timestamp(account)
  11. expect(result).to match('time-ago')
  12. expect(result).to match(I18n.l(stamp))
  13. end
  14. end
  15. context 'with an account with newer sign in' do
  16. let(:account) { Fabricate(:account) }
  17. it 'returns a time element' do
  18. account.user.update(current_sign_in_at: 10.hours.ago)
  19. result = helper.relevant_account_timestamp(account)
  20. expect(result).to eq(I18n.t('generic.today'))
  21. end
  22. end
  23. context 'with an account where the user is pending' do
  24. let(:account) { Fabricate(:account) }
  25. it 'returns a time element' do
  26. account.user.update(current_sign_in_at: nil)
  27. account.user.update(approved: false)
  28. result = helper.relevant_account_timestamp(account)
  29. expect(result).to match('time-ago')
  30. expect(result).to match(I18n.l(account.user.created_at))
  31. end
  32. end
  33. context 'with an account with a last status value' do
  34. let(:account) { Fabricate(:account) }
  35. let(:stamp) { 5.minutes.ago }
  36. it 'returns a time element' do
  37. account.user.update(current_sign_in_at: nil)
  38. account.account_stat.update(last_status_at: stamp)
  39. result = helper.relevant_account_timestamp(account)
  40. expect(result).to match('time-ago')
  41. expect(result).to match(I18n.l(stamp))
  42. end
  43. end
  44. context 'with an account without sign in or last status or pending' do
  45. let(:account) { Fabricate(:account) }
  46. it 'returns a time element' do
  47. account.user.update(current_sign_in_at: nil)
  48. result = helper.relevant_account_timestamp(account)
  49. expect(result).to eq('-')
  50. end
  51. end
  52. end
  53. end