闭社主体 forked from https://github.com/tootsuite/mastodon
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.

121 lines
3.4 KiB

  1. require 'rails_helper'
  2. describe ApplicationHelper do
  3. describe 'active_nav_class' do
  4. it 'returns active when on the current page' do
  5. allow(helper).to receive(:current_page?).and_return(true)
  6. result = helper.active_nav_class("/test")
  7. expect(result).to eq "active"
  8. end
  9. it 'returns empty string when not on current page' do
  10. allow(helper).to receive(:current_page?).and_return(false)
  11. result = helper.active_nav_class("/test")
  12. expect(result).to eq ""
  13. end
  14. end
  15. describe 'add_rtl_body_class' do
  16. around do |example|
  17. current_locale = I18n.locale
  18. example.run
  19. I18n.locale = current_locale
  20. end
  21. it 'adds rtl body class if locale is Arabic' do
  22. I18n.locale = :ar
  23. expect(helper.add_rtl_body_class('other classes')).to eq 'other classes rtl'
  24. end
  25. it 'adds rtl body class if locale is Farsi' do
  26. I18n.locale = :fa
  27. expect(helper.add_rtl_body_class('other classes')).to eq 'other classes rtl'
  28. end
  29. it 'adds rtl if locale is Hebrew' do
  30. I18n.locale = :he
  31. expect(helper.add_rtl_body_class('other classes')).to eq 'other classes rtl'
  32. end
  33. it 'does not add rtl if locale is Thai' do
  34. I18n.locale = :th
  35. expect(helper.add_rtl_body_class('other classes')).to eq 'other classes'
  36. end
  37. end
  38. describe 'fa_icon' do
  39. it 'returns a tag of fixed-width cog' do
  40. expect(helper.fa_icon('cog fw')).to eq '<i class="fa fa-cog fa-fw"></i>'
  41. end
  42. end
  43. describe 'favicon_path' do
  44. it 'returns /favicon.ico on production enviromnent' do
  45. expect(Rails.env).to receive(:production?).and_return(true)
  46. expect(helper.favicon_path).to eq '/favicon.ico'
  47. end
  48. end
  49. describe 'open_registrations?' do
  50. it 'returns true when open for registrations' do
  51. without_partial_double_verification do
  52. expect(Setting).to receive(:open_registrations).and_return(true)
  53. end
  54. expect(helper.open_registrations?).to eq true
  55. end
  56. it 'returns false when closed for registrations' do
  57. without_partial_double_verification do
  58. expect(Setting).to receive(:open_registrations).and_return(false)
  59. end
  60. expect(helper.open_registrations?).to eq false
  61. end
  62. end
  63. describe 'show_landing_strip?', without_verify_partial_doubles: true do
  64. describe 'when signed in' do
  65. before do
  66. allow(helper).to receive(:user_signed_in?).and_return(true)
  67. end
  68. it 'does not show landing strip' do
  69. expect(helper.show_landing_strip?).to eq false
  70. end
  71. end
  72. describe 'when signed out' do
  73. before do
  74. allow(helper).to receive(:user_signed_in?).and_return(false)
  75. end
  76. it 'does not show landing strip on single user instance' do
  77. allow(helper).to receive(:single_user_mode?).and_return(true)
  78. expect(helper.show_landing_strip?).to eq false
  79. end
  80. it 'shows landing strip on multi user instance' do
  81. allow(helper).to receive(:single_user_mode?).and_return(false)
  82. expect(helper.show_landing_strip?).to eq true
  83. end
  84. end
  85. end
  86. describe 'title' do
  87. around do |example|
  88. site_title = Setting.site_title
  89. example.run
  90. Setting.site_title = site_title
  91. end
  92. it 'returns site title on production enviroment' do
  93. Setting.site_title = 'site title'
  94. expect(Rails.env).to receive(:production?).and_return(true)
  95. expect(helper.title).to eq 'site title'
  96. end
  97. end
  98. end