-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into PIMS-1869-BCA-XREF
- Loading branch information
Showing
10 changed files
with
113 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ describe('UNIT - Ches Services', () => { | |
text: () => '{"access_token":"eyAiYSI6IDEgfQ==.ewoiZXhwIjoxCn0="}', | ||
})); | ||
_fetch.mockImplementationOnce(() => ({ | ||
ok: true, | ||
text: () => `{ "messages": [{}], "txId": "${randomUUID()}" }`, | ||
})); | ||
const response = await chesServices.sendEmailAsync(email, keycloak); | ||
|
@@ -35,10 +36,37 @@ describe('UNIT - Ches Services', () => { | |
text: () => '{"access_token":"eyAiYSI6IDEgfQ==.ewoiZXhwIjoxCn0="}', | ||
})); | ||
_fetch.mockImplementationOnce(() => ({ | ||
ok: false, | ||
text: () => `{ "messages": [{}], "txId": "${randomUUID()}" }`, | ||
})); | ||
expect(async () => await chesServices.sendEmailAsync(email, keycloak)).rejects.toThrow(); | ||
}); | ||
it('should return null if the CHES response is not OK', async () => { | ||
const email = produceEmail({ cc: ['[email protected]'], bcc: ['[email protected]'] }); | ||
const keycloak = producePimsRequestUser(); | ||
_fetch.mockImplementationOnce(() => ({ | ||
text: () => '{"access_token":"eyAiYSI6IDEgfQ==.ewoiZXhwIjoxCn0="}', | ||
})); | ||
_fetch.mockImplementationOnce(() => ({ | ||
ok: false, | ||
text: () => `{ "messages": [{}], "txId": "${randomUUID()}" }`, | ||
})); | ||
const result = await chesServices.sendEmailAsync(email, keycloak); | ||
expect(result).toBeNull(); | ||
}); | ||
it('should return null if the CHES response has no text length', async () => { | ||
const email = produceEmail({ cc: ['[email protected]'], bcc: ['[email protected]'] }); | ||
const keycloak = producePimsRequestUser(); | ||
_fetch.mockImplementationOnce(() => ({ | ||
text: () => '{"access_token":"eyAiYSI6IDEgfQ==.ewoiZXhwIjoxCn0="}', | ||
})); | ||
_fetch.mockImplementationOnce(() => ({ | ||
ok: true, | ||
text: () => ``, | ||
})); | ||
const result = await chesServices.sendEmailAsync(email, keycloak); | ||
expect(result).toBeNull(); | ||
}); | ||
it('should send email with extra config', async () => { | ||
const email: IEmail = produceEmail({}); | ||
const keycloak = producePimsRequestUser(); | ||
|
@@ -55,6 +83,7 @@ describe('UNIT - Ches Services', () => { | |
text: () => '{"access_token":"eyAiYSI6IDEgfQ==.ewoiZXhwIjoxCn0="}', | ||
})); | ||
_fetch.mockImplementationOnce(() => ({ | ||
ok: true, | ||
text: () => `{ "messages": [{}], "txId": "${randomUUID()}" }`, | ||
})); | ||
const response = await chesServices.sendEmailAsync(email, keycloak); | ||
|
@@ -67,8 +96,8 @@ describe('UNIT - Ches Services', () => { | |
text: () => '{"access_token":"eyAiYSI6IDEgfQ==.ewoiZXhwIjoxCn0="}', | ||
})); | ||
_fetch.mockImplementationOnce(() => ({ | ||
ok: true, | ||
text: () => ` | ||
{ | ||
"createdTS": 1560000000, | ||
|
@@ -102,6 +131,7 @@ describe('UNIT - Ches Services', () => { | |
text: () => '{"access_token":"eyAiYSI6IDEgfQ==.ewoiZXhwIjoxCn0="}', | ||
})); | ||
_fetch.mockImplementationOnce(() => ({ | ||
ok: true, | ||
text: () => ` | ||
[ | ||
{ | ||
|
@@ -143,6 +173,7 @@ describe('UNIT - Ches Services', () => { | |
text: () => '{"access_token":"eyAiYSI6IDEgfQ==.ewoiZXhwIjoxCn0="}', | ||
})); | ||
_fetch.mockImplementationOnce(() => ({ | ||
ok: true, | ||
text: () => ` | ||
{ | ||
|
@@ -177,6 +208,7 @@ describe('UNIT - Ches Services', () => { | |
text: () => '{"access_token":"eyAiYSI6IDEgfQ==.ewoiZXhwIjoxCn0="}', | ||
})); | ||
_fetch.mockImplementationOnce(() => ({ | ||
ok: true, | ||
text: () => ` | ||
{ | ||
|
@@ -202,6 +234,7 @@ describe('UNIT - Ches Services', () => { | |
text: () => '{"access_token":"eyAiYSI6IDEgfQ==.ewoiZXhwIjoxCn0="}', | ||
})); | ||
_fetch.mockImplementationOnce(() => ({ | ||
ok: true, | ||
text: () => ` | ||
{ | ||
|
@@ -238,6 +271,7 @@ describe('UNIT - Ches Services', () => { | |
text: () => '{"access_token":"eyAiYSI6IDEgfQ==.ewoiZXhwIjoxCn0="}', | ||
})); | ||
_fetch.mockImplementationOnce(() => ({ | ||
ok: true, | ||
text: () => ` | ||
[ | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import React from 'react'; | ||
import { SxProps, Typography, Box, useTheme, Switch } from '@mui/material'; | ||
import { Controller, useFormContext } from 'react-hook-form'; | ||
|
||
interface ToggleSwitchProps { | ||
name: string; | ||
label: string; | ||
sx?: SxProps; | ||
required?: boolean; | ||
} | ||
|
||
const ToggleSwitch = (props: ToggleSwitchProps) => { | ||
const { control } = useFormContext(); | ||
const theme = useTheme(); | ||
const { name, label, required } = props; | ||
return ( | ||
<Controller | ||
name={name} | ||
control={control} | ||
rules={{ validate: (value) => !required || value || 'Required field.' }} | ||
render={({ field: { onChange, value, onBlur }, fieldState: { error } }) => ( | ||
<> | ||
<Box | ||
sx={{ | ||
display: 'flex', | ||
alignItems: 'center', | ||
}} | ||
> | ||
<Switch | ||
id={`single-checkbox-${name}`} | ||
onChange={(_, data) => onChange(data)} | ||
onBlur={onBlur} | ||
checked={!!value} | ||
required={required} | ||
/> | ||
<Typography> | ||
{label} {required ? <sup>{'*'}</sup> : <></>} | ||
</Typography> | ||
</Box> | ||
{!!error && !!error.message ? ( | ||
<Box> | ||
<Typography ml={'3.2em'} fontSize={'smaller'} color={theme.palette.error.main}> | ||
{error.message} | ||
</Typography> | ||
</Box> | ||
) : ( | ||
<></> | ||
)} | ||
</> | ||
)} | ||
/> | ||
); | ||
}; | ||
|
||
export default ToggleSwitch; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters