Skip to content
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

Datahub: Fix organisation search with special chars #737

Merged
merged 3 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 12 additions & 0 deletions libs/common/fixtures/src/lib/organisations.fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,16 @@ export const ORGANISATIONS_FIXTURE: Organization[] = deepFreeze([
logoUrl: new URL('https://my-geonetwork.org/logo11.png'),
recordCount: 2,
},
{
name: "Université de l'Ingénierie",
description: 'another org for testing',
logoUrl: new URL('https://my-geonetwork.org/logo12.png'),
recordCount: 2,
},
{
name: 'ARS / Agence régionale de santé',
description: 'another org for testing',
logoUrl: new URL('https://my-geonetwork.org/logo12.png'),
recordCount: 2,
},
])
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ describe('OrganisationsComponent', () => {
expect(orgPreviewComponents[0].organisation.name).toEqual('A Data Org')
})
it('should pass 6th organisation (sorted by name-asc) on page to 6th ui preview component', () => {
expect(orgPreviewComponents[5].organisation.name).toEqual('é Data Org')
expect(orgPreviewComponents[5].organisation.name).toEqual('E Data Org')
})
})
describe('pass params to ui pagination component', () => {
Expand Down Expand Up @@ -153,14 +153,14 @@ describe('OrganisationsComponent', () => {
})
it('should pass first organisation of second page (sorted by name-asc) to first ui preview component', () => {
expect(orgPreviewComponents[0].organisation.name).toEqual(
'F Data Org'
'é Data Org'
)
})
it('should pass last organisation of second page (sorted by name-asc) to last ui preview component', () => {
expect(
orgPreviewComponents[orgPreviewComponents.length - 1].organisation
.name
).toEqual('wizard-org')
).toEqual('J Data Org')
})
})
})
Expand Down Expand Up @@ -239,6 +239,16 @@ describe('OrganisationsComponent', () => {
fixture.detectChanges()
expect(orgResultComponent.componentInstance.hits).toEqual(2)
})
it('should ignore special caharacter without space and display 1 match for "l\'Ingénierie"', () => {
fgravin marked this conversation as resolved.
Show resolved Hide resolved
component.filterBy$.next("l'Ingénierie")
fixture.detectChanges()
expect(orgResultComponent.componentInstance.hits).toEqual(1)
})
it('should ignore special caharacter with space and display 1 match for "ARS / Agence"', () => {
fgravin marked this conversation as resolved.
Show resolved Hide resolved
component.filterBy$.next('ARS / Agence')
fixture.detectChanges()
expect(orgResultComponent.componentInstance.hits).toEqual(1)
})
it('should combine multiple termes with "AND" logic and display 1 match for "a data"', () => {
component.filterBy$.next('a data')
fixture.detectChanges()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export class OrganisationsComponent {
if (!filterBy) return organisations
const filterRegex = new RegExp(
this.normalizeString(filterBy) //ignore accents and case
.replace(/[^a-z0-9\s]/g, '') //ignore special characters
.replace(/[^a-z0-9\s]/g, ' ') //ignore special characters (also without spaces like l')
.replace(/\s(?=.)/g, '.*') //replace whitespaces by "AND" separator
.replace(/\s/g, ''), //remove potential whitespaces left
'i'
Expand Down
Loading