2023-02-22 00:55:31 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-02-26 14:28:08 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2017-04-09 16:11:37 +01:00
|
|
|
describe ApplicationHelper do
|
|
|
|
describe 'active_nav_class' do
|
|
|
|
it 'returns active when on the current page' do
|
|
|
|
allow(helper).to receive(:current_page?).and_return(true)
|
2016-02-26 14:28:08 +00:00
|
|
|
|
2023-02-18 22:38:14 +00:00
|
|
|
result = helper.active_nav_class('/test')
|
|
|
|
expect(result).to eq 'active'
|
2018-09-23 19:42:13 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns active when on a current page' do
|
|
|
|
allow(helper).to receive(:current_page?).with('/foo').and_return(false)
|
|
|
|
allow(helper).to receive(:current_page?).with('/test').and_return(true)
|
|
|
|
|
|
|
|
result = helper.active_nav_class('/foo', '/test')
|
2023-02-18 22:38:14 +00:00
|
|
|
expect(result).to eq 'active'
|
2017-04-09 16:11:37 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns empty string when not on current page' do
|
|
|
|
allow(helper).to receive(:current_page?).and_return(false)
|
|
|
|
|
2023-02-18 22:38:14 +00:00
|
|
|
result = helper.active_nav_class('/test')
|
|
|
|
expect(result).to eq ''
|
2017-04-09 16:11:37 +01:00
|
|
|
end
|
|
|
|
end
|
2017-04-16 02:40:33 +01:00
|
|
|
|
2023-04-23 21:35:54 +01:00
|
|
|
describe 'body_classes' do
|
|
|
|
context 'with a body class string from a controller' do
|
|
|
|
before do
|
|
|
|
without_partial_double_verification do
|
|
|
|
allow(helper).to receive(:body_class_string).and_return('modal-layout compose-standalone')
|
|
|
|
allow(helper).to receive(:current_theme).and_return('default')
|
|
|
|
allow(helper).to receive(:current_account).and_return(Fabricate(:account))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'uses the controller body classes in the result' do
|
|
|
|
expect(helper.body_classes).to match(/modal-layout compose-standalone/)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-08-25 21:55:25 +01:00
|
|
|
describe 'locale_direction' do
|
2017-05-29 17:03:37 +01:00
|
|
|
it 'adds rtl body class if locale is Arabic' do
|
2023-04-30 13:07:03 +01:00
|
|
|
I18n.with_locale(:ar) do
|
|
|
|
expect(helper.locale_direction).to eq 'rtl'
|
|
|
|
end
|
2017-05-29 17:03:37 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'adds rtl body class if locale is Farsi' do
|
2023-04-30 13:07:03 +01:00
|
|
|
I18n.with_locale(:fa) do
|
|
|
|
expect(helper.locale_direction).to eq 'rtl'
|
|
|
|
end
|
2017-05-29 17:03:37 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'adds rtl if locale is Hebrew' do
|
2023-04-30 13:07:03 +01:00
|
|
|
I18n.with_locale(:he) do
|
|
|
|
expect(helper.locale_direction).to eq 'rtl'
|
|
|
|
end
|
2017-05-29 17:03:37 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not add rtl if locale is Thai' do
|
2023-04-30 13:07:03 +01:00
|
|
|
I18n.with_locale(:th) do
|
|
|
|
expect(helper.locale_direction).to_not eq 'rtl'
|
|
|
|
end
|
2017-05-29 17:03:37 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'fa_icon' do
|
|
|
|
it 'returns a tag of fixed-width cog' do
|
2018-09-28 01:11:14 +01:00
|
|
|
expect(helper.fa_icon('cog fw')).to eq '<i class="fa fa-cog fa-fw"></i>'
|
2017-05-29 17:03:37 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'open_registrations?' do
|
|
|
|
it 'returns true when open for registrations' do
|
|
|
|
without_partial_double_verification do
|
2019-03-14 04:28:30 +00:00
|
|
|
expect(Setting).to receive(:registrations_mode).and_return('open')
|
2017-05-29 17:03:37 +01:00
|
|
|
end
|
|
|
|
|
2023-02-20 05:14:50 +00:00
|
|
|
expect(helper.open_registrations?).to be true
|
2017-05-29 17:03:37 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false when closed for registrations' do
|
|
|
|
without_partial_double_verification do
|
2019-03-14 04:28:30 +00:00
|
|
|
expect(Setting).to receive(:registrations_mode).and_return('none')
|
2017-05-29 17:03:37 +01:00
|
|
|
end
|
|
|
|
|
2023-02-20 05:14:50 +00:00
|
|
|
expect(helper.open_registrations?).to be false
|
2017-05-29 17:03:37 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-04-16 02:40:33 +01:00
|
|
|
describe 'show_landing_strip?', without_verify_partial_doubles: true do
|
|
|
|
describe 'when signed in' do
|
|
|
|
before do
|
|
|
|
allow(helper).to receive(:user_signed_in?).and_return(true)
|
|
|
|
end
|
2023-02-19 05:54:34 +00:00
|
|
|
|
2017-04-16 02:40:33 +01:00
|
|
|
it 'does not show landing strip' do
|
2023-02-20 05:14:50 +00:00
|
|
|
expect(helper.show_landing_strip?).to be false
|
2017-04-16 02:40:33 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'when signed out' do
|
|
|
|
before do
|
|
|
|
allow(helper).to receive(:user_signed_in?).and_return(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not show landing strip on single user instance' do
|
|
|
|
allow(helper).to receive(:single_user_mode?).and_return(true)
|
|
|
|
|
2023-02-20 05:14:50 +00:00
|
|
|
expect(helper.show_landing_strip?).to be false
|
2017-04-16 02:40:33 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'shows landing strip on multi user instance' do
|
|
|
|
allow(helper).to receive(:single_user_mode?).and_return(false)
|
|
|
|
|
2023-02-20 05:14:50 +00:00
|
|
|
expect(helper.show_landing_strip?).to be true
|
2017-04-16 02:40:33 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-05-29 17:03:37 +01:00
|
|
|
|
|
|
|
describe 'title' do
|
2017-05-30 11:29:48 +01:00
|
|
|
around do |example|
|
|
|
|
site_title = Setting.site_title
|
|
|
|
example.run
|
|
|
|
Setting.site_title = site_title
|
|
|
|
end
|
|
|
|
|
2022-12-15 15:20:55 +00:00
|
|
|
it 'returns site title on production environment' do
|
2017-05-29 17:03:37 +01:00
|
|
|
Setting.site_title = 'site title'
|
|
|
|
expect(Rails.env).to receive(:production?).and_return(true)
|
|
|
|
expect(helper.title).to eq 'site title'
|
|
|
|
end
|
|
|
|
end
|
2016-02-26 14:28:08 +00:00
|
|
|
end
|