Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
a57f3d25
Commit
a57f3d25
authored
May 15, 2015
by
Sean Hammond
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove duplication when stugging changeEmailForm
parent
55e8c35d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
72 deletions
+42
-72
account-controller-test.coffee
h/static/scripts/account/test/account-controller-test.coffee
+42
-72
No files found.
h/static/scripts/account/test/account-controller-test.coffee
View file @
a57f3d25
...
...
@@ -273,6 +273,25 @@ describe "h:AccountController", ->
edit_profile
:
edit_profile
or
->
{
$promise
:
Promise
.
resolve
({})}
}
# Return a minimal stub version of the object that AccountController's
# changeEmail() method receives when the user submits the changeEmailForm.
getStubChangeEmailForm
=
({
email
,
emailAgain
,
password
})
->
return
{
$name
:
"changeEmailForm"
email
:
$modelValue
:
email
$setValidity
:
->
emailAgain
:
$modelValue
:
emailAgain
$setValidity
:
->
pwd
:
$modelValue
:
password
$setValidity
:
->
$valid
:
true
$setPristine
:
->
$setValidity
:
->
}
###
Return an AccountController instance and stub services.
...
...
@@ -340,7 +359,7 @@ describe "h:AccountController", ->
it
"calls sesson.edit_profile() with the right data on form submission"
,
->
new_email_addr
ess
=
"new_email_address@test.com"
new_email_addr
=
"new_email_address@test.com"
# Stub the session.edit_profile() function.
edit_profile
=
sinon
.
stub
()
...
...
@@ -351,21 +370,15 @@ describe "h:AccountController", ->
# Simulate a logged-in user with username "joeuser"
$filter
:
->
->
"joeuser"
)
form
=
{
$name
:
"changeEmailForm"
email
:
$modelValue
:
new_email_address
emailAgain
:
$modelValue
:
new_email_address
pwd
:
$modelValue
:
"pass"
$valid
:
true
$setPristine
:
->
}
form
=
getStubChangeEmailForm
(
email
:
new_email_addr
,
emailAgain
:
new_email_addr
,
password
:
"pass"
)
$scope
.
changeEmail
(
form
).
then
(
->
assert
edit_profile
.
calledWithExactly
({
username
:
"joeuser"
pwd
:
"pass"
email
:
new_email_addr
ess
emailAgain
:
new_email_addr
ess
email
:
new_email_addr
emailAgain
:
new_email_addr
})
)
...
...
@@ -382,14 +395,8 @@ describe "h:AccountController", ->
)
)
form
=
{
$name
:
"changeEmailForm"
email
:
$modelValue
:
new_email_addr
emailAgain
:
$modelValue
:
new_email_addr
pwd
:
$modelValue
:
"pass"
$valid
:
true
$setPristine
:
->
}
form
=
getStubChangeEmailForm
(
email
:
new_email_addr
,
emailAgain
:
new_email_addr
,
password
:
"pass"
)
$scope
.
changeEmail
(
form
).
then
(
->
assert
$scope
.
email
==
new_email_addr
...
...
@@ -411,56 +418,36 @@ describe "h:AccountController", ->
)
)
form
=
{
$name
:
"changeEmailForm"
email
:
$modelValue
:
"my_new_email_address@yahoo.com"
emailAgain
:
$modelValue
:
"a_different_email_address@bluebottle.com"
$setValidity
:
->
pwd
:
$modelValue
:
"pass"
$valid
:
true
$setPristine
:
->
$setValidity
:
->
}
form
=
getStubChangeEmailForm
(
email
:
"my_new_email_address@yahoo.com"
emailAgain
:
"a_different_email_address@bluebottle.com"
pwd
:
"pass"
)
$scope
.
changeEmail
(
form
).
then
(
->
assert
form
.
emailAgain
.
responseErrorMessage
==
"The emails must match."
)
it
"broadcasts 'formState' 'changeEmailForm' 'loading' on submit"
,
->
new_email_address
=
"new_email_address@test.com"
{
$scope
}
=
controller
({})
$scope
.
$broadcast
=
sinon
.
stub
()
form
=
{
$name
:
"changeEmailForm"
email
:
$modelValue
:
new_email_address
emailAgain
:
$modelValue
:
new_email_address
pwd
:
$modelValue
:
"pass"
$valid
:
true
$setPristine
:
->
}
form
=
getStubChangeEmailForm
(
email
:
"new_email_address@test.com"
,
emailAgain
:
"new_email_address@test.com"
,
password
:
"pass"
)
$scope
.
changeEmail
(
form
)
assert
$scope
.
$broadcast
.
calledWithExactly
(
"formState"
,
"changeEmailForm"
,
"loading"
)
it
"broadcasts 'formState' 'changeEmailForm' 'success' on success"
,
->
new_email_address
=
"new_email_address@test.com"
{
$scope
}
=
controller
({})
$scope
.
$broadcast
=
sinon
.
stub
()
form
=
{
$name
:
"changeEmailForm"
email
:
$modelValue
:
new_email_address
emailAgain
:
$modelValue
:
new_email_address
pwd
:
$modelValue
:
"pass"
$valid
:
true
$setPristine
:
->
}
form
=
getStubChangeEmailForm
(
email
:
"new_email_address@test.com"
,
emailAgain
:
"new_email_address@test.com"
,
password
:
"pass"
)
$scope
.
changeEmail
(
form
).
then
(
->
assert
$scope
.
$broadcast
.
calledWithExactly
(
...
...
@@ -468,8 +455,6 @@ describe "h:AccountController", ->
)
it
"broadcasts 'formState' 'changeEmailForm' '' on error"
,
->
new_email_address
=
"new_email_address@test.com"
{
$scope
}
=
controller
(
flash
:
{
error
:
->
}
session
:
getStubSession
(
...
...
@@ -479,14 +464,9 @@ describe "h:AccountController", ->
$scope
.
$broadcast
=
sinon
.
stub
()
form
=
{
$name
:
"changeEmailForm"
email
:
$modelValue
:
new_email_address
emailAgain
:
$modelValue
:
new_email_address
pwd
:
$modelValue
:
"pass"
$valid
:
true
$setPristine
:
->
}
form
=
getStubChangeEmailForm
(
email
:
"new_email_address@test.com"
,
emailAgain
:
"new_email_address@test.com"
,
password
:
"pass"
)
$scope
.
changeEmail
(
form
).
then
(
->
assert
$scope
.
$broadcast
.
calledWithExactly
(
...
...
@@ -494,8 +474,6 @@ describe "h:AccountController", ->
)
it
"shows an error if the password is wrong"
,
->
new_email_address
=
"new_email_address@test.com"
# Mock of the server response you get when you enter the wrong password.
server_response
=
{
data
:
...
...
@@ -512,17 +490,9 @@ describe "h:AccountController", ->
)
)
form
=
{
$name
:
"changeEmailForm"
email
:
$modelValue
:
new_email_address
emailAgain
:
$modelValue
:
new_email_address
pwd
:
$modelValue
:
"pass"
$setValidity
:
->
$valid
:
true
$setPristine
:
->
$setValidity
:
->
}
form
=
getStubChangeEmailForm
(
email
:
"new_email_address@test.com"
,
emailAgain
:
"new_email_address@test.com"
,
password
:
"pass"
)
$scope
.
changeEmail
(
form
).
then
(
->
assert
form
.
pwd
.
responseErrorMessage
==
"Invalid password"
...
...
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