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
c59d515c
Commit
c59d515c
authored
Jun 17, 2013
by
David Baumgold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added unit tests for file upload widget
parent
7bb86b6c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
82 additions
and
0 deletions
+82
-0
cms/static/coffee/files.json
+1
-0
cms/static/coffee/fixtures/upload-dialog.underscore
+2
-0
cms/static/coffee/spec/views/textbook_spec.coffee
+79
-0
No files found.
cms/static/coffee/files.json
View file @
c59d515c
...
...
@@ -11,6 +11,7 @@
"js/vendor/backbone-min.js"
,
"js/vendor/backbone-associations-min.js"
,
"js/vendor/jquery.leanModal.min.js"
,
"js/vendor/jquery.form.js"
,
"js/vendor/sinon-1.7.1.js"
,
"js/vendor/jasmine-stealth.js"
,
"js/test/i18n.js"
...
...
cms/static/coffee/fixtures/upload-dialog.underscore
0 → 120000
View file @
c59d515c
../../../templates/js/upload-dialog.underscore
\ No newline at end of file
cms/static/coffee/spec/views/textbook_spec.coffee
View file @
c59d515c
...
...
@@ -190,3 +190,82 @@ describe "CMS.Views.ListTextbooks", ->
expect
(
@
view
.
$el
).
not
.
toContain
(
@
showSpies
.
$el
)
describe
"CMS.Views.UploadDialog"
,
->
tpl
=
readFixtures
(
"upload-dialog.underscore"
)
beforeEach
->
setFixtures
(
$
(
"<script>"
,
{
id
:
"upload-dialog-tpl"
,
type
:
"text/template"
}).
text
(
tpl
))
window
.
UPLOAD_ASSET_CALLBACK_URL
=
"/upload"
@
requests
=
requests
=
[]
@
xhr
=
sinon
.
useFakeXMLHttpRequest
()
@
xhr
.
onCreate
=
(
xhr
)
->
requests
.
push
(
xhr
)
@
model
=
new
CMS
.
Models
.
FileUpload
()
@
chapter
=
new
CMS
.
Models
.
Chapter
()
@
view
=
new
CMS
.
Views
.
UploadDialog
({
model
:
@
model
,
chapter
:
@
chapter
})
spyOn
(
@
view
,
'remove'
).
andCallThrough
()
# create mock file input, so that we aren't subject to browser restrictions
@
mockFiles
=
[]
mockFileInput
=
jasmine
.
createSpy
(
'mockFileInput'
)
mockFileInput
.
files
=
@
mockFiles
jqMockFileInput
=
jasmine
.
createSpyObj
(
'jqMockFileInput'
,
[
'get'
,
'replaceWith'
])
jqMockFileInput
.
get
.
andReturn
(
mockFileInput
)
realMethod
=
@
view
.
$
spyOn
(
@
view
,
"$"
).
andCallFake
(
selector
)
->
if
selector
==
"input[type=file]"
jqMockFileInput
else
realMethod
.
apply
(
this
,
arguments
)
afterEach
->
delete
window
.
UPLOAD_ASSET_CALLBACK_URL
@
xhr
.
restore
()
it
"should be shown by default"
,
->
expect
(
@
view
.
options
.
shown
).
toBeTruthy
()
it
"should render without a file selected"
,
->
@
view
.
render
()
expect
(
@
view
.
$el
).
toContain
(
"input[type=file]"
)
expect
(
@
view
.
$
(
".action-upload"
)).
toBeDisabled
()
it
"should render with a file selected"
,
->
@
mockFiles
.
push
({
name
:
"fake.pdf"
})
@
view
.
render
()
expect
(
@
view
.
$el
).
toContain
(
"input[type=file]"
)
expect
(
@
view
.
$
(
".action-upload"
)).
not
.
toBeDisabled
()
it
"adds body class on show()"
,
->
@
view
.
show
()
expect
(
@
view
.
options
.
shown
).
toBeTruthy
()
# can't test: this blows up the spec runner
# expect($("body")).toHaveClass("dialog-is-shown")
it
"removes body class on hide()"
,
->
@
view
.
hide
()
expect
(
@
view
.
options
.
shown
).
toBeFalsy
()
# can't test: this blows up the spec runner
# expect($("body")).not.toHaveClass("dialog-is-shown")
it
"can upload correctly"
,
->
@
view
.
upload
()
expect
(
@
model
.
get
(
"uploading"
)).
toBeTruthy
()
expect
(
@
requests
.
length
).
toEqual
(
1
)
request
=
@
requests
[
0
]
expect
(
request
.
url
).
toEqual
(
UPLOAD_ASSET_CALLBACK_URL
)
expect
(
request
.
method
).
toEqual
(
"POST"
)
request
.
respond
(
200
,
{
"Content-Type"
:
"application/json"
},
'{"displayname": "starfish", "url": "/uploaded/starfish.pdf"}'
)
expect
(
@
model
.
get
(
"uploading"
)).
toBeFalsy
()
expect
(
@
chapter
.
get
(
"name"
)).
toEqual
(
"starfish"
)
expect
(
@
chapter
.
get
(
"asset_path"
)).
toEqual
(
"/uploaded/starfish.pdf"
)
expect
(
@
view
.
remove
).
toHaveBeenCalled
()
it
"can handle upload errors"
,
->
@
view
.
upload
()
@
requests
[
0
].
respond
(
500
)
expect
(
@
model
.
get
(
"title"
)).
toMatch
(
/error/
)
expect
(
@
view
.
remove
).
not
.
toHaveBeenCalled
()
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