Skip to content
Snippets Groups Projects
Commit 68cbbf61 authored by Tore.Brede's avatar Tore.Brede
Browse files

GREG-165: Adding some more rules for when fields should be visible

parent 60e40478
No related branches found
No related tags found
1 merge request!239GREG-165: Part 1 : Handle missing information from Feide
Pipeline #109692 passed
......@@ -3,6 +3,7 @@
* the form needs to enable and disable fields.
*/
export type FormSetup = {
allow_first_name_editable: boolean
allow_last_name_editable: boolean
allowFirstNameEditable: boolean
allowLastNameEditable: boolean
disableIdentifierFields: boolean
}
......@@ -97,3 +97,55 @@ test('Name editable if missing and invite is Feide', async () => {
expect(screen.queryByTestId('last-name-input-text')).toBeEnabled()
})
})
test('Identifier fields disabled if invite if Feide and national ID present', async () => {
const nextHandler = (registerData: GuestRegisterData) => {
console.log(`Entered data: ${registerData}`)
}
const testData = getEmptyGuestData()
testData.authentication_method = AuthenticationMethod.Feide
testData.fnr = '12042335418'
render(
<LocalizationProvider dateAdapter={AdapterDateFns}>
<GuestRegisterStep
nextHandler={nextHandler}
initialGuestData={testData}
registerData={null}
/>
</LocalizationProvider>
)
await waitFor(() => {
expect(screen.queryByTestId('national-id-number-input')).toBeDisabled()
expect(screen.queryByTestId('passport_number_input')).toBeDisabled()
expect(screen.queryByTestId('passport-nationality-input')).toBeDisabled()
})
})
test('Identifier fields enabled if invite if Feide but national ID number missing', async () => {
const nextHandler = (registerData: GuestRegisterData) => {
console.log(`Entered data: ${registerData}`)
}
const testData = getEmptyGuestData()
testData.authentication_method = AuthenticationMethod.Feide
testData.fnr = ''
render(
<LocalizationProvider dateAdapter={AdapterDateFns}>
<GuestRegisterStep
nextHandler={nextHandler}
initialGuestData={testData}
registerData={null}
/>
</LocalizationProvider>
)
await waitFor(() => {
expect(screen.queryByTestId('national-id-number-input')).toBeEnabled()
expect(screen.queryByTestId('passport_number_input')).toBeEnabled()
expect(screen.queryByTestId('passport-nationality-input')).toBeEnabled()
})
})
......@@ -225,14 +225,21 @@ const GuestRegisterStep = forwardRef(
)
const formSetup: FormSetup = {
allow_first_name_editable:
allowFirstNameEditable:
initialGuestData.authentication_method ===
AuthenticationMethod.Invite ||
initialGuestData.first_name.length === 0,
allow_last_name_editable:
allowLastNameEditable:
initialGuestData.authentication_method ===
AuthenticationMethod.Invite ||
initialGuestData.last_name.length === 0,
// If there is a national ID number (presumably from Feide),
// already present, then do not allow the user to change the data
// in the identifier fields
disableIdentifierFields:
initialGuestData.authentication_method === AuthenticationMethod.Feide &&
initialGuestData.fnr !== null &&
initialGuestData.fnr?.length !== 0,
}
return (
......@@ -267,7 +274,7 @@ const GuestRegisterStep = forwardRef(
onChange={onChange}
error={!!errors.firstName}
helperText={errors.firstName && errors.firstName.message}
disabled={!formSetup.allow_first_name_editable}
disabled={!formSetup.allowFirstNameEditable}
inputProps={{
'data-testid': 'first-name-input-text',
}}
......@@ -289,7 +296,7 @@ const GuestRegisterStep = forwardRef(
onChange={onChange}
error={!!errors.lastName}
helperText={errors.lastName && errors.lastName.message}
disabled={!formSetup.allow_last_name_editable}
disabled={!formSetup.allowLastNameEditable}
inputProps={{
'data-testid': 'last-name-input-text',
}}
......@@ -495,6 +502,10 @@ const GuestRegisterStep = forwardRef(
helperText={
errors.nationalIdNumber && errors.nationalIdNumber.message
}
disabled={formSetup.disableIdentifierFields}
inputProps={{
'data-testid': 'national-id-number-input',
}}
/>
)}
/>
......@@ -522,6 +533,10 @@ const GuestRegisterStep = forwardRef(
}
return selected
}}
disabled={formSetup.disableIdentifierFields}
inputProps={{
'data-testid': 'passport-nationality-input',
}}
>
<MenuItem disabled value="">
{t('input.passportNationality')}
......@@ -538,15 +553,13 @@ const GuestRegisterStep = forwardRef(
render={({ field }) => (
<TextField
id="passportNumber"
data-testid="passport_number_input"
inputProps={{
'data-testid': 'passport_number_input',
}}
value={field.value}
label={t('input.passportNumber')}
onChange={field.onChange}
disabled={
initialGuestData.authentication_method !==
AuthenticationMethod.Invite &&
initialGuestData.passport !== null
}
disabled={formSetup.disableIdentifierFields}
/>
)}
/>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment