1
0

home_helper_spec.rb 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. before { helper.extend controller_helpers }
  20. it 'returns a link to the account' do
  21. result = helper.account_link_to(account)
  22. expect(result).to match "@#{account.acct}"
  23. end
  24. private
  25. def controller_helpers
  26. Module.new do
  27. def current_account = Account.last
  28. end
  29. end
  30. end
  31. end
  32. describe 'obscured_counter' do
  33. context 'with a value of less than zero' do
  34. let(:count) { -10 }
  35. it 'returns the correct string' do
  36. expect(helper.obscured_counter(count)).to eq '0'
  37. end
  38. end
  39. context 'with a value of zero' do
  40. let(:count) { 0 }
  41. it 'returns the correct string' do
  42. expect(helper.obscured_counter(count)).to eq '0'
  43. end
  44. end
  45. context 'with a value of one' do
  46. let(:count) { 1 }
  47. it 'returns the correct string' do
  48. expect(helper.obscured_counter(count)).to eq '1'
  49. end
  50. end
  51. context 'with a value of more than one' do
  52. let(:count) { 10 }
  53. it 'returns the correct string' do
  54. expect(helper.obscured_counter(count)).to eq '1+'
  55. end
  56. end
  57. end
  58. describe 'custom_field_classes' do
  59. context 'with a verified field' do
  60. let(:field) { instance_double(Account::Field, verified?: true) }
  61. it 'returns verified string' do
  62. result = helper.custom_field_classes(field)
  63. expect(result).to eq 'verified'
  64. end
  65. end
  66. context 'with a non-verified field' do
  67. let(:field) { instance_double(Account::Field, verified?: false) }
  68. it 'returns verified string' do
  69. result = helper.custom_field_classes(field)
  70. expect(result).to eq 'emojify'
  71. end
  72. end
  73. end
  74. describe 'sign_up_messages' do
  75. context 'with closed registrations' do
  76. it 'returns correct sign up message' do
  77. allow(helper).to receive(:closed_registrations?).and_return(true)
  78. result = helper.sign_up_message
  79. expect(result).to eq t('auth.registration_closed', instance: 'cb6e6126.ngrok.io')
  80. end
  81. end
  82. context 'with open registrations' do
  83. it 'returns correct sign up message' do
  84. allow(helper).to receive_messages(closed_registrations?: false, open_registrations?: true)
  85. result = helper.sign_up_message
  86. expect(result).to eq t('auth.register')
  87. end
  88. end
  89. context 'with approved registrations' do
  90. it 'returns correct sign up message' do
  91. allow(helper).to receive_messages(closed_registrations?: false, open_registrations?: false, approved_registrations?: true)
  92. result = helper.sign_up_message
  93. expect(result).to eq t('auth.apply_for_account')
  94. end
  95. end
  96. end
  97. end