-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#3383] Added tests for plugin validator
- Loading branch information
Showing
5 changed files
with
107 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const phoneNumberComponent = { | ||
label: 'Phone Number', | ||
key: 'phonenumber', | ||
type: 'phoneNumber', | ||
input: true, | ||
validate: { | ||
backendApi: true, | ||
plugins: ['phonenumber-international', 'phonenumber-nl'], | ||
}, | ||
}; | ||
|
||
const validSamples = ['630123456', '+31630123456']; | ||
const inValidSamples = ['63012345', '+3163012345']; | ||
|
||
export {phoneNumberComponent, validSamples, inValidSamples}; |
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 was deleted.
Oops, something went wrong.
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,65 @@ | ||
import { | ||
inValidSamples, | ||
phoneNumberComponent, | ||
validSamples, | ||
} from 'jstests/formio/components/fixtures/phonenumber'; | ||
import {invalid} from 'moment'; | ||
|
||
import {BASE_URL} from 'api-mocks'; | ||
import mswServer from 'api-mocks/msw-server'; | ||
import {pluginsAPIValidator} from 'formio/validators/plugins'; | ||
|
||
import { | ||
mockDutchInValidPost, | ||
mockDutchValidPost, | ||
mockInternationalInValidPost, | ||
mockInternationalValidPost, | ||
} from './mocks'; | ||
|
||
describe('The OpenForms plugins validation', () => { | ||
test('tests expected errors are returned when phone number is invalid', async () => { | ||
mswServer.use(mockDutchInValidPost, mockInternationalInValidPost); | ||
|
||
const component = { | ||
component: phoneNumberComponent, | ||
options: { | ||
baseUrl: BASE_URL, | ||
}, | ||
}; | ||
|
||
for (const sample of inValidSamples) { | ||
const result = await pluginsAPIValidator.check(component, undefined, sample); | ||
expect(result).toBe('Invalid international phone number<br>Invalid dutch phone number'); | ||
} | ||
}); | ||
|
||
test('tests no errors are returned when phone number is valid', async () => { | ||
mswServer.use(mockDutchValidPost, mockInternationalValidPost); | ||
|
||
const component = { | ||
component: phoneNumberComponent, | ||
options: { | ||
baseUrl: BASE_URL, | ||
}, | ||
}; | ||
|
||
for (const sample of validSamples) { | ||
const result = await pluginsAPIValidator.check(component, undefined, sample); | ||
expect(result).toBe(true); | ||
} | ||
}); | ||
|
||
test('tests no errors are returned when phone number is null', async () => { | ||
mswServer.use(mockDutchValidPost, mockInternationalValidPost); | ||
|
||
const component = { | ||
component: phoneNumberComponent, | ||
options: { | ||
baseUrl: BASE_URL, | ||
}, | ||
}; | ||
|
||
const result = await pluginsAPIValidator.check(component, undefined, null); | ||
expect(result).toBe(true); | ||
}); | ||
}); |