Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions spec/util/autoComplete-spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
const { normalizeText } = require('../../src/util/textNormalizer')

describe('autoComplete', () => {
describe('normalizeText', () => {
it('should convert text to lowercase', () => {
Comment on lines +3 to +5
Copy link

Copilot AI Jan 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This spec file is named autoComplete-spec.js and the top-level describe is 'autoComplete', but the tests only exercise normalizeText from textNormalizer.js. Other util specs (for example spec/util/urlUtils-spec.js:1-6 and spec/util/inputSanitizer-spec.js:1-4) follow a convention where the spec file name and top-level describe match the module under test. To keep tests discoverable and aligned with that convention, consider renaming this spec to something like textNormalizer-spec.js and updating the top-level describe to 'textNormalizer' (or similar).

Copilot uses AI. Check for mistakes.
expect(normalizeText('HELLO WORLD')).toBe('hello world')
expect(normalizeText('Test Case')).toBe('test case')
})

it('should remove Portuguese accents', () => {
expect(normalizeText('Autorização')).toBe('autorizacao')
expect(normalizeText('Experiência')).toBe('experiencia')
expect(normalizeText('ação')).toBe('acao')
expect(normalizeText('coração')).toBe('coracao')
})

it('should remove Spanish accents', () => {
expect(normalizeText('señor')).toBe('senor')
expect(normalizeText('niño')).toBe('nino')
expect(normalizeText('mañana')).toBe('manana')
})

it('should remove French accents', () => {
expect(normalizeText('café')).toBe('cafe')
expect(normalizeText('résumé')).toBe('resume')
expect(normalizeText('naïve')).toBe('naive')
expect(normalizeText('façade')).toBe('facade')
})

it('should remove German umlauts', () => {
expect(normalizeText('über')).toBe('uber')
expect(normalizeText('Mädchen')).toBe('madchen')
expect(normalizeText('schön')).toBe('schon')
})

it('should handle mixed accented and non-accented text', () => {
expect(normalizeText('Continuous Delivery práticas')).toBe('continuous delivery praticas')
expect(normalizeText('Test Automation técnicas')).toBe('test automation tecnicas')
})

it('should preserve text without accents', () => {
expect(normalizeText('hello world')).toBe('hello world')
expect(normalizeText('Kubernetes')).toBe('kubernetes')
expect(normalizeText('React.js')).toBe('react.js')
})

it('should handle empty string', () => {
expect(normalizeText('')).toBe('')
})

it('should handle numbers and special characters', () => {
expect(normalizeText('Test123!')).toBe('test123!')
expect(normalizeText('hello@world.com')).toBe('hello@world.com')
})
})
})
9 changes: 5 additions & 4 deletions src/util/autoComplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const $ = require('jquery')
require('jquery-ui/ui/widgets/autocomplete')

const config = require('../config')
const { normalizeText } = require('./textNormalizer')
const featureToggles = config().featureToggles

$.widget('custom.radarcomplete', $.ui.autocomplete, {
Expand Down Expand Up @@ -36,8 +37,8 @@ const AutoComplete = (el, quadrants, cb) => {
appendTo: '.search-container',
source: (request, response) => {
const matches = blips.filter(({ blip }) => {
const searchable = `${blip.name()} ${blip.description()}`.toLowerCase()
return request.term.split(' ').every((term) => searchable.includes(term.toLowerCase()))
const searchable = normalizeText(`${blip.name()} ${blip.description()}`)
return request.term.split(' ').every((term) => searchable.includes(normalizeText(term)))
})
response(matches.map((item) => ({ ...item, value: item.blip.name() })))
},
Expand All @@ -47,8 +48,8 @@ const AutoComplete = (el, quadrants, cb) => {
$(el).radarcomplete({
source: (request, response) => {
const matches = blips.filter(({ blip }) => {
const searchable = `${blip.name()} ${blip.description()}`.toLowerCase()
return request.term.split(' ').every((term) => searchable.includes(term.toLowerCase()))
const searchable = normalizeText(`${blip.name()} ${blip.description()}`)
return request.term.split(' ').every((term) => searchable.includes(normalizeText(term)))
})
response(matches.map((item) => ({ ...item, value: item.blip.name() })))
},
Expand Down
16 changes: 16 additions & 0 deletions src/util/textNormalizer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Normalize text by removing diacritical marks for accent-insensitive search
* This allows searching for "Autorizacao" to match "Autorização" (Portuguese)
* or "Experiencia" to match "Experiência"
*
* @param {string} text - The text to normalize
* @returns {string} - Lowercase text with diacritical marks removed
*/
const normalizeText = (text) => {
return text
.toLowerCase()
.normalize('NFD')
.replace(/[\u0300-\u036f]/g, '')
}

module.exports = { normalizeText }
Loading