Skip to content

Commit

Permalink
Site 3912 (#166)
Browse files Browse the repository at this point in the history
* Changes from SITE-3986

* Update B1Tab.tsx

* Create SMTPTestCases.tsx

* Remove duplicate files

* Add env variables and move API calls to ServerActions

* Improve environment variable name

* Remove env variables

* Add Loading Button, Remove Default Profile Values

* add IMAP/POP3 manual validation, attachment type field

* Fix tab data carryover, fix include filter

* Add XDR endpoint fields

* Add XDR DocumentSelector handling

* Fix incorrect emails

* Fix missing doc select on XDR 3

* Add logs formatting

* Fix reversed IMAP and POP3 icons

* Add tooltip

* Fix XDR logs and missing manual validations

* Add attachment type tooltip

* Remove Tooltips add XDR API call

* Add error condition, add clear button

* Fix more info sections, censor profile password

* Add clear selected document

* Remove accept/reject on API error

* Fix XDR more info page

* add tooltip and pop over for endpoint copy

* Fix incorrect xdr email addresses

* Replace popover system and fix error handling

* Language improvements and fix clear button visibility trigger

* Fix language errors

* Add clear button to XDR send

* Basic xdr functionality

* Add manual validation, request/response, remining request fields,

* add xdr document selector

* Add XDR Document Select test functionality, add colorized XML display

* Correct document selection per sub criteria

* Fix failure detection on empty responses

* Banish type errors

* Less restrictive clear button

* Fix CORS issue with document select

* Update DocumentSelector.tsx

* add prettier ignore to bugged line

* Add improved warning triggers

* Add backup content, fix criteriaMet icon on non manual tests

* Language fix and null value handling

* Update replacement values

* Modify jessionid formation

* Update ServerActions.ts

* Alternative auth method

* Improve error handling

* Remove client session in request

* Add document selector role handling

* Add endpoint generation

* Add refresh functionality and endpoint visibility fix

* Fix env variable usage

* Add results to status refresh

* Fix clear button not visible after refresh

* Add CCDA Validation Tab

* Resolve typescript build errors

* Remove secondary endpoint value and add HTTPS to endpoints missing it

* Fix manual validation test issues

* Remove endpointTLS from test 7

* Fix ts error
  • Loading branch information
ebrockainq authored Oct 17, 2024
1 parent c5bdf42 commit c186a62
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 71 deletions.
179 changes: 112 additions & 67 deletions src/components/direct/hisp/XDRTestCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ interface StepTextProps {
inputs: InputFields[]
role?: string
endpointsGenerated: boolean
criteriaMet: string
}

interface ValidationResults {
Expand All @@ -102,30 +103,6 @@ interface CCDAValidationResult {
const senderText = 'Hit Run to generate your endpoint.'
const receiverText = 'Hit Run to send a XDR message.'

const StepText = ({ inputs, role, endpointsGenerated }: StepTextProps) => {
if (endpointsGenerated) {
return (
<Typography variant="body2">
<strong>Step 2:</strong> Send XDR message to endpoint and refresh to check status.
</Typography>
)
}

return (
<>
<Typography variant="body2">
<strong>Step 1:</strong> Provide your{' '}
{inputs.map((input, i) => (
<span key={i}>
{input.name}
{inputs.length - 1 === i ? '. ' : ', '}
</span>
))}
{role === 'sender' ? senderText : receiverText}
</Typography>
</>
)
}
export type FieldValue = boolean | string | number
export type ExtraFields = {
label: string
Expand Down Expand Up @@ -188,7 +165,7 @@ const TestCard = ({ test }: TestCardProps) => {
const [alertSeverity, setAlertSeverity] = useState<'success' | 'error' | 'warning' | 'info'>('info')

const [logType, setLogType] = useState<'request' | 'response' | 'ccdaValidation'>('request')
const manualValidationIDs = ['4a', '4b']
const manualValidationIDs = ['4a', '4b', '20amu2', '20bmu2']
const { data: session } = useSession()
const subHeader = 'Description'
const subDesc = test['Purpose/Description']
Expand All @@ -211,7 +188,6 @@ const TestCard = ({ test }: TestCardProps) => {
const handleAlertClose = () => {
setAlertOpen(false)
}

const toggleLogType = (type: 'request' | 'response' | 'ccdaValidation') => {
setLogType(type)
}
Expand All @@ -232,7 +208,45 @@ const TestCard = ({ test }: TestCardProps) => {
'44mu2',
]
const ccdaRequiredTestIds = ['1', '2', '3add']
const sendEdgeTestsCriteria = ['b1-1']
const isCCDADocumentRequired = ccdaRequiredTestIds.includes(test.id.toString())
const StepText = ({ inputs, role, endpointsGenerated, criteriaMet }: StepTextProps) => {
if (manualValidationIDs.includes(test.id.toString()) && isFinished) {
if (test.id == '20amu2' || test.id == '20bmu2') {
console.log('abc')
testRequest == 'Check your SUT logs and accept or reject'
testResponse == 'Check your SUT logs and accept or reject'
}
return (
<Typography variant="body2">
<strong>Step 3:</strong> Check the logs to accept/reject the response
</Typography>
)
}

if (endpointsGenerated) {
return (
<Typography variant="body2">
<strong>Step 2:</strong> Send XDR message to endpoint and refresh to check status.
</Typography>
)
}

return (
<>
<Typography variant="body2">
<strong>Step 1:</strong> Provide your{' '}
{inputs.map((input, i) => (
<span key={i}>
{input.name}
{inputs.length - 1 === i ? '. ' : ', '}
</span>
))}
{role === 'sender' ? senderText : receiverText}
</Typography>
</>
)
}
const [formData] = useState<{ [key: string]: FieldValue }>(() => {
const initialData: { [key: string]: FieldValue } = {}
test.moreInfo?.fields?.forEach((field) => {
Expand All @@ -248,6 +262,14 @@ const TestCard = ({ test }: TestCardProps) => {
}))
}
}

const fixEndpoint = (url: string): string => {
if (url && !url.startsWith('http://') && !url.startsWith('https://')) {
return 'https://' + url
}
return url
}

const handleRunTest = async () => {
if (!session) {
setAlertMessage('You must be logged in and have a valid session to perform this action.')
Expand Down Expand Up @@ -283,6 +305,7 @@ const TestCard = ({ test }: TestCardProps) => {
setIsFinished(true)
if (status.results) {
setValidationResults(status.results)
setEndpointsGenerated(false)
}
} else {
const response = await handleXDRAPICall({
Expand All @@ -308,13 +331,20 @@ const TestCard = ({ test }: TestCardProps) => {
if (test.criteria && !manualValidationIDs.includes(test.id.toString())) {
setCriteriaMet(response.criteriaMet)
}
if (
!endpointTestIds.includes(test.id.toString()) &&
(response.endpoint.length > 10 || response.endpointTLS.length > 10)
) {
setEndpointsGenerated(true)
setEndpoint(response.endpoint || defaultEndpoint)
setEndpointTLS(response.endpointTLS || defaultEndpointTLS)
if (!endpointTestIds.includes(test.id.toString())) {
let endpointSet = false
if (response.endpoint && response.endpoint.length > 10) {
setEndpoint(fixEndpoint(response.endpoint))
endpointSet = true
}
if (response.endpointTLS && response.endpointTLS.length > 10) {
setEndpointTLS(fixEndpoint(response.endpointTLS))
endpointSet = true
}
if (endpointSet) {
console.log('setting endpoints generated')
setEndpointsGenerated(true)
}
}
setTestRequestRequest(response.testRequest)
setTestRequestResponse(response.testResponse)
Expand Down Expand Up @@ -372,11 +402,9 @@ const TestCard = ({ test }: TestCardProps) => {
}

const renderCriteriaMetIcon = () => {
console.log('criteria met icon: ', criteriaMet)
if (endpointsGenerated && criteriaMet != 'PASSED' && manualValidationIDs.includes(test.id.toString())) {
if (endpointsGenerated) {
return <Typography style={{ color: 'red' }}>Pending</Typography>
}
if (criteriaMet === 'TRUE' || criteriaMet === 'PASSED' || criteriaMet === 'SUCCESS') {
} else if (criteriaMet === 'TRUE' || criteriaMet === 'PASSED' || criteriaMet === 'SUCCESS') {
return <CheckCircleIcon style={{ color: 'green' }} />
} else if (criteriaMet === 'FALSE' || criteriaMet === 'ERROR') {
return <CancelIcon style={{ color: 'red' }} />
Expand Down Expand Up @@ -431,7 +459,12 @@ const TestCard = ({ test }: TestCardProps) => {
return <Typography>No C-CDA Validation results available.</Typography>
}
} else {
const content = logType === 'request' ? testRequest : testResponse
let content = logType === 'request' ? testRequest : testResponse

if ((test.id === '20amu2' || test.id === '20bmu2') && isFinished && (!testRequest || !testResponse)) {
content = 'Check your SUT logs and accept or reject'
}

return <XMLDisplay xmlContent={content || 'No logs to display.'} />
}
}
Expand Down Expand Up @@ -525,19 +558,16 @@ const TestCard = ({ test }: TestCardProps) => {
{renderLogs()}
<Divider sx={{ mb: 2, mt: 2 }} />
<Box sx={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', mt: 2 }}>
{test.criteria &&
manualValidationIDs.includes(test.id.toString()) &&
testRequest &&
testRequest.length > 0 && (
<Box sx={{ display: 'flex', gap: 1 }}>
<Button variant="contained" color="primary" onClick={handleAcceptTest}>
Accept
</Button>
<Button variant="outlined" color="primary" onClick={handleRejectTest}>
Reject
</Button>
</Box>
)}
{test.criteria && manualValidationIDs.includes(test.id.toString()) && isFinished && (
<Box sx={{ display: 'flex', gap: 1 }}>
<Button variant="contained" color="primary" onClick={handleAcceptTest}>
Accept
</Button>
<Button variant="outlined" color="primary" onClick={handleRejectTest}>
Reject
</Button>
</Box>
)}
<Button variant="contained" onClick={handleToggleLogs}>
Close Logs
</Button>
Expand All @@ -550,14 +580,25 @@ const TestCard = ({ test }: TestCardProps) => {
{test.desc}
</Typography>
{_.isEqual(test.sutRole, 'receiver') && _.has(test, 'inputs') && test.inputs !== undefined && (
<StepText inputs={test.inputs} role={test.sutRole} endpointsGenerated={endpointsGenerated} />
<StepText
inputs={test.inputs}
role={test.sutRole}
endpointsGenerated={endpointsGenerated}
criteriaMet={criteriaMet}
/>
)}
{_.isEqual(test.sutRole, 'sender') && _.has(test, 'inputs') && test.inputs !== undefined && (
<StepText inputs={test.inputs} role={test.sutRole} endpointsGenerated={endpointsGenerated} />
<StepText
inputs={test.inputs}
role={test.sutRole}
endpointsGenerated={endpointsGenerated}
criteriaMet={criteriaMet}
/>
)}
{_.has(test, 'inputs') &&
test.inputs &&
!endpointsGenerated &&
!isFinished &&
test.inputs.filter(shouldDisplayInput).map((input) => (
<Box sx={{ pt: 2 }} key={input.key || 'default-key'}>
<FormControl fullWidth>
Expand Down Expand Up @@ -597,16 +638,22 @@ const TestCard = ({ test }: TestCardProps) => {
Endpoint
</Button>
</Tooltip>
<Tooltip placement="bottom" title={endpointsGenerated ? endpointTLS : `${defaultEndpointTLS}`} arrow>
<Button
sx={{ ml: 2 }}
color="secondary"
endIcon={<ContentPasteGoIcon />}
onClick={(e) => handleClick(e, endpointsGenerated ? endpointTLS : `${defaultEndpointTLS}`)}
{test.id != 7 && (
<Tooltip
placement="bottom"
title={endpointsGenerated ? endpointTLS : `${defaultEndpointTLS}`}
arrow
>
Endpoint TLS
</Button>
</Tooltip>
<Button
sx={{ ml: 2 }}
color="secondary"
endIcon={<ContentPasteGoIcon />}
onClick={(e) => handleClick(e, endpointsGenerated ? endpointTLS : `${defaultEndpointTLS}`)}
>
Endpoint TLS
</Button>
</Tooltip>
)}
</Box>
)}
{requiresCCDADocument() && !endpointsGenerated && (
Expand Down Expand Up @@ -661,11 +708,9 @@ const TestCard = ({ test }: TestCardProps) => {
</Button>
</Box>
)}
{test.criteria &&
manualValidationIDs.includes(test.id.toString()) &&
(testRequest || testResponse) &&
isFinished &&
!apiError && <Typography sx={{ ml: 2, color: 'error.main' }}>Waiting Validation</Typography>}
{test.criteria && manualValidationIDs.includes(test.id.toString()) && isFinished && !apiError && (
<Typography sx={{ ml: 2, color: 'error.main' }}>Waiting Validation</Typography>
)}
</Box>
</Box>
</>
Expand Down
8 changes: 4 additions & 4 deletions src/components/direct/test-by-criteria/ServerActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,10 @@ export async function handleXDRAPICall(data: XDRAPICallData): Promise<XDRAPIResp
let endpointTLS = ''

if (content && content.content && content.content.value) {
testRequest = content.content.value.request || content.message
testResponse = content.content.value.response || content.message
endpoint = content.content.value.endpoint || content.message
endpointTLS = content.content.value.endpointTLS || content.message
testRequest = content.content.value.request
testResponse = content.content.value.response
endpoint = content.content.value.endpoint
endpointTLS = content.content.value.endpointTLS
} else {
console.error('Invalid response structure:', content)
testRequest = content.message
Expand Down

0 comments on commit c186a62

Please sign in to comment.