2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-01-18 17:24:21 +01:00
|
|
|
describe ApplicationHelper do
|
2024-02-23 10:42:23 +01:00
|
|
|
describe 'app_host_legacy?' do
|
|
|
|
let(:request) { instance_double(ActionDispatch::Request, base_url: request_base_url) }
|
|
|
|
let(:app_host_legacy) { 'legacy' }
|
|
|
|
let(:app_host) { 'host' }
|
|
|
|
|
|
|
|
before do
|
|
|
|
stub_const("ApplicationHelper::APP_HOST_LEGACY", app_host_legacy)
|
|
|
|
stub_const("ApplicationHelper::APP_HOST", app_host)
|
|
|
|
end
|
|
|
|
|
|
|
|
subject { app_host_legacy?(request) }
|
|
|
|
|
2024-02-26 05:41:01 +01:00
|
|
|
context 'when request on ENV[APP_HOST_LEGACY]' do
|
2024-02-23 10:42:23 +01:00
|
|
|
let(:request_base_url) { app_host_legacy }
|
|
|
|
it { is_expected.to be_truthy }
|
|
|
|
end
|
|
|
|
|
2024-02-26 05:41:01 +01:00
|
|
|
context 'when request on ENV[APP_HOST]' do
|
2024-02-23 10:42:23 +01:00
|
|
|
let(:request_base_url) { app_host }
|
|
|
|
it { is_expected.to be_falsey }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-02-26 05:41:01 +01:00
|
|
|
describe 'auto_switch_domain?' do
|
|
|
|
subject { auto_switch_domain?(request, user_signed_in) }
|
|
|
|
|
|
|
|
context 'when user_signed_in? is true' do
|
|
|
|
let(:user_signed_in) { true }
|
|
|
|
let(:request) { instance_double(ActionDispatch::Request, base_url: 'osf', params: {}) }
|
|
|
|
it { is_expected.to be_falsey }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user_signed_in? is false' do
|
|
|
|
let(:user_signed_in) { false }
|
|
|
|
let(:params) { {} }
|
|
|
|
let(:request) { instance_double(ActionDispatch::Request, base_url: request_base_url, params:) }
|
|
|
|
let(:app_host_legacy) { 'legacy' }
|
|
|
|
let(:app_host) { 'host' }
|
|
|
|
|
|
|
|
before do
|
|
|
|
stub_const("ApplicationHelper::APP_HOST_LEGACY", app_host_legacy)
|
|
|
|
stub_const("ApplicationHelper::APP_HOST", app_host)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'request on ENV[APP_HOST_LEGACY] without feature or url' do
|
|
|
|
let(:request_base_url) { app_host_legacy }
|
|
|
|
it { is_expected.to be_falsey }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'request on ENV[APP_HOST_LEGACY] with switch_domain params' do
|
|
|
|
let(:params) { { switch_domain: '1' } }
|
|
|
|
let(:request_base_url) { app_host_legacy }
|
|
|
|
it { is_expected.to be_truthy }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'request on ENV[APP_HOST_LEGACY] with switch_domain params' do
|
|
|
|
before { Flipper.enable :switch_domain }
|
|
|
|
after { Flipper.disable :switch_domain }
|
|
|
|
let(:request_base_url) { app_host_legacy }
|
|
|
|
it { is_expected.to be_truthy }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'request on ENV[APP_HOST]' do
|
|
|
|
let(:request_base_url) { app_host }
|
|
|
|
it { is_expected.to be_falsey }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-01-06 12:43:02 +01:00
|
|
|
describe "#flash_class" do
|
|
|
|
it { expect(flash_class('notice')).to eq 'alert-success' }
|
|
|
|
it { expect(flash_class('alert', sticky: true, fixed: true)).to eq 'alert-danger sticky alert-fixed' }
|
2022-01-06 13:21:47 +01:00
|
|
|
it { expect(flash_class('error')).to eq 'alert-danger' }
|
2022-01-06 12:43:02 +01:00
|
|
|
it { expect(flash_class('unknown-level')).to eq '' }
|
|
|
|
end
|
|
|
|
|
2019-04-10 15:49:13 +02:00
|
|
|
describe "#try_format_date" do
|
|
|
|
subject { try_format_date(date) }
|
|
|
|
|
|
|
|
describe 'try formatting a date' do
|
|
|
|
let(:date) { Date.new(2019, 01, 24) }
|
|
|
|
it { is_expected.to eq("24 janvier 2019") }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'try formatting a blank string' do
|
|
|
|
let(:date) { "" }
|
|
|
|
it { is_expected.to eq("") }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'try formatting a nil string' do
|
|
|
|
let(:date) { nil }
|
|
|
|
it { is_expected.to eq("") }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#try_format_datetime" do
|
|
|
|
subject { try_format_datetime(datetime) }
|
|
|
|
|
|
|
|
describe 'try formatting 31/01/2019 11:25' do
|
|
|
|
let(:datetime) { Time.zone.local(2019, 01, 31, 11, 25, 00) }
|
|
|
|
it { is_expected.to eq("31 janvier 2019 11:25") }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'try formatting a blank string' do
|
|
|
|
let(:datetime) { "" }
|
|
|
|
it { is_expected.to eq("") }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'try formatting a nil string' do
|
|
|
|
let(:datetime) { nil }
|
|
|
|
it { is_expected.to eq("") }
|
|
|
|
end
|
|
|
|
end
|
2024-06-03 09:20:56 +02:00
|
|
|
describe '#acronymize' do
|
|
|
|
it 'returns the acronym of a given string' do
|
|
|
|
expect(helper.acronymize('Application Name')).to eq('AN')
|
|
|
|
expect(helper.acronymize('Hello World')).to eq('HW')
|
|
|
|
expect(helper.acronymize('Demarches Simplifiees')).to eq('DS')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'handles single word input' do
|
|
|
|
expect(helper.acronymize('Word')).to eq('W')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns an empty string for empty input' do
|
|
|
|
expect(helper.acronymize('')).to eq('')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'handles strings with extensions' do
|
|
|
|
expect(helper.acronymize('file_name.txt')).to eq('FN')
|
|
|
|
expect(helper.acronymize('example.pdf')).to eq('E')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'handles strings with various word separators' do
|
|
|
|
expect(helper.acronymize('multi-word_string')).to eq('MWS')
|
|
|
|
expect(helper.acronymize('another_example-test')).to eq('AET')
|
|
|
|
end
|
|
|
|
end
|
2018-01-18 17:24:21 +01:00
|
|
|
end
|