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.

125 lines
3.4 KiB

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