Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
scratch-www
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
scratch-www
Commits
cb1332fb
Commit
cb1332fb
authored
Nov 04, 2019
by
Ben Wheeler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
revised and expanded email step tests
parent
53f6b133
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
100 additions
and
2 deletions
+100
-2
test/unit/components/email-step.test.jsx
test/unit/components/email-step.test.jsx
+100
-2
No files found.
test/unit/components/email-step.test.jsx
View file @
cb1332fb
...
...
@@ -4,9 +4,24 @@ const JoinFlowStep = require('../../../src/components/join-flow/join-flow-step.j
const
FormikInput
=
require
(
'
../../../src/components/formik-forms/formik-input.jsx
'
);
const
FormikCheckbox
=
require
(
'
../../../src/components/formik-forms/formik-checkbox.jsx
'
);
const
mockedValidateEmailRemotely
=
jest
.
fn
(()
=>
(
const
requestSuccessResponse
=
{
requestSucceeded
:
true
,
valid
:
false
,
errMsgId
:
'
registration.validationEmailInvalid
'
};
const
requestFailureResponse
=
{
requestSucceeded
:
false
,
valid
:
false
,
errMsgId
:
'
general.error
'
};
// mockedValidateEmailRemotely will return a promise resolving with remoteRequestResponse.
// Using remoteRequestResponse, rather than using requestSuccessResponse directly,
// lets us change where remoteRequestResponse points later, without actually changing
// mockedValidateEmailRemotely.
let
remoteRequestResponse
=
requestSuccessResponse
;
let
mockedValidateEmailRemotely
=
jest
.
fn
(()
=>
(
/* eslint-disable no-undef */
Promise
.
resolve
(
{
valid
:
false
,
errMsgId
:
'
registration.validationEmailInvalid
'
}
)
Promise
.
resolve
(
remoteRequestResponse
)
/* eslint-enable no-undef */
));
...
...
@@ -193,6 +208,13 @@ describe('EmailStep test', () => {
const
val
=
formikWrapper
.
instance
().
validateEmail
();
expect
(
val
).
toBe
(
'
general.required
'
);
});
});
describe
(
'
validateEmailRemotelyWithCache test with successful requests
'
,
()
=>
{
afterEach
(()
=>
{
jest
.
clearAllMocks
();
});
test
(
'
validateEmailRemotelyWithCache calls validate.validateEmailRemotely
'
,
done
=>
{
const
wrapper
=
shallowWithIntl
(
...
...
@@ -256,3 +278,79 @@ describe('EmailStep test', () => {
});
});
});
describe
(
'
validateEmailRemotelyWithCache test with failing requests
'
,
()
=>
{
beforeEach
(()
=>
{
// needs to be wrapped inside beforeEach, because if not, it gets run as this
// test file is loaded, and goes into effect before any of the earlier tests run!
remoteRequestResponse
=
requestFailureResponse
;
});
afterEach
(()
=>
{
jest
.
clearAllMocks
();
});
test
(
'
validateEmailRemotelyWithCache calls validate.validateEmailRemotely
'
,
done
=>
{
const
wrapper
=
shallowWithIntl
(
<
EmailStep
/>);
const
instance
=
wrapper
.
dive
().
instance
();
instance
.
validateEmailRemotelyWithCache
(
'
some-email@some-domain.com
'
)
.
then
(
response
=>
{
expect
(
mockedValidateEmailRemotely
).
toHaveBeenCalled
();
expect
(
response
.
valid
).
toBe
(
false
);
expect
(
response
.
errMsgId
).
toBe
(
'
general.error
'
);
done
();
});
});
test
(
'
validateEmailRemotelyWithCache, called twice with different data, makes two remote requests
'
,
done
=>
{
const
wrapper
=
shallowWithIntl
(
<
EmailStep
/>
);
const
instance
=
wrapper
.
dive
().
instance
();
instance
.
validateEmailRemotelyWithCache
(
'
some-email@some-domain.com
'
)
.
then
(
response
=>
{
expect
(
mockedValidateEmailRemotely
).
toHaveBeenCalledTimes
(
1
);
expect
(
response
.
valid
).
toBe
(
false
);
expect
(
response
.
errMsgId
).
toBe
(
'
general.error
'
);
})
.
then
(()
=>
{
// make the same request a second time
instance
.
validateEmailRemotelyWithCache
(
'
different-email@some-domain.org
'
)
.
then
(
response
=>
{
expect
(
mockedValidateEmailRemotely
).
toHaveBeenCalledTimes
(
2
);
expect
(
response
.
valid
).
toBe
(
false
);
expect
(
response
.
errMsgId
).
toBe
(
'
general.error
'
);
done
();
});
});
});
test
(
'
validateEmailRemotelyWithCache, called 2x w/same data, makes 2 requests, since 1st not stored
'
,
done
=>
{
const
wrapper
=
shallowWithIntl
(
<
EmailStep
/>
);
const
instance
=
wrapper
.
dive
().
instance
();
instance
.
validateEmailRemotelyWithCache
(
'
some-email@some-domain.com
'
)
.
then
(
response
=>
{
expect
(
mockedValidateEmailRemotely
).
toHaveBeenCalledTimes
(
1
);
expect
(
response
.
valid
).
toBe
(
false
);
expect
(
response
.
errMsgId
).
toBe
(
'
general.error
'
);
})
.
then
(()
=>
{
// make the same request a second time
instance
.
validateEmailRemotelyWithCache
(
'
some-email@some-domain.com
'
)
.
then
(
response
=>
{
expect
(
mockedValidateEmailRemotely
).
toHaveBeenCalledTimes
(
2
);
expect
(
response
.
valid
).
toBe
(
false
);
expect
(
response
.
errMsgId
).
toBe
(
'
general.error
'
);
done
();
});
});
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment