Skip to content

Commit

Permalink
Fix TestRunBugForm trim of null string. Created a _trim function to s…
Browse files Browse the repository at this point in the history
…implify the check on variables before calling trim()

Signed-off-by: Luigi Pellecchia <[email protected]>
  • Loading branch information
Luigi Pellecchia committed Dec 7, 2024
1 parent 0caf6c4 commit 694644b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
12 changes: 12 additions & 0 deletions app/src/app/Constants/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,18 @@ export const getLimitedText = (_text, _length) => {
return _text
}

export const _trim = (_var) => {
try {
if (_var == undefined) {
return ''
} else {
return String(_var).trim()
}
} catch {
return ''
}
}

export const logObject = (obj) => {
let i
let k
Expand Down
14 changes: 7 additions & 7 deletions app/src/app/Mapping/Form/TestRunBugForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ export const TestRunBugForm: React.FunctionComponent<TestRunBugFormProps> = ({
parentType
}: TestRunBugFormProps) => {
const auth = useAuth()
const [bugsValue, setBugsValue] = React.useState(modalTestRun.bugs)
const [fixesValue, setFixesValue] = React.useState(modalTestRun.fixes)
const [notesValue, setNotesValue] = React.useState(modalTestRun.notes)
const [bugsValue, setBugsValue] = React.useState(modalTestRun?.bugs || '')
const [fixesValue, setFixesValue] = React.useState(modalTestRun?.fixes || '')
const [notesValue, setNotesValue] = React.useState(modalTestRun?.notes || '')
const [messageValue, setMessageValue] = React.useState('')

const handleBugsValueChange = (value: string) => {
Expand Down Expand Up @@ -56,9 +56,9 @@ export const TestRunBugForm: React.FunctionComponent<TestRunBugFormProps> = ({
const data = {
'api-id': api.id,
id: modalTestRun.id,
bugs: bugsValue.trim(),
fixes: fixesValue.trim(),
notes: notesValue.trim(),
bugs: Constants._trim(bugsValue),
fixes: Constants._trim(fixesValue),
notes: Constants._trim(notesValue),
'user-id': auth.userId,
token: auth.token,
mapped_to_type: mapping_to,
Expand All @@ -77,7 +77,7 @@ export const TestRunBugForm: React.FunctionComponent<TestRunBugFormProps> = ({
if (response.status !== 200) {
setMessageValue(response.statusText)
} else {
setMessageValue('')
setMessageValue('SAVED')
}
})
.catch((err) => {
Expand Down

0 comments on commit 694644b

Please sign in to comment.