Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
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
edx
edx-platform
Commits
9f91935f
Commit
9f91935f
authored
Dec 13, 2013
by
cahrens
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Do not restore sinon global objects in afterEach.
STUD-1040
parent
6952aec8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
108 additions
and
86 deletions
+108
-86
cms/static/coffee/spec/main.coffee
+3
-2
cms/static/coffee/spec/main_spec.coffee
+12
-12
cms/static/coffee/spec/models/section_spec.coffee
+7
-9
cms/static/coffee/spec/views/assets_spec.coffee
+22
-21
cms/static/coffee/spec/views/course_info_spec.coffee
+0
-0
cms/static/coffee/spec/views/overview_spec.coffee
+13
-17
cms/static/coffee/spec/views/section_spec.coffee
+4
-6
cms/static/coffee/spec/views/textbook_spec.coffee
+6
-9
cms/static/coffee/spec/views/upload_spec.coffee
+11
-9
cms/static/js/spec/create_sinon.js
+29
-0
rakelib/js_test.rake
+1
-1
No files found.
cms/static/coffee/spec/main.coffee
View file @
9f91935f
...
...
@@ -41,9 +41,10 @@ requirejs.config({
"mathjax"
:
"//edx-static.s3.amazonaws.com/mathjax-MathJax-727332c/MathJax.js?config=TeX-MML-AM_HTMLorMML-full&delayStartupUntil=configured"
,
"youtube"
:
"//www.youtube.com/player_api?noext"
,
"tender"
:
"//edxedge.tenderapp.com/tender_widget"
"tender"
:
"//edxedge.tenderapp.com/tender_widget"
,
"coffee/src/ajax_prefix"
:
"xmodule_js/common_static/coffee/src/ajax_prefix"
"coffee/src/ajax_prefix"
:
"xmodule_js/common_static/coffee/src/ajax_prefix"
,
"js/spec/test_utils"
:
"js/spec/test_utils"
,
}
shim
:
{
"gettext"
:
{
...
...
cms/static/coffee/spec/main_spec.coffee
View file @
9f91935f
require
[
"jquery"
,
"backbone"
,
"coffee/src/main"
,
"sinon"
,
"jasmine-stealth"
,
"jquery.cookie"
],
(
$
,
Backbone
,
main
,
sinon
)
->
require
[
"jquery"
,
"backbone"
,
"coffee/src/main"
,
"
js/spec/create_
sinon"
,
"jasmine-stealth"
,
"jquery.cookie"
],
(
$
,
Backbone
,
main
,
create_
sinon
)
->
describe
"CMS"
,
->
it
"should initialize URL"
,
->
expect
(
window
.
CMS
.
URL
).
toBeDefined
()
...
...
@@ -26,30 +26,30 @@ require ["jquery", "backbone", "coffee/src/main", "sinon", "jasmine-stealth", "j
beforeEach
->
setFixtures
(
$
(
"<script>"
,
{
id
:
"system-feedback-tpl"
,
type
:
"text/template"
}).
text
(
tpl
))
appendSetFixtures
(
sandbox
({
id
:
"page-notification"
}))
@
requests
=
requests
=
[]
@
xhr
=
sinon
.
useFakeXMLHttpRequest
()
@
xhr
.
onCreate
=
(
xhr
)
->
requests
.
push
(
xhr
)
afterEach
->
@
xhr
.
restore
()
it
"successful AJAX request does not pop an error notification"
,
->
server
=
create_sinon
[
'server'
](
200
,
this
)
expect
(
$
(
"#page-notification"
)).
toBeEmpty
()
$
.
ajax
(
"/test"
)
expect
(
$
(
"#page-notification"
)).
toBeEmpty
()
@
requests
[
0
].
respond
(
200
)
server
.
respond
(
)
expect
(
$
(
"#page-notification"
)).
toBeEmpty
()
it
"AJAX request with error should pop an error notification"
,
->
server
=
create_sinon
[
'server'
](
500
,
this
)
$
.
ajax
(
"/test"
)
@
requests
[
0
].
respond
(
500
)
server
.
respond
(
)
expect
(
$
(
"#page-notification"
)).
not
.
toBeEmpty
()
expect
(
$
(
"#page-notification"
)).
toContain
(
'div.wrapper-notification-error'
)
it
"can override AJAX request with error so it does not pop an error notification"
,
->
server
=
create_sinon
[
'server'
](
500
,
this
)
$
.
ajax
url
:
"/test"
notifyOnError
:
false
@
requests
[
0
].
respond
(
500
)
expect
(
$
(
"#page-notification"
)).
toBeEmpty
()
server
.
respond
()
expect
(
$
(
"#page-notification"
)).
toBeEmpty
()
cms/static/coffee/spec/models/section_spec.coffee
View file @
9f91935f
define
[
"js/models/section"
,
"
sinon"
,
"js/utils/module"
],
(
Section
,
sinon
,
ModuleUtils
)
->
define
[
"js/models/section"
,
"
js/spec/create_sinon"
,
"js/utils/module"
],
(
Section
,
create_
sinon
,
ModuleUtils
)
->
describe
"Section"
,
->
describe
"basic"
,
->
beforeEach
->
...
...
@@ -32,21 +32,19 @@ define ["js/models/section", "sinon", "js/utils/module"], (Section, sinon, Modul
id
:
42
name
:
"Life, the Universe, and Everything"
})
@
requests
=
requests
=
[]
@
xhr
=
sinon
.
useFakeXMLHttpRequest
()
@
xhr
.
onCreate
=
(
xhr
)
->
requests
.
push
(
xhr
)
afterEach
->
@
xhr
.
restore
()
it
"show/hide a notification when it saves to the server"
,
->
server
=
create_sinon
[
'server'
](
200
,
this
)
@
model
.
save
()
expect
(
Section
.
prototype
.
showNotification
).
toHaveBeenCalled
()
@
requests
[
0
].
respond
(
200
)
server
.
respond
(
)
expect
(
Section
.
prototype
.
hideNotification
).
toHaveBeenCalled
()
it
"don't hide notification when saving fails"
,
->
# this is handled by the global AJAX error handler
server
=
create_sinon
[
'server'
](
500
,
this
)
@
model
.
save
()
@
requests
[
0
].
respond
(
500
)
server
.
respond
(
)
expect
(
Section
.
prototype
.
hideNotification
).
not
.
toHaveBeenCalled
()
cms/static/coffee/spec/views/assets_spec.coffee
View file @
9f91935f
define
[
"jasmine"
,
"sinon"
,
"squire"
],
(
jasmine
,
sinon
,
Squire
)
->
define
[
"jasmine"
,
"
js/spec/create_
sinon"
,
"squire"
],
(
jasmine
,
create_
sinon
,
Squire
)
->
feedbackTpl
=
readFixtures
(
'system-feedback.underscore'
)
assetTpl
=
readFixtures
(
'asset.underscore'
)
...
...
@@ -68,26 +68,20 @@ define ["jasmine", "sinon", "squire"],
expect
(
@
collection
).
toContain
(
@
model
)
describe
"AJAX"
,
->
beforeEach
->
@
requests
=
requests
=
[]
@
xhr
=
sinon
.
useFakeXMLHttpRequest
()
@
xhr
.
onCreate
=
(
xhr
)
->
requests
.
push
(
xhr
)
afterEach
->
@
xhr
.
restore
()
it
"should destroy itself on confirmation"
,
->
requests
=
create_sinon
[
"requests"
](
this
)
@
view
.
render
().
$
(
".remove-asset-button"
).
click
()
ctorOptions
=
@
promptSpies
.
constructor
.
mostRecentCall
.
args
[
0
]
# run the primary function to indicate confirmation
ctorOptions
.
actions
.
primary
.
click
(
@
promptSpies
)
# AJAX request has been sent, but not yet returned
expect
(
@
model
.
destroy
).
toHaveBeenCalled
()
expect
(
@
requests
.
length
).
toEqual
(
1
)
expect
(
requests
.
length
).
toEqual
(
1
)
expect
(
@
confirmationSpies
.
constructor
).
not
.
toHaveBeenCalled
()
expect
(
@
collection
.
contains
(
@
model
)).
toBeTruthy
()
# return a success response
@
requests
[
0
].
respond
(
200
)
requests
[
0
].
respond
(
200
)
expect
(
@
confirmationSpies
.
constructor
).
toHaveBeenCalled
()
expect
(
@
confirmationSpies
.
show
).
toHaveBeenCalled
()
savingOptions
=
@
confirmationSpies
.
constructor
.
mostRecentCall
.
args
[
0
]
...
...
@@ -95,6 +89,8 @@ define ["jasmine", "sinon", "squire"],
expect
(
@
collection
.
contains
(
@
model
)).
toBeFalsy
()
it
"should not destroy itself if server errors"
,
->
requests
=
create_sinon
[
"requests"
](
this
)
@
view
.
render
().
$
(
".remove-asset-button"
).
click
()
ctorOptions
=
@
promptSpies
.
constructor
.
mostRecentCall
.
args
[
0
]
# run the primary function to indicate confirmation
...
...
@@ -102,29 +98,33 @@ define ["jasmine", "sinon", "squire"],
# AJAX request has been sent, but not yet returned
expect
(
@
model
.
destroy
).
toHaveBeenCalled
()
# return an error response
@
requests
[
0
].
respond
(
404
)
requests
[
0
].
respond
(
404
)
expect
(
@
confirmationSpies
.
constructor
).
not
.
toHaveBeenCalled
()
expect
(
@
collection
.
contains
(
@
model
)).
toBeTruthy
()
it
"should lock the asset on confirmation"
,
->
requests
=
create_sinon
[
"requests"
](
this
)
@
view
.
render
().
$
(
".lock-checkbox"
).
click
()
# AJAX request has been sent, but not yet returned
expect
(
@
model
.
save
).
toHaveBeenCalled
()
expect
(
@
requests
.
length
).
toEqual
(
1
)
expect
(
requests
.
length
).
toEqual
(
1
)
expect
(
@
savingSpies
.
constructor
).
toHaveBeenCalled
()
expect
(
@
savingSpies
.
show
).
toHaveBeenCalled
()
savingOptions
=
@
savingSpies
.
constructor
.
mostRecentCall
.
args
[
0
]
expect
(
savingOptions
.
title
).
toMatch
(
"Saving..."
)
expect
(
@
model
.
get
(
"locked"
)).
toBeFalsy
()
# return a success response
@
requests
[
0
].
respond
(
200
)
requests
[
0
].
respond
(
200
)
expect
(
@
savingSpies
.
hide
).
toHaveBeenCalled
()
expect
(
@
model
.
get
(
"locked"
)).
toBeTruthy
()
it
"should not lock the asset if server errors"
,
->
requests
=
create_sinon
[
"requests"
](
this
)
@
view
.
render
().
$
(
".lock-checkbox"
).
click
()
# return an error response
@
requests
[
0
].
respond
(
404
)
requests
[
0
].
respond
(
404
)
# Don't call hide because that closes the notification showing the server error.
expect
(
@
savingSpies
.
hide
).
not
.
toHaveBeenCalled
()
expect
(
@
model
.
get
(
"locked"
)).
toBeFalsy
()
...
...
@@ -172,9 +172,6 @@ define ["jasmine", "sinon", "squire"],
waitsFor
(
=>
@
view
),
"AssetView was not created"
,
1000
$
.
ajax
()
@
requests
=
requests
=
[]
@
xhr
=
sinon
.
useFakeXMLHttpRequest
()
@
xhr
.
onCreate
=
(
xhr
)
->
requests
.
push
(
xhr
)
afterEach
->
delete
window
.
analytics
...
...
@@ -190,18 +187,22 @@ define ["jasmine", "sinon", "squire"],
expect
(
@
view
.
$el
).
toContainText
(
"test asset 2"
)
it
"should remove the deleted asset from the view"
,
->
requests
=
create_sinon
[
"requests"
](
this
)
# Delete the 2nd asset with success from server.
@
view
.
render
().
$
(
".remove-asset-button"
)[
1
].
click
()
@
promptSpies
.
constructor
.
mostRecentCall
.
args
[
0
].
actions
.
primary
.
click
(
@
promptSpies
)
req
.
respond
(
200
)
for
req
in
@
requests
req
.
respond
(
200
)
for
req
in
requests
expect
(
@
view
.
$el
).
toContainText
(
"test asset 1"
)
expect
(
@
view
.
$el
).
not
.
toContainText
(
"test asset 2"
)
it
"does not remove asset if deletion failed"
,
->
requests
=
create_sinon
[
"requests"
](
this
)
# Delete the 2nd asset, but mimic a failure from the server.
@
view
.
render
().
$
(
".remove-asset-button"
)[
1
].
click
()
@
promptSpies
.
constructor
.
mostRecentCall
.
args
[
0
].
actions
.
primary
.
click
(
@
promptSpies
)
req
.
respond
(
404
)
for
req
in
@
requests
req
.
respond
(
404
)
for
req
in
requests
expect
(
@
view
.
$el
).
toContainText
(
"test asset 1"
)
expect
(
@
view
.
$el
).
toContainText
(
"test asset 2"
)
...
...
cms/static/coffee/spec/views/course_info_spec.coffee
View file @
9f91935f
This diff is collapsed.
Click to expand it.
cms/static/coffee/spec/views/overview_spec.coffee
View file @
9f91935f
define
[
"js/views/overview"
,
"js/views/feedback_notification"
,
"sinon"
,
"js/base"
,
"date"
,
"jquery.timepicker"
],
(
Overview
,
Notification
,
sinon
)
->
define
[
"js/views/overview"
,
"js/views/feedback_notification"
,
"
js/spec/create_
sinon"
,
"js/base"
,
"date"
,
"jquery.timepicker"
],
(
Overview
,
Notification
,
create_
sinon
)
->
describe
"Course Overview"
,
->
beforeEach
->
...
...
@@ -71,9 +71,6 @@ define ["js/views/overview", "js/views/feedback_notification", "sinon", "js/base
@
notificationSpy
=
spyOn
(
Notification
.
Mini
.
prototype
,
'show'
).
andCallThrough
()
window
.
analytics
=
jasmine
.
createSpyObj
(
'analytics'
,
[
'track'
])
window
.
course_location_analytics
=
jasmine
.
createSpy
()
@
xhr
=
sinon
.
useFakeXMLHttpRequest
()
requests
=
@
requests
=
[]
@
xhr
.
onCreate
=
(
req
)
->
requests
.
push
(
req
)
Overview
.
overviewDragger
.
makeDraggable
(
'.unit'
,
...
...
@@ -104,9 +101,11 @@ define ["js/views/overview", "js/views/feedback_notification", "sinon", "js/base
# expect(@requests[0].url).toEqual('/delete_item')
it
"should not delete model when cancel is clicked"
,
->
requests
=
create_sinon
[
"requests"
](
this
)
$
(
'a.delete-section-button'
).
click
()
$
(
'a.action-secondary'
).
click
()
expect
(
@
requests
.
length
).
toEqual
(
0
)
expect
(
requests
.
length
).
toEqual
(
0
)
# Fails sporadically in Jenkins.
# it "should show a confirmation on delete", ->
...
...
@@ -328,22 +327,19 @@ define ["js/views/overview", "js/views/feedback_notification", "sinon", "js/base
)
expect
(
$
(
'#subsection-2'
)).
not
.
toHaveClass
(
'collapsed'
)
x
describe
"AJAX"
,
->
describe
"AJAX"
,
->
beforeEach
->
@
requests
=
requests
=
[]
@
xhr
=
sinon
.
useFakeXMLHttpRequest
()
@
xhr
.
onCreate
=
(
xhr
)
->
requests
.
push
(
xhr
)
@
savingSpies
=
spyOnConstructor
(
Notification
,
"Mini"
,
[
"show"
,
"hide"
])
@
savingSpies
.
show
.
andReturn
(
@
savingSpies
)
@
clock
=
sinon
.
useFakeTimers
()
afterEach
->
@
xhr
.
restore
()
@
clock
.
restore
()
it
"should send an update on reorder"
,
->
requests
=
create_sinon
[
"requests"
](
this
)
Overview
.
overviewDragger
.
dragState
.
dropDestination
=
$
(
'#unit-4'
)
Overview
.
overviewDragger
.
dragState
.
attachMethod
=
"after"
Overview
.
overviewDragger
.
dragState
.
parentList
=
$
(
'#subsection-2'
)
...
...
@@ -357,7 +353,7 @@ define ["js/views/overview", "js/views/feedback_notification", "sinon", "js/base
null
,
{
clientX
:
$
(
'#unit-1'
).
offset
().
left
}
)
expect
(
@
requests
.
length
).
toEqual
(
2
)
expect
(
requests
.
length
).
toEqual
(
2
)
expect
(
@
savingSpies
.
constructor
).
toHaveBeenCalled
()
expect
(
@
savingSpies
.
show
).
toHaveBeenCalled
()
expect
(
@
savingSpies
.
hide
).
not
.
toHaveBeenCalled
()
...
...
@@ -366,11 +362,11 @@ define ["js/views/overview", "js/views/feedback_notification", "sinon", "js/base
expect
(
$
(
'#unit-1'
)).
toHaveClass
(
'was-dropped'
)
# We expect 2 requests to be sent-- the first for removing Unit 1 from Subsection 1,
# and the second for adding Unit 1 to the end of Subsection 2.
expect
(
@
requests
[
0
].
requestBody
).
toEqual
(
'{"children":["second-unit-id","third-unit-id"]}'
)
@
requests
[
0
].
respond
(
200
)
expect
(
requests
[
0
].
requestBody
).
toEqual
(
'{"children":["second-unit-id","third-unit-id"]}'
)
requests
[
0
].
respond
(
200
)
expect
(
@
savingSpies
.
hide
).
not
.
toHaveBeenCalled
()
expect
(
@
requests
[
1
].
requestBody
).
toEqual
(
'{"children":["fourth-unit-id","first-unit-id"]}'
)
@
requests
[
1
].
respond
(
200
)
expect
(
requests
[
1
].
requestBody
).
toEqual
(
'{"children":["fourth-unit-id","first-unit-id"]}'
)
requests
[
1
].
respond
(
200
)
expect
(
@
savingSpies
.
hide
).
toHaveBeenCalled
()
# Class is removed in a timeout.
@
clock
.
tick
(
1001
)
...
...
cms/static/coffee/spec/views/section_spec.coffee
View file @
9f91935f
define
[
"js/models/section"
,
"js/views/section_show"
,
"js/views/section_edit"
,
"
sinon"
],
(
Section
,
SectionShow
,
SectionEdit
,
sinon
)
->
define
[
"js/models/section"
,
"js/views/section_show"
,
"js/views/section_edit"
,
"
js/spec/create_sinon"
],
(
Section
,
SectionShow
,
SectionEdit
,
create_
sinon
)
->
describe
"SectionShow"
,
->
describe
"Basic"
,
->
...
...
@@ -39,9 +39,6 @@ define ["js/models/section", "js/views/section_show", "js/views/section_edit", "
.
andCallThrough
()
window
.
analytics
=
jasmine
.
createSpyObj
(
'analytics'
,
[
'track'
])
window
.
course_location_analytics
=
jasmine
.
createSpy
()
@
requests
=
requests
=
[]
@
xhr
=
sinon
.
useFakeXMLHttpRequest
()
@
xhr
.
onCreate
=
(
xhr
)
->
requests
.
push
(
xhr
)
@
model
=
new
Section
({
id
:
42
...
...
@@ -51,7 +48,6 @@ define ["js/models/section", "js/views/section_show", "js/views/section_edit", "
@
view
.
render
()
afterEach
->
@
xhr
.
restore
()
delete
window
.
analytics
delete
window
.
course_location_analytics
...
...
@@ -68,8 +64,10 @@ define ["js/models/section", "js/views/section_show", "js/views/section_edit", "
expect
(
@
model
.
save
).
toHaveBeenCalled
()
it
"should call switchToShowView when save() is successful"
,
->
requests
=
create_sinon
[
"requests"
](
this
)
@
view
.
$
(
"input[type=submit]"
).
click
()
@
requests
[
0
].
respond
(
200
)
requests
[
0
].
respond
(
200
)
expect
(
@
view
.
switchToShowView
).
toHaveBeenCalled
()
it
"should call showInvalidMessage when validation is unsuccessful"
,
->
...
...
cms/static/coffee/spec/views/textbook_spec.coffee
View file @
9f91935f
define
[
"js/models/textbook"
,
"js/models/chapter"
,
"js/collections/chapter"
,
"js/models/course"
,
"js/collections/textbook"
,
"js/views/show_textbook"
,
"js/views/edit_textbook"
,
"js/views/list_textbooks"
,
"js/views/edit_chapter"
,
"js/views/feedback_prompt"
,
"js/views/feedback_notification"
,
"sinon"
,
"jasmine-stealth"
],
(
Textbook
,
Chapter
,
ChapterSet
,
Course
,
TextbookSet
,
ShowTextbook
,
EditTextbook
,
ListTexbook
,
EditChapter
,
Prompt
,
Notification
,
sinon
)
->
"
js/spec/create_
sinon"
,
"jasmine-stealth"
],
(
Textbook
,
Chapter
,
ChapterSet
,
Course
,
TextbookSet
,
ShowTextbook
,
EditTextbook
,
ListTexbook
,
EditChapter
,
Prompt
,
Notification
,
create_
sinon
)
->
feedbackTpl
=
readFixtures
(
'system-feedback.underscore'
)
beforeEach
->
...
...
@@ -74,34 +74,31 @@ define ["js/models/textbook", "js/models/chapter", "js/collections/chapter", "js
describe
"AJAX"
,
->
beforeEach
->
@
requests
=
requests
=
[]
@
xhr
=
sinon
.
useFakeXMLHttpRequest
()
@
xhr
.
onCreate
=
(
xhr
)
->
requests
.
push
(
xhr
)
@
savingSpies
=
spyOnConstructor
(
Notification
,
"Mini"
,
[
"show"
,
"hide"
])
@
savingSpies
.
show
.
andReturn
(
@
savingSpies
)
CMS
.
URL
.
TEXTBOOKS
=
"/textbooks"
afterEach
->
@
xhr
.
restore
()
delete
CMS
.
URL
.
TEXTBOOKS
it
"should destroy itself on confirmation"
,
->
requests
=
create_sinon
[
"requests"
](
this
)
@
view
.
render
().
$
(
".delete"
).
click
()
ctorOptions
=
@
promptSpies
.
constructor
.
mostRecentCall
.
args
[
0
]
# run the primary function to indicate confirmation
ctorOptions
.
actions
.
primary
.
click
(
@
promptSpies
)
# AJAX request has been sent, but not yet returned
expect
(
@
model
.
destroy
).
toHaveBeenCalled
()
expect
(
@
requests
.
length
).
toEqual
(
1
)
expect
(
requests
.
length
).
toEqual
(
1
)
expect
(
@
savingSpies
.
constructor
).
toHaveBeenCalled
()
expect
(
@
savingSpies
.
show
).
toHaveBeenCalled
()
expect
(
@
savingSpies
.
hide
).
not
.
toHaveBeenCalled
()
savingOptions
=
@
savingSpies
.
constructor
.
mostRecentCall
.
args
[
0
]
expect
(
savingOptions
.
title
).
toMatch
(
/Deleting/
)
# return a success response
@
requests
[
0
].
respond
(
200
)
requests
[
0
].
respond
(
200
)
expect
(
@
savingSpies
.
hide
).
toHaveBeenCalled
()
expect
(
@
collection
.
contains
(
@
model
)).
toBeFalsy
()
...
...
cms/static/coffee/spec/views/upload_spec.coffee
View file @
9f91935f
define
[
"js/models/uploads"
,
"js/views/uploads"
,
"js/models/chapter"
,
"
sinon"
],
(
FileUpload
,
UploadDialog
,
Chapter
,
sinon
)
->
define
[
"js/models/uploads"
,
"js/views/uploads"
,
"js/models/chapter"
,
"
js/spec/create_sinon"
],
(
FileUpload
,
UploadDialog
,
Chapter
,
create_
sinon
)
->
feedbackTpl
=
readFixtures
(
'system-feedback.underscore'
)
...
...
@@ -78,20 +78,18 @@ define ["js/models/uploads", "js/views/uploads", "js/models/chapter", "sinon"],
describe
"Uploads"
,
->
beforeEach
->
@
requests
=
requests
=
[]
@
xhr
=
sinon
.
useFakeXMLHttpRequest
()
@
xhr
.
onCreate
=
(
xhr
)
->
requests
.
push
(
xhr
)
@
clock
=
sinon
.
useFakeTimers
()
afterEach
->
@
xhr
.
restore
()
@
clock
.
restore
()
it
"can upload correctly"
,
->
requests
=
create_sinon
[
"requests"
](
this
)
@
view
.
upload
()
expect
(
@
model
.
get
(
"uploading"
)).
toBeTruthy
()
expect
(
@
requests
.
length
).
toEqual
(
1
)
request
=
@
requests
[
0
]
expect
(
requests
.
length
).
toEqual
(
1
)
request
=
requests
[
0
]
expect
(
request
.
url
).
toEqual
(
"/upload"
)
expect
(
request
.
method
).
toEqual
(
"POST"
)
...
...
@@ -102,14 +100,18 @@ define ["js/models/uploads", "js/views/uploads", "js/models/chapter", "sinon"],
expect
(
@
dialogResponse
.
pop
()).
toEqual
(
"dummy_response"
)
it
"can handle upload errors"
,
->
requests
=
create_sinon
[
"requests"
](
this
)
@
view
.
upload
()
@
requests
[
0
].
respond
(
500
)
requests
[
0
].
respond
(
500
)
expect
(
@
model
.
get
(
"title"
)).
toMatch
(
/error/
)
expect
(
@
view
.
remove
).
not
.
toHaveBeenCalled
()
it
"removes itself after two seconds on successful upload"
,
->
requests
=
create_sinon
[
"requests"
](
this
)
@
view
.
upload
()
@
requests
[
0
].
respond
(
200
,
{
"Content-Type"
:
"application/json"
},
requests
[
0
].
respond
(
200
,
{
"Content-Type"
:
"application/json"
},
'{"response": "dummy_response"}'
)
expect
(
@
view
.
remove
).
not
.
toHaveBeenCalled
()
@
clock
.
tick
(
2001
)
...
...
cms/static/js/spec/create_sinon.js
0 → 100644
View file @
9f91935f
define
([
"sinon"
],
function
(
sinon
)
{
var
fakeServer
=
function
(
statusCode
,
that
)
{
var
server
=
sinon
.
fakeServer
.
create
();
that
.
after
(
function
()
{
server
.
restore
();
});
server
.
respondWith
([
statusCode
,
{},
''
]);
return
server
;
};
var
fakeRequests
=
function
(
that
)
{
var
requests
=
[];
var
xhr
=
sinon
.
useFakeXMLHttpRequest
();
xhr
.
onCreate
=
function
(
request
)
{
requests
.
push
(
request
)
};
that
.
after
(
function
()
{
xhr
.
restore
();
});
return
requests
;
};
return
{
"server"
:
fakeServer
,
"requests"
:
fakeRequests
};
});
rakelib/js_test.rake
View file @
9f91935f
JS_TEST_SUITES
=
{
'lms'
=>
'lms/static/js_test.yml'
,
'cms'
=>
'cms/static/js_test.yml'
,
#
'cms-squire' => 'cms/static/js_test_squire.yml',
'cms-squire'
=>
'cms/static/js_test_squire.yml'
,
'xmodule'
=>
'common/lib/xmodule/xmodule/js/js_test.yml'
,
'common'
=>
'common/static/js_test.yml'
,
}
...
...
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