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

GREG-261: Adding test for default mobile country code

parent e91c19ec
No related branches found
No related tags found
1 merge request!324GREG-261: Default country code can be blank in form
Pipeline #132397 passed
......@@ -392,3 +392,63 @@ test('Guest allowed to proceed in wizard if data is valid', async () => {
expect(nextHandler.mock.calls.length).toBe(1)
})
test('Default country code gets set in form values', async () => {
// This stores the data sent from the form when the user clicks submit
let guestRegisterData: GuestRegisterData | null = null
const nextHandler = (registerData: GuestRegisterData) => {
guestRegisterData = registerData
}
const allFeaturesOn = {
displayContactAtUnit: true,
displayComment: true,
displayContactAtUnitGuestInput: true,
showGenderFieldForGuest: true,
}
// Leave the mobile phone country code blank, it should
// be populated with a default value
const formData: GuestRegisterData = {
firstName: 'Test',
lastName: 'Test2',
mobilePhoneCountry: '',
mobilePhone: '97543992',
nationalIdNumber: '',
passportNumber: '12345678',
passportNationality: 'NO',
dateOfBirth: addYears(-20)(new Date()),
gender: 'male',
}
const testData = getEmptyGuestData()
testData.gender = 'male'
const submitMock = jest.fn()
// Need this to be able to call on the submit-method on the form
const reference = {
current: {
doSubmit: submitMock,
},
}
render(
<FeatureContext.Provider value={allFeaturesOn}>
<LocalizationProvider dateAdapter={AdapterDateFns}>
<GuestRegisterStep
nextHandler={nextHandler}
initialGuestData={testData}
registerData={formData}
ref={reference}
/>
</LocalizationProvider>
</FeatureContext.Provider>,
)
expect(guestRegisterData).toBeNull()
await act(async () => reference.current?.doSubmit())
// Check that the mobile country has gotten the default value
// @ts-ignore
expect(guestRegisterData.mobilePhoneCountry).toEqual('NO')
})
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