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.

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