Ajoute la méthode Acronomyze comme helper pour être utilisé sur la page toutes les démarches

This commit is contained in:
Kara Diaby 2024-06-03 07:20:56 +00:00
parent 27f15bbe07
commit 8e093e88c2
2 changed files with 34 additions and 0 deletions

View file

@ -1,6 +1,8 @@
module ApplicationHelper module ApplicationHelper
APP_HOST = ENV['APP_HOST'] APP_HOST = ENV['APP_HOST']
APP_HOST_LEGACY = ENV['APP_HOST_LEGACY'] APP_HOST_LEGACY = ENV['APP_HOST_LEGACY']
REGEXP_REPLACE_TRAILING_EXTENSION = /(\.\w+)+$/.freeze
REGEXP_REPLACE_WORD_SEPARATOR = /[\s_-]+/.freeze
def app_host_legacy?(request) def app_host_legacy?(request)
return false if APP_HOST_LEGACY.blank? return false if APP_HOST_LEGACY.blank?
@ -145,4 +147,11 @@ module ApplicationHelper
tag.span(class: class_names(classes, 'fr-icon--sm': sm, 'fr-mr-1v': mr), tag.span(class: class_names(classes, 'fr-icon--sm': sm, 'fr-mr-1v': mr),
"aria-hidden" => true) "aria-hidden" => true)
end end
def acronymize(str)
str.gsub(REGEXP_REPLACE_TRAILING_EXTENSION, '')
.split(REGEXP_REPLACE_WORD_SEPARATOR)
.map { |word| word[0].upcase }
.join
end
end end

View file

@ -112,4 +112,29 @@ describe ApplicationHelper do
it { is_expected.to eq("") } it { is_expected.to eq("") }
end end
end end
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
end end