From 39b1edde708e26d6f35dbee736bb5b576cd8a11f Mon Sep 17 00:00:00 2001 From: Usmanfee Date: Mon, 4 Nov 2024 19:21:11 +0100 Subject: [PATCH] fix(app overview): enable search for numeric and special characters (#1179) https://github.com/eclipse-tractusx/portal-frontend/issues/1177 --- src/components/pages/AppOverview/index.tsx | 4 ++-- src/types/Patterns.test.ts | 13 +++++++++++++ src/types/Patterns.ts | 5 +++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/components/pages/AppOverview/index.tsx b/src/components/pages/AppOverview/index.tsx index 20441c8c8..e4c39c297 100644 --- a/src/components/pages/AppOverview/index.tsx +++ b/src/components/pages/AppOverview/index.tsx @@ -57,6 +57,7 @@ import { fetchImageWithToken } from 'services/ImageService' import { setCurrentActiveStep } from 'features/appManagement/slice' import { setAppId, setAppStatus } from 'features/appManagement/actions' import NoItems from '../NoItems' +import { isValidAppOverviewSearch } from 'types/Patterns' export default function AppOverview() { const { t } = useTranslation() @@ -222,8 +223,7 @@ export default function AppOverview() { const doSearch = useCallback( (expr: string) => { - const validateExpr = /^[ A-Za-z]*$/.test(expr) - if (!validateExpr) { + if (!isValidAppOverviewSearch(expr)) { return } setSearchExpr(expr) diff --git a/src/types/Patterns.test.ts b/src/types/Patterns.test.ts index 803569c30..fa79c6fe2 100644 --- a/src/types/Patterns.test.ts +++ b/src/types/Patterns.test.ts @@ -30,6 +30,7 @@ import { isClientID, isPersonName, isSearchUserEmail, + isValidAppOverviewSearch, } from './Patterns' const TESTDATA = { @@ -255,6 +256,10 @@ const TESTDATA = { ], invalid: ['()*&^%$#/\\?><,`~'], }, + appOverview: { + valid: ['sa-12', '1234', 'Test123!@#'], + invalid: ['🚀 Rocket!', 'Invalid\nNewLine'], + }, } describe('Input Pattern Tests', () => { @@ -354,4 +359,12 @@ describe('Input Pattern Tests', () => { expect(isSearchUserEmail(expr)).toBe(false) }) }) + it('validate appoverview search', () => { + TESTDATA.appOverview.valid.forEach((expr) => { + expect(isValidAppOverviewSearch(expr)).toBe(true) + }) + TESTDATA.appOverview.invalid.forEach((expr) => { + expect(isValidAppOverviewSearch(expr)).toBe(false) + }) + }) }) diff --git a/src/types/Patterns.ts b/src/types/Patterns.ts index c9253a092..0b3994971 100644 --- a/src/types/Patterns.ts +++ b/src/types/Patterns.ts @@ -118,6 +118,9 @@ export const Patterns = { /^(?!.*\s$)(?=[a-zA-Z\d-]{0,10}[-\s]?[a-zA-Z\d-]{0,10}$)[a-zA-Z\d\s-]{2,10}$/, }, EMAIL_SEARCH: /^[ A-Za-z0-9._!@+-]*$/, + appOverview: { + SEARCH: /^[ A-Za-z0-9!@#$%^&*()_+\-=[\]{};':"\\|,.<>/?]*$/, + }, } export const isEmpty = (expr: string) => !expr || expr.trim() === '' @@ -208,5 +211,7 @@ export const isPostalCode = (expr: string) => Patterns.companyData.POSTAL_CODE.test(expr) export const isSearchUserEmail = (expr: string) => Patterns.EMAIL_SEARCH.test(expr) +export const isValidAppOverviewSearch = (expr: string) => + Patterns.appOverview.SEARCH.test(expr) export default Patterns