-
Notifications
You must be signed in to change notification settings - Fork 2
closed #88 #134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
closed #88 #134
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ecc0425
ignore "tildes"
zumaichi a9f353f
add normalizeSearrchString
zumaichi 7eaaadd
Merge branch 'main' into feature/#88-Enhance-typeahead,-ignore-tildes
antonio06 064be6b
refactor: enhance normalizeSearchString function and add unit tests f…
antonio06 46aa69d
fix: correct comment formatting in normalizeSearchString function
antonio06 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
155 changes: 155 additions & 0 deletions
155
front/src/pods/embalse-search/embalse-search.business.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,155 @@ | ||
| import { describe, it, expect } from "vitest"; | ||
| import { normalizeSearchString, getFilteredEmbalses } from './embalse-search.business'; | ||
|
|
||
| describe('normalizeSearchString', () => { | ||
| it('should return a empty string when input is empty', () => { | ||
| // Arrange | ||
| const input = ''; | ||
|
|
||
| // Act | ||
| const result = normalizeSearchString(input); | ||
|
|
||
| // Assert | ||
| expect(result).toBe(''); | ||
| }); | ||
|
|
||
| it('should return a empty string when input is null', () => { | ||
| // Arrange | ||
| const input: any = null; | ||
|
|
||
| // Act | ||
| const result = normalizeSearchString(input); | ||
|
|
||
| // Assert | ||
| expect(result).toBe(''); | ||
| }); | ||
|
|
||
| it('should return a empty string when input is undefined', () => { | ||
| // Arrange | ||
| const input: any = undefined; | ||
|
|
||
| // Act | ||
| const result = normalizeSearchString(input); | ||
|
|
||
| // Assert | ||
| expect(result).toBe(''); | ||
| }); | ||
|
|
||
| it('should normalize a string by removing accents, punctuation and extra spaces', () => { | ||
| // Arrange | ||
| const input = ' Guadalquivir '; | ||
| const expectedResult = 'guadalquivir'; | ||
|
|
||
| // Act | ||
| const result = normalizeSearchString(input); | ||
|
|
||
| // Assert | ||
| expect(result).toBe(expectedResult); | ||
| }); | ||
|
|
||
| it('should normalize a string with accents', () => { | ||
| // Arrange | ||
| const input = 'Sistema Valle de Arán'; | ||
| const expectedResult = 'sistema valle de aran'; | ||
|
|
||
| // Act | ||
| const result = normalizeSearchString(input); | ||
|
|
||
| // Assert | ||
| expect(result).toBe(expectedResult); | ||
| }); | ||
|
|
||
| it('should normalize a string with punctuation', () => { | ||
| // Arrange | ||
| const input = 'Embalse de la Mora, Huelva.'; | ||
| const expectedResult = 'embalse de la mora huelva'; | ||
|
|
||
| // Act | ||
| const result = normalizeSearchString(input); | ||
|
|
||
| // Assert | ||
| expect(result).toBe(expectedResult); | ||
| }); | ||
|
|
||
| it('should return Avinuela, when feed Aviñuela', () => { | ||
| // Arrange | ||
| const input = 'Aviñuela'; | ||
| const expectedResult = 'avinuela'; | ||
|
|
||
| // Act | ||
| const result = normalizeSearchString(input); | ||
|
|
||
| // Assert | ||
| expect(result).toBe(expectedResult); | ||
| }); | ||
|
|
||
| }); | ||
|
|
||
| describe('getFilteredEmbalses', () => { | ||
| it('should return an empty array when embalses and inputValue is empty', () => { | ||
| // Arrange | ||
| const inputValue = ''; | ||
| const embalses = []; | ||
|
|
||
| // Act | ||
| const result = getFilteredEmbalses(inputValue, embalses); | ||
|
|
||
| // Assert | ||
| expect(result).toEqual([]); | ||
| }); | ||
|
|
||
| it('should return an empty array when embalses is empty and inputValue is null', () => { | ||
| // Arrange | ||
| const inputValue = null as any; | ||
| const embalses = []; | ||
|
|
||
| // Act | ||
| const result = getFilteredEmbalses(inputValue, embalses); | ||
|
|
||
| // Assert | ||
| expect(result).toEqual([]); | ||
| }); | ||
|
|
||
| it('should return an empty array when embalses is empty and inputValue is undefined', () => { | ||
| // Arrange | ||
| const inputValue = undefined as any; | ||
| const embalses = []; | ||
|
|
||
| // Act | ||
| const result = getFilteredEmbalses(inputValue, embalses); | ||
|
|
||
| // Assert | ||
| expect(result).toEqual([]); | ||
| }); | ||
|
|
||
| it('should return an empty array when embalses is empty', () => { | ||
| // Arrange | ||
| const inputValue = 'Viñuela'; | ||
| const embalses = []; | ||
|
|
||
| // Act | ||
| const result = getFilteredEmbalses(inputValue, embalses); | ||
|
|
||
| // Assert | ||
| expect(result).toEqual([]); | ||
| }); | ||
|
|
||
| it('should return filtered embalses based on inputValue', () => { | ||
| // Arrange | ||
| const inputValue = 'Viñuela'; | ||
| const embalses = [ | ||
| { _id: '1', nombre: 'Embalse de la Mora', provincia: 'Huelva' }, | ||
| { _id: '2', nombre: 'Embalse de la Viñuela', provincia: 'Málaga' }, | ||
| ]; | ||
| const expectedResult = [ | ||
| { slug: '2', name: 'Embalse de la Viñuela (Málaga)' }, | ||
| ]; | ||
|
|
||
| // Act | ||
| const result = getFilteredEmbalses(inputValue, embalses); | ||
|
|
||
| // Assert | ||
| expect(result).toEqual(expectedResult); | ||
| }); | ||
| }); | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import { mapEmbalseToSearch } from "./embalse-search.mapper"; | ||
| import { Embalse } from "./api"; | ||
|
|
||
| export const normalizeSearchString = (input: string): string => { | ||
| return input ? | ||
| input.toString() | ||
| .normalize("NFD") // Separa los acentos de las letras | ||
| .replace(/[\u0300-\u036f]/g, "") // Elimina acentos | ||
| .toLowerCase() | ||
| .replace(/[.,\/#!$%\^&\*;:{}=\-_`~()]/g, "") // Elimina signos de puntuación | ||
| .replace(/\s+/g, " ").trim() : ""; // Reemplaza múltiples espacios por uno | ||
| }; | ||
| // encontre todos esos filtros por internet y los aplico si sobra alguno lo quitamos, también dejé las descripciones | ||
|
|
||
| export const getFilteredEmbalses = ( | ||
| inputValue: string, | ||
| embalses: Embalse[], | ||
| ) => { | ||
| if (!embalses || embalses.length === 0) { | ||
| return []; | ||
| } | ||
|
|
||
| const lower = normalizeSearchString(inputValue); | ||
| const normalizedInputValue = normalizeSearchString(inputValue); | ||
|
|
||
| return embalses | ||
| .filter( | ||
| (e) => | ||
| e.nombre.toLowerCase().includes(lower) || | ||
| (e.provincia ?? "").toLowerCase().includes(lower) || | ||
| normalizeSearchString(e.nombre ?? "").includes(normalizedInputValue) || | ||
| normalizeSearchString(e.provincia ?? "").includes(normalizedInputValue), | ||
| ) | ||
| .map(mapEmbalseToSearch); | ||
| }; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I miss unit test on this business methods.
@antonio06 or @manudous could you please shed some light to @zumaichi