You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
2.0 KiB

  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