generated from openedx/frontend-template-application
-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: frontend validation on email field (#1249)
- Loading branch information
1 parent
8efb225
commit 99bca1b
Showing
2 changed files
with
100 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { isFormValid } from '../utils'; | ||
|
||
describe('Payload validation', () => { | ||
let formatMessage; | ||
let configurableFormFields; | ||
let fieldDescriptions; | ||
|
||
beforeEach(() => { | ||
formatMessage = jest.fn(msg => msg); | ||
configurableFormFields = { | ||
confirm_email: true, | ||
}; | ||
fieldDescriptions = {}; | ||
}); | ||
|
||
test('validates name field correctly', () => { | ||
const payload = { name: ' ' }; | ||
const errors = {}; | ||
const { isValid, fieldErrors } = isFormValid( | ||
payload, | ||
errors, | ||
configurableFormFields, | ||
fieldDescriptions, | ||
formatMessage); | ||
|
||
expect(fieldErrors.name).toBeDefined(); | ||
expect(isValid).toBe(false); | ||
}); | ||
|
||
test('validates email field correctly', () => { | ||
const payload = { email: 'invalid-email' }; | ||
const errors = {}; | ||
const { isValid, fieldErrors } = isFormValid( | ||
payload, errors, configurableFormFields, fieldDescriptions, formatMessage); | ||
|
||
expect(fieldErrors.email).toBeDefined(); | ||
expect(isValid).toBe(false); | ||
}); | ||
|
||
test('validates username field correctly', () => { | ||
const payload = { username: 'invalid username' }; | ||
const errors = {}; | ||
const { isValid, fieldErrors } = isFormValid( | ||
payload, errors, configurableFormFields, fieldDescriptions, formatMessage); | ||
|
||
expect(fieldErrors.username).toBeDefined(); | ||
expect(isValid).toBe(false); | ||
}); | ||
|
||
test('validates password field correctly', () => { | ||
const payload = { password: 'short' }; | ||
const errors = {}; | ||
const { isValid, fieldErrors } = isFormValid( | ||
payload, errors, configurableFormFields, fieldDescriptions, formatMessage); | ||
|
||
expect(fieldErrors.password).toBeDefined(); | ||
expect(isValid).toBe(false); | ||
}); | ||
|
||
test('validates multiple fields correctly', () => { | ||
const payload = { | ||
name: 'InvalidName!', | ||
email: 'invalid-email', | ||
username: 'invalid username', | ||
password: 'short', | ||
}; | ||
const errors = {}; | ||
const { isValid, fieldErrors } = isFormValid( | ||
payload, errors, configurableFormFields, fieldDescriptions, formatMessage); | ||
|
||
expect(fieldErrors.name).toBeDefined(); | ||
expect(fieldErrors.email).toBeDefined(); | ||
expect(fieldErrors.username).toBeDefined(); | ||
expect(fieldErrors.password).toBeDefined(); | ||
expect(isValid).toBe(false); | ||
}); | ||
}); |
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