Skip to content

Commit

Permalink
Merge pull request #10482 from demarches-simplifiees/fix-bug-all-proc…
Browse files Browse the repository at this point in the history
…edures-page

Fix BUG - Ajoute la méthode Acronomyze comme helper
  • Loading branch information
kara22 authored Jun 3, 2024
2 parents 27f15bb + 8e093e8 commit 256b707
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
9 changes: 9 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module ApplicationHelper
APP_HOST = ENV['APP_HOST']
APP_HOST_LEGACY = ENV['APP_HOST_LEGACY']
REGEXP_REPLACE_TRAILING_EXTENSION = /(\.\w+)+$/.freeze
REGEXP_REPLACE_WORD_SEPARATOR = /[\s_-]+/.freeze

def app_host_legacy?(request)
return false if APP_HOST_LEGACY.blank?
Expand Down Expand Up @@ -145,4 +147,11 @@ def dsfr_icon(classes, *options)
tag.span(class: class_names(classes, 'fr-icon--sm': sm, 'fr-mr-1v': mr),
"aria-hidden" => true)
end

def acronymize(str)
str.gsub(REGEXP_REPLACE_TRAILING_EXTENSION, '')
.split(REGEXP_REPLACE_WORD_SEPARATOR)
.map { |word| word[0].upcase }
.join
end
end
25 changes: 25 additions & 0 deletions spec/helpers/application_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,29 @@
it { is_expected.to eq("") }
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

0 comments on commit 256b707

Please sign in to comment.