Skip to content

Commit

Permalink
fix(app overview): enable search for numeric and special characters (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Usmanfee authored Nov 4, 2024
1 parent e6e2e0d commit 39b1edd
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/components/pages/AppOverview/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions src/types/Patterns.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
isClientID,
isPersonName,
isSearchUserEmail,
isValidAppOverviewSearch,
} from './Patterns'

const TESTDATA = {
Expand Down Expand Up @@ -255,6 +256,10 @@ const TESTDATA = {
],
invalid: ['()*&^%$#/\\?><,`~'],
},
appOverview: {
valid: ['sa-12', '1234', 'Test123!@#'],
invalid: ['🚀 Rocket!', 'Invalid\nNewLine'],
},
}

describe('Input Pattern Tests', () => {
Expand Down Expand Up @@ -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)
})
})
})
5 changes: 5 additions & 0 deletions src/types/Patterns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() === ''
Expand Down Expand Up @@ -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

0 comments on commit 39b1edd

Please sign in to comment.