overleaf/services/web/test/frontend/shared/utils/email.test.tsx
Miguel Serrano 0e782d3fb6 [Settings] "Start by adding your email address" hint (#8173)
* [Settings] "Start by adding your email address" hint

GitOrigin-RevId: 19d432c70b173752ee7c6d8978dd6be16b042921
2022-05-31 08:04:50 +00:00

46 lines
1.2 KiB
TypeScript

import { expect } from 'chai'
import { isValidEmail } from '../../../../frontend/js/shared/utils/email'
const validEmailAddresses = [
'email@example.com',
'firstname.lastname@example.com',
'firstname-lastname@example.com',
'email@subdomain.example.com',
'firstname+lastname@example.com',
'1234567890@example.com',
'email@example-one.com',
'_@example.com',
'email@example.name',
'email@example.co.jp',
]
const invalidEmailAddresses = [
'plaintext',
'#@%^%#$@#$@#.com',
'@example.com',
'email.example.com',
'.email@example.com',
'email.@example.com',
'email..email@example.com',
'email@example.com (Joe Smith)',
'email@example',
'email@111.222.333.44444',
'email@example..com',
]
describe('isValidEmail', function () {
it('should return true for valid email addresses', function () {
validEmailAddresses.forEach(email =>
expect(isValidEmail(email)).to.equal(true, email + ' should be valid ')
)
})
it('should return false for invalid email addresses', function () {
invalidEmailAddresses.forEach(email =>
expect(isValidEmail(email)).to.equal(
false,
email + ' should not be valid '
)
)
})
})