2020-09-01 13:55:28 +00:00
/* eslint-disable no-useless-escape */
2020-10-16 13:16:01 +00:00
import React from "react" ;
import { mount , shallow } from "enzyme" ;
import EmailInput from "." ;
2021-03-02 08:25:11 +00:00
import { EmailSettings } from "../utils/email/" ;
2019-10-11 17:59:59 +00:00
const baseProps = {
2020-10-16 13:16:01 +00:00
id : "emailInputId" ,
name : "emailInputName" ,
value : "" ,
size : "base" ,
2019-10-11 17:59:59 +00:00
scale : false ,
isDisabled : false ,
isReadOnly : false ,
maxLength : 255 ,
2020-10-16 13:16:01 +00:00
placeholder : "email" ,
2019-10-11 17:59:59 +00:00
onChange : ( ) => jest . fn ( ) ,
2020-10-16 13:16:01 +00:00
onValidateInput : ( ) => jest . fn ( ) ,
} ;
2019-10-11 17:59:59 +00:00
2020-10-16 13:16:01 +00:00
describe ( "<EmailInput />" , ( ) => {
it ( "Init invalid value test" , ( ) => {
2019-12-17 13:37:16 +00:00
const email = "zzz" ;
const wrapper = shallow ( < EmailInput value = { email } / > ) . instance ( ) ;
2019-12-23 09:02:03 +00:00
expect ( wrapper . state . isValidEmail . isValid ) . toBe ( false ) ;
2019-12-17 13:37:16 +00:00
} ) ;
2020-10-16 13:16:01 +00:00
it ( "Clean valid value test" , ( ) => {
2019-12-17 13:37:16 +00:00
const email = "zzz" ;
const wrapper = shallow ( < EmailInput value = { email } / > ) . instance ( ) ;
let event = { target : { value : "simple@example.com" } } ;
2019-12-19 07:35:25 +00:00
wrapper . onChange ( event ) ;
2019-12-17 13:37:16 +00:00
2019-12-23 09:02:03 +00:00
expect ( wrapper . state . isValidEmail . isValid ) . toBe ( true ) ;
2019-12-17 13:37:16 +00:00
event = { target : { value : "" } } ;
2019-12-19 07:35:25 +00:00
wrapper . onChange ( event ) ;
2019-12-17 13:37:16 +00:00
2019-12-23 09:02:03 +00:00
expect ( wrapper . state . isValidEmail . isValid ) . toBe ( false ) ;
2019-12-17 13:37:16 +00:00
} ) ;
2020-10-16 13:16:01 +00:00
it ( "Change value prop test" , ( ) => {
2019-12-17 13:37:16 +00:00
const email = "zzz" ;
const wrapper = mount ( < EmailInput value = { email } / > ) ;
expect ( wrapper . state ( ) . inputValue ) . toBe ( email ) ;
2020-10-16 13:16:01 +00:00
wrapper . setProps ( { value : "bar" } ) ;
2019-12-19 07:35:25 +00:00
2019-12-23 09:02:03 +00:00
expect ( wrapper . state ( ) . isValidEmail . isValid ) . toBe ( false ) ;
2019-12-17 13:37:16 +00:00
expect ( wrapper . state ( ) . inputValue ) . toBe ( "bar" ) ;
} ) ;
2020-10-16 13:16:01 +00:00
it ( "Custom validation test" , ( ) => {
2019-12-25 13:56:09 +00:00
const email = "zzz" ;
const customValidate = ( value ) => {
const isValid = ! ! ( value && value . length > 0 ) ;
2020-10-16 13:16:01 +00:00
return {
2019-12-25 13:56:09 +00:00
isValid : isValid ,
2020-10-16 13:16:01 +00:00
errors : isValid ? [ ] : [ "incorrect email" ] ,
} ;
} ;
2019-12-25 13:56:09 +00:00
2020-10-16 13:16:01 +00:00
const wrapper = mount (
< EmailInput value = { email } customValidate = { customValidate } / >
) ;
2019-12-25 13:56:09 +00:00
expect ( wrapper . state ( ) . inputValue ) . toBe ( email ) ;
expect ( wrapper . state ( ) . isValidEmail . isValid ) . toBe ( true ) ;
2020-10-16 13:16:01 +00:00
wrapper . setProps ( { value : "bar" } ) ;
2019-12-25 13:56:09 +00:00
expect ( wrapper . state ( ) . isValidEmail . isValid ) . toBe ( true ) ;
expect ( wrapper . state ( ) . inputValue ) . toBe ( "bar" ) ;
2020-10-16 13:16:01 +00:00
wrapper . setProps ( { value : "" } ) ;
2019-12-25 13:56:09 +00:00
expect ( wrapper . state ( ) . isValidEmail . isValid ) . toBe ( false ) ;
} ) ;
2020-10-16 13:16:01 +00:00
it ( "renders without error" , ( ) => {
2019-10-11 17:59:59 +00:00
const wrapper = mount ( < EmailInput { ... baseProps } / > ) ;
expect ( wrapper ) . toExist ( ) ;
} ) ;
2019-12-19 07:35:25 +00:00
it ( 'isValidEmail is "false" after deleting value' , ( ) => {
2019-10-16 05:58:06 +00:00
const wrapper = mount ( < EmailInput { ... baseProps } / > ) ;
const event = { target : { value : "test" } } ;
2020-10-16 13:16:01 +00:00
wrapper . simulate ( "change" , event ) ;
2019-10-16 05:58:06 +00:00
2019-12-23 09:02:03 +00:00
expect ( wrapper . state ( ) . isValidEmail . isValid ) . toBe ( false ) ;
2019-10-16 05:58:06 +00:00
const emptyValue = { target : { value : "" } } ;
2020-10-16 13:16:01 +00:00
wrapper . simulate ( "change" , emptyValue ) ;
2019-10-16 05:58:06 +00:00
2019-12-23 09:02:03 +00:00
expect ( wrapper . state ( ) . isValidEmail . isValid ) . toBe ( false ) ;
2019-10-16 05:58:06 +00:00
} ) ;
2019-10-15 11:21:59 +00:00
2020-10-16 13:16:01 +00:00
it ( "passed valid email: simple@example.com" , ( ) => {
const onValidateInput = jest . fn ( ( isValidEmail ) => {
2019-12-23 09:02:03 +00:00
expect ( isValidEmail . isValid ) . toEqual ( true ) ;
2019-10-15 06:07:02 +00:00
} ) ;
2020-10-16 13:16:01 +00:00
const wrapper = mount (
< EmailInput { ... baseProps } onValidateInput = { onValidateInput } / >
) ;
2019-10-15 06:07:02 +00:00
const event = { target : { value : "simple@example.com" } } ;
2020-10-16 13:16:01 +00:00
wrapper . simulate ( "change" , event ) ;
2019-10-15 06:07:02 +00:00
} ) ;
2020-10-16 13:16:01 +00:00
it ( "passed valid email: disposable.style.email.with+symbol@example.com" , ( ) => {
const onValidateInput = jest . fn ( ( isValidEmail ) => {
2019-12-23 09:02:03 +00:00
expect ( isValidEmail . isValid ) . toEqual ( true ) ;
2019-10-15 06:07:02 +00:00
} ) ;
2020-10-16 13:16:01 +00:00
const wrapper = mount (
< EmailInput { ... baseProps } onValidateInput = { onValidateInput } / >
) ;
2019-10-15 06:07:02 +00:00
2020-10-16 13:16:01 +00:00
const event = {
target : { value : "disposable.style.email.with+symbol@example.com" } ,
} ;
2019-10-15 06:07:02 +00:00
2020-10-16 13:16:01 +00:00
wrapper . simulate ( "change" , event ) ;
2019-10-15 06:07:02 +00:00
} ) ;
2020-10-16 13:16:01 +00:00
it ( "passed valid email: user.name+tag+sorting@example.com" , ( ) => {
const onValidateInput = jest . fn ( ( isValidEmail ) => {
2019-12-23 09:02:03 +00:00
expect ( isValidEmail . isValid ) . toEqual ( true ) ;
2019-10-15 06:07:02 +00:00
} ) ;
2020-10-16 13:16:01 +00:00
const wrapper = mount (
< EmailInput { ... baseProps } onValidateInput = { onValidateInput } / >
) ;
2019-10-15 06:07:02 +00:00
const event = { target : { value : "user.name+tag+sorting@example.com" } } ;
2020-10-16 13:16:01 +00:00
wrapper . simulate ( "change" , event ) ;
2019-10-15 06:07:02 +00:00
} ) ;
2020-10-16 13:16:01 +00:00
it ( "passed valid email with one-letter local-part: x@example.com" , ( ) => {
const onValidateInput = jest . fn ( ( isValidEmail ) => {
2019-12-23 09:02:03 +00:00
expect ( isValidEmail . isValid ) . toEqual ( true ) ;
2019-10-15 06:07:02 +00:00
} ) ;
2020-10-16 13:16:01 +00:00
const wrapper = mount (
< EmailInput { ... baseProps } onValidateInput = { onValidateInput } / >
) ;
2019-10-15 06:07:02 +00:00
const event = { target : { value : "x@example.com" } } ;
2020-10-16 13:16:01 +00:00
wrapper . simulate ( "change" , event ) ;
2019-10-15 06:07:02 +00:00
} ) ;
2019-10-15 11:21:59 +00:00
2020-10-16 13:16:01 +00:00
it ( "passed valid email, local domain name with no TLD: admin@mailserver1" , ( ) => {
const onValidateInput = jest . fn ( ( isValidEmail ) => {
2019-12-23 09:02:03 +00:00
expect ( isValidEmail . isValid ) . toEqual ( false ) ;
2019-10-15 11:21:59 +00:00
} ) ;
2020-10-16 13:16:01 +00:00
const wrapper = mount (
< EmailInput { ... baseProps } onValidateInput = { onValidateInput } / >
) ;
2019-10-15 11:21:59 +00:00
const event = { target : { value : "admin@mailserver1" } } ;
2020-10-16 13:16:01 +00:00
wrapper . simulate ( "change" , event ) ;
2019-10-15 11:21:59 +00:00
} ) ;
2020-10-16 13:16:01 +00:00
it ( "passed valid email, local domain name with no TLD: admin@mailserver1 (settings: allowLocalDomainName = true)" , ( ) => {
const onValidateInput = jest . fn ( ( isValidEmail ) => {
2019-12-23 09:02:03 +00:00
expect ( isValidEmail . isValid ) . toEqual ( true ) ;
2019-10-15 06:07:02 +00:00
} ) ;
const emailSettings = new EmailSettings ( ) ;
emailSettings . allowLocalDomainName = true ;
2020-10-16 13:16:01 +00:00
const wrapper = mount (
< EmailInput
{ ... baseProps }
onValidateInput = { onValidateInput }
emailSettings = { emailSettings }
/ >
) ;
2019-10-15 06:07:02 +00:00
const event = { target : { value : "admin@mailserver1" } } ;
2020-10-16 13:16:01 +00:00
wrapper . simulate ( "change" , event ) ;
2019-10-15 06:07:02 +00:00
} ) ;
2020-10-16 13:16:01 +00:00
it ( "passed valid email (one-letter domain name): example@s.example" , ( ) => {
const onValidateInput = jest . fn ( ( isValidEmail ) => {
2019-12-23 09:02:03 +00:00
expect ( isValidEmail . isValid ) . toEqual ( true ) ;
2019-10-15 06:07:02 +00:00
} ) ;
2020-10-16 13:16:01 +00:00
const wrapper = mount (
< EmailInput { ... baseProps } onValidateInput = { onValidateInput } / >
) ;
2019-10-15 06:07:02 +00:00
const event = { target : { value : "example@s.example" } } ;
2020-10-16 13:16:01 +00:00
wrapper . simulate ( "change" , event ) ;
2019-10-15 06:07:02 +00:00
} ) ;
it ( 'passed valid email (space between the quotes): " "@example.org' , ( ) => {
2020-10-16 13:16:01 +00:00
const onValidateInput = jest . fn ( ( isValidEmail ) => {
2019-12-23 09:02:03 +00:00
expect ( isValidEmail . isValid ) . toEqual ( false ) ;
2019-10-15 11:21:59 +00:00
} ) ;
2020-10-16 13:16:01 +00:00
const wrapper = mount (
< EmailInput { ... baseProps } onValidateInput = { onValidateInput } / >
) ;
2019-10-15 11:21:59 +00:00
const event = { target : { value : '" "@example.org' } } ;
2020-10-16 13:16:01 +00:00
wrapper . simulate ( "change" , event ) ;
2019-10-15 11:21:59 +00:00
} ) ;
it ( 'passed valid email (space between the quotes): " "@example.org (settings: allowSpaces = true, allowStrictLocalPart = false)' , ( ) => {
2020-10-16 13:16:01 +00:00
const onValidateInput = jest . fn ( ( isValidEmail ) => {
2019-12-23 09:02:03 +00:00
expect ( isValidEmail . isValid ) . toEqual ( true ) ;
2019-10-15 06:07:02 +00:00
} ) ;
const emailSettings = new EmailSettings ( ) ;
emailSettings . allowSpaces = true ;
emailSettings . allowStrictLocalPart = false ;
2020-10-16 13:16:01 +00:00
const wrapper = mount (
< EmailInput
{ ... baseProps }
onValidateInput = { onValidateInput }
emailSettings = { emailSettings }
/ >
) ;
2019-10-15 06:07:02 +00:00
const event = { target : { value : '" "@example.org' } } ;
2020-10-16 13:16:01 +00:00
wrapper . simulate ( "change" , event ) ;
2019-10-15 06:07:02 +00:00
} ) ;
2019-10-15 11:21:59 +00:00
it ( 'passed valid email (quoted double dot): "john..doe"@example.org)' , ( ) => {
2020-10-16 13:16:01 +00:00
const onValidateInput = jest . fn ( ( isValidEmail ) => {
2019-12-23 09:02:03 +00:00
expect ( isValidEmail . isValid ) . toEqual ( false ) ;
2019-10-15 11:21:59 +00:00
} ) ;
2020-10-16 13:16:01 +00:00
const wrapper = mount (
< EmailInput { ... baseProps } onValidateInput = { onValidateInput } / >
) ;
2019-10-15 11:21:59 +00:00
const event = { target : { value : '"john..doe"@example.org' } } ;
2020-10-16 13:16:01 +00:00
wrapper . simulate ( "change" , event ) ;
2019-10-15 11:21:59 +00:00
} ) ;
it ( 'passed valid email (quoted double dot): "john..doe"@example.org (settings: allowSpaces = true, allowStrictLocalPart = false)' , ( ) => {
2020-10-16 13:16:01 +00:00
const onValidateInput = jest . fn ( ( isValidEmail ) => {
2019-12-23 09:02:03 +00:00
expect ( isValidEmail . isValid ) . toEqual ( true ) ;
2019-10-15 06:07:02 +00:00
} ) ;
const emailSettings = new EmailSettings ( ) ;
emailSettings . allowSpaces = true ;
emailSettings . allowStrictLocalPart = false ;
2020-10-16 13:16:01 +00:00
const wrapper = mount (
< EmailInput
{ ... baseProps }
onValidateInput = { onValidateInput }
emailSettings = { emailSettings }
/ >
) ;
2019-10-15 06:07:02 +00:00
const event = { target : { value : '"john..doe"@example.org' } } ;
2020-10-16 13:16:01 +00:00
wrapper . simulate ( "change" , event ) ;
2019-10-15 06:07:02 +00:00
} ) ;
2020-10-16 13:16:01 +00:00
it ( "passed valid email (bangified host route used for uucp mailers): mailhost!username@example.org" , ( ) => {
const onValidateInput = jest . fn ( ( isValidEmail ) => {
2019-12-23 09:02:03 +00:00
expect ( isValidEmail . isValid ) . toEqual ( false ) ;
2019-10-15 11:21:59 +00:00
} ) ;
2020-10-16 13:16:01 +00:00
const wrapper = mount (
< EmailInput { ... baseProps } onValidateInput = { onValidateInput } / >
) ;
2019-10-15 11:21:59 +00:00
const event = { target : { value : "mailhost!username@example.org" } } ;
2020-10-16 13:16:01 +00:00
wrapper . simulate ( "change" , event ) ;
2019-10-15 11:21:59 +00:00
} ) ;
2020-10-16 13:16:01 +00:00
it ( "passed valid email (bangified host route used for uucp mailers): mailhost!username@example.org (object settings: allowStrictLocalPart = false)" , ( ) => {
const onValidateInput = jest . fn ( ( isValidEmail ) => {
2019-12-23 09:02:03 +00:00
expect ( isValidEmail . isValid ) . toEqual ( true ) ;
2019-10-15 06:07:02 +00:00
} ) ;
2019-10-15 11:21:59 +00:00
const emailSettings = {
2020-10-16 13:16:01 +00:00
allowStrictLocalPart : false ,
} ;
const wrapper = mount (
< EmailInput
{ ... baseProps }
onValidateInput = { onValidateInput }
2022-03-16 15:51:02 +00:00
emailSettings = { EmailSettings . parse ( emailSettings ) }
2020-10-16 13:16:01 +00:00
/ >
) ;
2019-10-15 06:07:02 +00:00
const event = { target : { value : "mailhost!username@example.org" } } ;
2020-10-16 13:16:01 +00:00
wrapper . simulate ( "change" , event ) ;
2019-10-15 06:07:02 +00:00
} ) ;
2020-10-16 13:16:01 +00:00
it ( "passed valid email (% escaped mail route to user@example.com via example.org): user%example.com@example.org)" , ( ) => {
const onValidateInput = jest . fn ( ( isValidEmail ) => {
2019-12-23 09:02:03 +00:00
expect ( isValidEmail . isValid ) . toEqual ( true ) ;
2019-10-15 06:07:02 +00:00
} ) ;
const emailSettings = new EmailSettings ( ) ;
emailSettings . allowStrictLocalPart = false ;
2020-10-16 13:16:01 +00:00
const wrapper = mount (
< EmailInput
{ ... baseProps }
onValidateInput = { onValidateInput }
emailSettings = { emailSettings }
/ >
) ;
2019-10-15 06:07:02 +00:00
const event = { target : { value : "user%example.com@example.org" } } ;
2020-10-16 13:16:01 +00:00
wrapper . simulate ( "change" , event ) ;
2019-10-15 06:07:02 +00:00
} ) ;
2020-10-16 13:16:01 +00:00
it ( "passed valid email with punycode symbols in domain: example@джpу мла те с т.bр фa" , ( ) => {
const onValidateInput = jest . fn ( ( isValidEmail ) => {
2019-12-23 09:02:03 +00:00
expect ( isValidEmail . isValid ) . toEqual ( false ) ;
2019-10-15 11:21:59 +00:00
} ) ;
2020-10-16 13:16:01 +00:00
const wrapper = mount (
< EmailInput { ... baseProps } onValidateInput = { onValidateInput } / >
) ;
2019-10-15 11:21:59 +00:00
const event = { target : { value : "example@джpу мла те с т.bр фa" } } ;
2020-10-16 13:16:01 +00:00
wrapper . simulate ( "change" , event ) ;
2019-10-15 11:21:59 +00:00
} ) ;
2020-10-16 13:16:01 +00:00
it ( "passed valid email with punycode symbols in local part: mañana@example.com" , ( ) => {
const onValidateInput = jest . fn ( ( isValidEmail ) => {
2019-12-23 09:02:03 +00:00
expect ( isValidEmail . isValid ) . toEqual ( false ) ;
2019-10-15 11:21:59 +00:00
} ) ;
2020-10-16 13:16:01 +00:00
const wrapper = mount (
< EmailInput { ... baseProps } onValidateInput = { onValidateInput } / >
) ;
2019-10-15 11:21:59 +00:00
const event = { target : { value : "mañana@example.com" } } ;
2020-10-16 13:16:01 +00:00
wrapper . simulate ( "change" , event ) ;
2019-10-15 11:21:59 +00:00
} ) ;
2020-10-16 13:16:01 +00:00
it ( "passed valid email with punycode symbols in local part and domain: mañana@mañana.com" , ( ) => {
const onValidateInput = jest . fn ( ( isValidEmail ) => {
2019-12-23 09:02:03 +00:00
expect ( isValidEmail . isValid ) . toEqual ( false ) ;
2019-10-15 11:21:59 +00:00
} ) ;
2020-10-16 13:16:01 +00:00
const wrapper = mount (
< EmailInput { ... baseProps } onValidateInput = { onValidateInput } / >
) ;
2019-10-15 11:21:59 +00:00
const event = { target : { value : "mañana@mañana.com" } } ;
2020-10-16 13:16:01 +00:00
wrapper . simulate ( "change" , event ) ;
2019-10-15 11:21:59 +00:00
} ) ;
2020-10-16 13:16:01 +00:00
it ( "passed valid email with punycode symbols in local part and domain: mañana@mañana.com (settings: allowDomainPunycode=true)" , ( ) => {
const onValidateInput = jest . fn ( ( isValidEmail ) => {
2019-12-23 09:02:03 +00:00
expect ( isValidEmail . isValid ) . toEqual ( false ) ;
2019-10-15 11:21:59 +00:00
} ) ;
const emailSettings = new EmailSettings ( ) ;
emailSettings . allowDomainPunycode = true ;
2020-10-16 13:16:01 +00:00
const wrapper = mount (
< EmailInput
{ ... baseProps }
onValidateInput = { onValidateInput }
emailSettings = { emailSettings }
/ >
) ;
2019-10-15 11:21:59 +00:00
const event = { target : { value : "mañana@mañana.com" } } ;
2020-10-16 13:16:01 +00:00
wrapper . simulate ( "change" , event ) ;
2019-10-15 11:21:59 +00:00
} ) ;
2020-10-16 13:16:01 +00:00
it ( "passed valid email with punycode symbols in local part and domain: mañana@mañana.com (settings: allowLocalPartPunycode=true)" , ( ) => {
const onValidateInput = jest . fn ( ( isValidEmail ) => {
2019-12-23 09:02:03 +00:00
expect ( isValidEmail . isValid ) . toEqual ( false ) ;
2019-10-15 11:21:59 +00:00
} ) ;
const emailSettings = new EmailSettings ( ) ;
emailSettings . allowLocalPartPunycode = true ;
2020-10-16 13:16:01 +00:00
const wrapper = mount (
< EmailInput
{ ... baseProps }
onValidateInput = { onValidateInput }
emailSettings = { emailSettings }
/ >
) ;
2019-10-15 11:21:59 +00:00
const event = { target : { value : "mañana@mañana.com" } } ;
2020-10-16 13:16:01 +00:00
wrapper . simulate ( "change" , event ) ;
2019-10-15 11:21:59 +00:00
} ) ;
2020-10-16 13:16:01 +00:00
it ( "passed valid email with punycode symbols in local part and domain: mañana@mañana.com (settings: allowDomainPunycode=true, allowLocalPartPunycode=true)" , ( ) => {
const onValidateInput = jest . fn ( ( isValidEmail ) => {
2019-12-23 09:02:03 +00:00
expect ( isValidEmail . isValid ) . toEqual ( false ) ;
2019-10-15 11:21:59 +00:00
} ) ;
const emailSettings = new EmailSettings ( ) ;
emailSettings . allowLocalPartPunycode = true ;
emailSettings . allowDomainPunycode = true ;
2020-10-16 13:16:01 +00:00
const wrapper = mount (
< EmailInput
{ ... baseProps }
onValidateInput = { onValidateInput }
emailSettings = { emailSettings }
/ >
) ;
2019-10-15 11:21:59 +00:00
const event = { target : { value : "mañana@mañana.com" } } ;
2020-10-16 13:16:01 +00:00
wrapper . simulate ( "change" , event ) ;
2019-10-15 11:21:59 +00:00
} ) ;
2020-10-16 13:16:01 +00:00
it ( "passed valid email with punycode symbols in local part and domain: mañana@mañana.com (settings: allowDomainPunycode=true, allowLocalPartPunycode=true, allowStrictLocalPart=false)" , ( ) => {
const onValidateInput = jest . fn ( ( isValidEmail ) => {
2019-12-23 09:02:03 +00:00
expect ( isValidEmail . isValid ) . toEqual ( true ) ;
2019-10-15 11:21:59 +00:00
} ) ;
const emailSettings = new EmailSettings ( ) ;
emailSettings . allowLocalPartPunycode = true ;
emailSettings . allowDomainPunycode = true ;
emailSettings . allowStrictLocalPart = false ;
2020-10-16 13:16:01 +00:00
const wrapper = mount (
< EmailInput
{ ... baseProps }
onValidateInput = { onValidateInput }
emailSettings = { emailSettings }
/ >
) ;
2019-10-15 11:21:59 +00:00
const event = { target : { value : "mañana@mañana.com" } } ;
2020-10-16 13:16:01 +00:00
wrapper . simulate ( "change" , event ) ;
2019-10-15 11:21:59 +00:00
} ) ;
2020-10-16 13:16:01 +00:00
it ( "passed valid email with IP address in domain: user@[127.0.0.1]" , ( ) => {
const onValidateInput = jest . fn ( ( isValidEmail ) => {
2019-12-23 09:02:03 +00:00
expect ( isValidEmail . isValid ) . toEqual ( false ) ;
2019-10-15 11:21:59 +00:00
} ) ;
2020-10-16 13:16:01 +00:00
const wrapper = mount (
< EmailInput { ... baseProps } onValidateInput = { onValidateInput } / >
) ;
2019-10-15 11:21:59 +00:00
const event = { target : { value : "user@[127.0.0.1]" } } ;
2020-10-16 13:16:01 +00:00
wrapper . simulate ( "change" , event ) ;
2019-10-15 11:21:59 +00:00
} ) ;
2020-10-16 13:16:01 +00:00
it ( "passed valid email with IP address in domain: user@[127.0.0.1] (settings: allowDomainIp = true)" , ( ) => {
const onValidateInput = jest . fn ( ( isValidEmail ) => {
2019-12-23 09:02:03 +00:00
expect ( isValidEmail . isValid ) . toEqual ( true ) ;
2019-10-15 11:21:59 +00:00
} ) ;
const emailSettings = { allowDomainIp : true } ;
2020-10-16 13:16:01 +00:00
const wrapper = mount (
< EmailInput
{ ... baseProps }
onValidateInput = { onValidateInput }
2022-03-16 15:51:02 +00:00
emailSettings = { EmailSettings . parse ( emailSettings ) }
2020-10-16 13:16:01 +00:00
/ >
) ;
2019-10-15 11:21:59 +00:00
const event = { target : { value : "user@[127.0.0.1]" } } ;
2020-10-16 13:16:01 +00:00
wrapper . simulate ( "change" , event ) ;
2019-10-15 11:21:59 +00:00
} ) ;
it ( 'passed valid email with Name (RFC 5322): "Jack Bowman" <jack@fogcreek.com>' , ( ) => {
2020-10-16 13:16:01 +00:00
const onValidateInput = jest . fn ( ( isValidEmail ) => {
2019-12-23 09:02:03 +00:00
expect ( isValidEmail . isValid ) . toEqual ( false ) ;
2019-10-15 11:21:59 +00:00
} ) ;
2020-10-16 13:16:01 +00:00
const wrapper = mount (
< EmailInput { ... baseProps } onValidateInput = { onValidateInput } / >
) ;
2019-10-15 11:21:59 +00:00
const event = { target : { value : '"Jack Bowman" <jack@fogcreek.com>' } } ;
2020-10-16 13:16:01 +00:00
wrapper . simulate ( "change" , event ) ;
2019-10-15 11:21:59 +00:00
} ) ;
it ( 'passed valid email with Name (RFC 5322): "Jack Bowman" <jack@fogcreek.com> (instance of EmailSettings: allowName = true)' , ( ) => {
2020-10-16 13:16:01 +00:00
const onValidateInput = jest . fn ( ( isValidEmail ) => {
2019-12-23 09:02:03 +00:00
expect ( isValidEmail . isValid ) . toEqual ( true ) ;
2019-10-15 11:21:59 +00:00
} ) ;
const emailSettings = new EmailSettings ( ) ;
emailSettings . allowName = true ;
2020-10-16 13:16:01 +00:00
const wrapper = mount (
< EmailInput
{ ... baseProps }
onValidateInput = { onValidateInput }
emailSettings = { emailSettings }
/ >
) ;
2019-10-15 11:21:59 +00:00
const event = { target : { value : '"Jack Bowman" <jack@fogcreek.com>' } } ;
2020-10-16 13:16:01 +00:00
wrapper . simulate ( "change" , event ) ;
2019-10-15 11:21:59 +00:00
} ) ;
2020-10-16 13:16:01 +00:00
it ( "passed valid email with Name (RFC 5322): Bob <bob@example.com>" , ( ) => {
const onValidateInput = jest . fn ( ( isValidEmail ) => {
2019-12-23 09:02:03 +00:00
expect ( isValidEmail . isValid ) . toEqual ( false ) ;
2019-10-15 11:21:59 +00:00
} ) ;
2020-10-16 13:16:01 +00:00
const wrapper = mount (
< EmailInput { ... baseProps } onValidateInput = { onValidateInput } / >
) ;
2019-10-15 11:21:59 +00:00
2020-10-16 13:16:01 +00:00
const event = { target : { value : "Bob <bob@example.com>" } } ;
2019-10-15 11:21:59 +00:00
2020-10-16 13:16:01 +00:00
wrapper . simulate ( "change" , event ) ;
2019-10-15 11:21:59 +00:00
} ) ;
2020-10-16 13:16:01 +00:00
it ( "passed valid email with Name (RFC 5322): Bob <bob@example.com> (instance of EmailSettings: allowName = true)" , ( ) => {
const onValidateInput = jest . fn ( ( isValidEmail ) => {
2019-12-23 09:02:03 +00:00
expect ( isValidEmail . isValid ) . toEqual ( true ) ;
2019-10-15 11:21:59 +00:00
} ) ;
const emailSettings = new EmailSettings ( ) ;
emailSettings . allowName = true ;
2020-10-16 13:16:01 +00:00
const wrapper = mount (
< EmailInput
{ ... baseProps }
onValidateInput = { onValidateInput }
emailSettings = { emailSettings }
/ >
) ;
2019-10-15 11:21:59 +00:00
2020-10-16 13:16:01 +00:00
const event = { target : { value : "Bob <bob@example.com>" } } ;
2019-10-15 11:21:59 +00:00
2020-10-16 13:16:01 +00:00
wrapper . simulate ( "change" , event ) ;
2019-10-15 11:21:59 +00:00
} ) ;
2020-10-16 13:16:01 +00:00
it ( "passed invalid email (no @ character): Abc.example.com" , ( ) => {
const onValidateInput = jest . fn ( ( isValidEmail ) => {
2019-12-23 09:02:03 +00:00
expect ( isValidEmail . isValid ) . toEqual ( false ) ;
2019-10-15 06:07:02 +00:00
} ) ;
2020-10-16 13:16:01 +00:00
const wrapper = mount (
< EmailInput { ... baseProps } onValidateInput = { onValidateInput } / >
) ;
2019-10-15 06:07:02 +00:00
const event = { target : { value : "Abc.example.com" } } ;
2020-10-16 13:16:01 +00:00
wrapper . simulate ( "change" , event ) ;
2019-10-15 06:07:02 +00:00
} ) ;
2020-10-16 13:16:01 +00:00
it ( "passed invalid email (only one @ is allowed outside quotation marks): A@b@c@example.com" , ( ) => {
const onValidateInput = jest . fn ( ( isValidEmail ) => {
2019-12-23 09:02:03 +00:00
expect ( isValidEmail . isValid ) . toEqual ( false ) ;
2019-10-15 06:07:02 +00:00
} ) ;
2020-10-16 13:16:01 +00:00
const wrapper = mount (
< EmailInput { ... baseProps } onValidateInput = { onValidateInput } / >
) ;
2019-10-15 06:07:02 +00:00
const event = { target : { value : "A@b@c@example.com" } } ;
2020-10-16 13:16:01 +00:00
wrapper . simulate ( "change" , event ) ;
2019-10-15 06:07:02 +00:00
} ) ;
2020-10-16 13:16:01 +00:00
it ( 'passed invalid email (none of the special characters in this local-part are allowed outside quotation marks): a"b(c)d,e:f;g<h>i[jk]l@example.com' , ( ) => {
const onValidateInput = jest . fn ( ( isValidEmail ) => {
2019-12-23 09:02:03 +00:00
expect ( isValidEmail . isValid ) . toEqual ( false ) ;
2019-10-15 06:07:02 +00:00
} ) ;
2020-10-16 13:16:01 +00:00
const wrapper = mount (
< EmailInput { ... baseProps } onValidateInput = { onValidateInput } / >
) ;
2019-10-15 06:07:02 +00:00
2020-10-16 13:16:01 +00:00
const event = { target : { value : 'a"b(c)d,e:f;g<h>i[jk]l@example.com' } } ;
2019-10-15 06:07:02 +00:00
2020-10-16 13:16:01 +00:00
wrapper . simulate ( "change" , event ) ;
2019-10-15 06:07:02 +00:00
} ) ;
2020-10-16 13:16:01 +00:00
it ( 'passed invalid email (none of the special characters in this local-part are allowed outside quotation marks): a"b(c)d,e:f;g<h>i[jk]l@example.com' , ( ) => {
const onValidateInput = jest . fn ( ( isValidEmail ) => {
2019-12-23 09:02:03 +00:00
expect ( isValidEmail . isValid ) . toEqual ( false ) ;
2019-10-15 06:07:02 +00:00
} ) ;
2020-10-16 13:16:01 +00:00
const wrapper = mount (
< EmailInput { ... baseProps } onValidateInput = { onValidateInput } / >
) ;
2019-10-15 06:07:02 +00:00
2020-10-16 13:16:01 +00:00
const event = { target : { value : 'a"b(c)d,e:f;g<h>i[jk]l@example.com' } } ;
2019-10-15 06:07:02 +00:00
2020-10-16 13:16:01 +00:00
wrapper . simulate ( "change" , event ) ;
2019-10-15 06:07:02 +00:00
} ) ;
it ( 'passed invalid email (quoted strings must be dot separated or the only element making up the local-part): just"not"right@example.com' , ( ) => {
2020-10-16 13:16:01 +00:00
const onValidateInput = jest . fn ( ( isValidEmail ) => {
2019-12-23 09:02:03 +00:00
expect ( isValidEmail . isValid ) . toEqual ( false ) ;
2019-10-15 06:07:02 +00:00
} ) ;
const emailSettings = new EmailSettings ( ) ;
emailSettings . allowSpaces = true ;
emailSettings . allowStrictLocalPart = false ;
2020-10-16 13:16:01 +00:00
const wrapper = mount (
< EmailInput
{ ... baseProps }
onValidateInput = { onValidateInput }
emailSettings = { emailSettings }
/ >
) ;
2019-10-15 06:07:02 +00:00
const event = { target : { value : 'just"not"right@example.com' } } ;
2020-10-16 13:16:01 +00:00
wrapper . simulate ( "change" , event ) ;
2019-10-15 06:07:02 +00:00
} ) ;
2020-10-16 13:16:01 +00:00
it ( 'passed invalid email (spaces, quotes, and backslashes may only exist when within quoted strings and preceded by a backslash): this is"notallowed@example.com' , ( ) => {
const onValidateInput = jest . fn ( ( isValidEmail ) => {
2019-12-23 09:02:03 +00:00
expect ( isValidEmail . isValid ) . toEqual ( false ) ;
2019-10-15 06:07:02 +00:00
} ) ;
const emailSettings = new EmailSettings ( ) ;
emailSettings . allowSpaces = true ;
emailSettings . allowStrictLocalPart = false ;
2020-10-16 13:16:01 +00:00
const wrapper = mount (
< EmailInput
{ ... baseProps }
onValidateInput = { onValidateInput }
emailSettings = { emailSettings }
/ >
) ;
2019-10-15 06:07:02 +00:00
2020-10-16 13:16:01 +00:00
const event = { target : { value : 'this is"notallowed@example.com' } } ;
2019-10-15 06:07:02 +00:00
2020-10-16 13:16:01 +00:00
wrapper . simulate ( "change" , event ) ;
2019-10-15 06:07:02 +00:00
} ) ;
2020-10-16 13:16:01 +00:00
it ( 'passed invalid email (even if escaped (preceded by a backslash), spaces, quotes, and backslashes must still be contained by quotes): this still"not\\allowed@example.com' , ( ) => {
const onValidateInput = jest . fn ( ( isValidEmail ) => {
2019-12-23 09:02:03 +00:00
expect ( isValidEmail . isValid ) . toEqual ( false ) ;
2019-10-15 06:07:02 +00:00
} ) ;
const emailSettings = new EmailSettings ( ) ;
emailSettings . allowSpaces = true ;
emailSettings . allowStrictLocalPart = false ;
2020-10-16 13:16:01 +00:00
const wrapper = mount (
< EmailInput
{ ... baseProps }
onValidateInput = { onValidateInput }
emailSettings = { emailSettings }
/ >
) ;
2019-10-15 06:07:02 +00:00
2020-10-16 13:16:01 +00:00
const event = { target : { value : 'this still"not\\allowed@example.com' } } ;
2019-10-15 06:07:02 +00:00
2020-10-16 13:16:01 +00:00
wrapper . simulate ( "change" , event ) ;
2019-10-15 06:07:02 +00:00
} ) ;
2020-10-16 13:16:01 +00:00
it ( "passed invalid email (local part is longer than 64 characters): 1234567890123456789012345678901234567890123456789012345678901234+x@example.com" , ( ) => {
const onValidateInput = jest . fn ( ( isValidEmail ) => {
2019-12-23 09:02:03 +00:00
expect ( isValidEmail . isValid ) . toEqual ( false ) ;
2019-10-15 06:07:02 +00:00
} ) ;
2020-10-16 13:16:01 +00:00
const wrapper = mount (
< EmailInput { ... baseProps } onValidateInput = { onValidateInput } / >
) ;
2019-10-15 06:07:02 +00:00
2020-10-16 13:16:01 +00:00
const event = {
target : {
value :
"1234567890123456789012345678901234567890123456789012345678901234+x@example.com" ,
} ,
} ;
2019-10-15 06:07:02 +00:00
2020-10-16 13:16:01 +00:00
wrapper . simulate ( "change" , event ) ;
2019-10-15 06:07:02 +00:00
} ) ;
2019-11-27 13:59:27 +00:00
2020-10-16 13:16:01 +00:00
it ( "accepts id" , ( ) => {
const wrapper = mount ( < EmailInput { ... baseProps } id = "testId" / > ) ;
2019-11-27 13:59:27 +00:00
2020-10-16 13:16:01 +00:00
expect ( wrapper . prop ( "id" ) ) . toEqual ( "testId" ) ;
2019-11-27 13:59:27 +00:00
} ) ;
2020-10-16 13:16:01 +00:00
it ( "accepts className" , ( ) => {
const wrapper = mount ( < EmailInput { ... baseProps } className = "test" / > ) ;
2019-11-27 13:59:27 +00:00
2020-10-16 13:16:01 +00:00
expect ( wrapper . prop ( "className" ) ) . toEqual ( "test" ) ;
2019-11-27 13:59:27 +00:00
} ) ;
2020-10-16 13:16:01 +00:00
it ( "accepts style" , ( ) => {
2019-11-27 13:59:27 +00:00
const wrapper = mount (
2020-10-16 13:16:01 +00:00
< EmailInput { ... baseProps } style = { { color : "red" } } / >
2019-11-27 13:59:27 +00:00
) ;
2020-10-16 13:16:01 +00:00
expect ( wrapper . getDOMNode ( ) . style ) . toHaveProperty ( "color" , "red" ) ;
2019-11-27 13:59:27 +00:00
} ) ;
2019-10-11 17:59:59 +00:00
} ) ;