home_helper_spec.rb 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe HomeHelper do
  4. describe 'default_props' do
  5. it 'returns default properties according to the context' do
  6. expect(helper.default_props).to eq locale: I18n.locale
  7. end
  8. end
  9. describe 'account_link_to' do
  10. context 'with a missing account' do
  11. let(:account) { nil }
  12. it 'returns a button' do
  13. result = helper.account_link_to(account)
  14. expect(result).to match t('about.contact_missing')
  15. end
  16. end
  17. context 'with a valid account' do
  18. let(:account) { Fabricate(:account) }
  19. it 'returns a link to the account' do
  20. without_partial_double_verification do
  21. allow(helper).to receive_messages(current_account: account, prefers_autoplay?: false)
  22. result = helper.account_link_to(account)
  23. expect(result).to match "@#{account.acct}"
  24. end
  25. end
  26. end
  27. end
  28. describe 'obscured_counter' do
  29. context 'with a value of less than zero' do
  30. let(:count) { -10 }
  31. it 'returns the correct string' do
  32. expect(helper.obscured_counter(count)).to eq '0'
  33. end
  34. end
  35. context 'with a value of zero' do
  36. let(:count) { 0 }
  37. it 'returns the correct string' do
  38. expect(helper.obscured_counter(count)).to eq '0'
  39. end
  40. end
  41. context 'with a value of one' do
  42. let(:count) { 1 }
  43. it 'returns the correct string' do
  44. expect(helper.obscured_counter(count)).to eq '1'
  45. end
  46. end
  47. context 'with a value of more than one' do
  48. let(:count) { 10 }
  49. it 'returns the correct string' do
  50. expect(helper.obscured_counter(count)).to eq '1+'
  51. end
  52. end
  53. end
  54. describe 'custom_field_classes' do
  55. context 'with a verified field' do
  56. let(:field) { instance_double(Account::Field, verified?: true) }
  57. it 'returns verified string' do
  58. result = helper.custom_field_classes(field)
  59. expect(result).to eq 'verified'
  60. end
  61. end
  62. context 'with a non-verified field' do
  63. let(:field) { instance_double(Account::Field, verified?: false) }
  64. it 'returns verified string' do
  65. result = helper.custom_field_classes(field)
  66. expect(result).to eq 'emojify'
  67. end
  68. end
  69. end
  70. describe 'sign_up_messages' do
  71. context 'with closed registrations' do
  72. it 'returns correct sign up message' do
  73. allow(helper).to receive(:closed_registrations?).and_return(true)
  74. result = helper.sign_up_message
  75. expect(result).to eq t('auth.registration_closed', instance: 'cb6e6126.ngrok.io')
  76. end
  77. end
  78. context 'with open registrations' do
  79. it 'returns correct sign up message' do
  80. allow(helper).to receive_messages(closed_registrations?: false, open_registrations?: true)
  81. result = helper.sign_up_message
  82. expect(result).to eq t('auth.register')
  83. end
  84. end
  85. context 'with approved registrations' do
  86. it 'returns correct sign up message' do
  87. allow(helper).to receive_messages(closed_registrations?: false, open_registrations?: false, approved_registrations?: true)
  88. result = helper.sign_up_message
  89. expect(result).to eq t('auth.apply_for_account')
  90. end
  91. end
  92. end
  93. end