Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
edx-platform-release
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hsin-Yu Chien
edx-platform-release
Commits
a861e015
Commit
a861e015
authored
11 years ago
by
David Baumgold
Browse files
Options
Downloads
Patches
Plain Diff
Reorganize Jasmine uploader tests
parent
c2ef6a53
Loading
Loading
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
cms/static/coffee/spec/views/textbook_spec.coffee
+73
-101
73 additions, 101 deletions
cms/static/coffee/spec/views/textbook_spec.coffee
with
73 additions
and
101 deletions
cms/static/coffee/spec/views/textbook_spec.coffee
+
73
−
101
View file @
a861e015
...
...
@@ -264,9 +264,6 @@ describe "CMS.Views.UploadDialog", ->
setFixtures
(
$
(
"<script>"
,
{
id
:
"upload-dialog-tpl"
,
type
:
"text/template"
}).
text
(
tpl
))
appendSetFixtures
(
$
(
"<script>"
,
{
id
:
"system-feedback-tpl"
,
type
:
"text/template"
}).
text
(
feedbackTpl
))
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
()
...
...
@@ -288,108 +285,83 @@ describe "CMS.Views.UploadDialog", ->
afterEach
->
delete
window
.
UPLOAD_ASSET_CALLBACK_URL
@
xhr
.
restore
()
it
"should be shown by default"
,
->
expect
(
@
view
.
options
.
shown
).
toBeTruthy
()
describe
"Basic"
,
->
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 without a file selected"
,
->
@
view
.
render
()
expect
(
@
view
.
$el
).
toContain
(
"input[type=file]"
)
expect
(
@
view
.
$
(
".action-upload"
)).
toBeDisabled
()
it
"should render with a PDF selected"
,
->
file
=
{
name
:
"fake.pdf"
,
"type"
:
"application/pdf"
}
@
mockFiles
.
push
(
file
)
@
model
.
set
(
"selectedFile"
,
file
)
@
view
.
render
()
expect
(
@
view
.
$el
).
toContain
(
"input[type=file]"
)
expect
(
@
view
.
$el
).
not
.
toContain
(
"p.error"
)
expect
(
@
view
.
$
(
".action-upload"
)).
not
.
toBeDisabled
()
it
"should render an error with an invalid file type selected"
,
->
file
=
{
name
:
"fake.png"
,
"type"
:
"image/png"
}
@
mockFiles
.
push
(
file
)
@
model
.
set
(
"selectedFile"
,
file
)
@
view
.
render
()
expect
(
@
view
.
$el
).
toContain
(
"input[type=file]"
)
expect
(
@
view
.
$el
).
toContain
(
"p.error"
)
expect
(
@
view
.
$
(
".action-upload"
)).
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
(
@
model
.
get
(
"finished"
)).
toBeTruthy
()
expect
(
@
chapter
.
get
(
"name"
)).
toEqual
(
"starfish"
)
expect
(
@
chapter
.
get
(
"asset_path"
)).
toEqual
(
"/uploaded/starfish.pdf"
)
it
"can handle upload errors"
,
->
@
view
.
upload
()
@
requests
[
0
].
respond
(
500
)
expect
(
@
model
.
get
(
"title"
)).
toMatch
(
/error/
)
expect
(
@
view
.
remove
).
not
.
toHaveBeenCalled
()
describe
"CMS.Views.UploadDialog timing"
,
->
tpl
=
readFixtures
(
"upload-dialog.underscore"
)
it
"should render with a PDF selected"
,
->
file
=
{
name
:
"fake.pdf"
,
"type"
:
"application/pdf"
}
@
mockFiles
.
push
(
file
)
@
model
.
set
(
"selectedFile"
,
file
)
@
view
.
render
()
expect
(
@
view
.
$el
).
toContain
(
"input[type=file]"
)
expect
(
@
view
.
$el
).
not
.
toContain
(
"p.error"
)
expect
(
@
view
.
$
(
".action-upload"
)).
not
.
toBeDisabled
()
it
"should render an error with an invalid file type selected"
,
->
file
=
{
name
:
"fake.png"
,
"type"
:
"image/png"
}
@
mockFiles
.
push
(
file
)
@
model
.
set
(
"selectedFile"
,
file
)
@
view
.
render
()
expect
(
@
view
.
$el
).
toContain
(
"input[type=file]"
)
expect
(
@
view
.
$el
).
toContain
(
"p.error"
)
expect
(
@
view
.
$
(
".action-upload"
)).
toBeDisabled
()
beforeEach
->
setFixtures
(
$
(
"<script>"
,
{
id
:
"upload-dialog-tpl"
,
type
:
"text/template"
}).
text
(
tpl
))
appendSetFixtures
(
$
(
"<script>"
,
{
id
:
"system-feedback-tpl"
,
type
:
"text/template"
}).
text
(
feedbackTpl
))
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
()
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")
# 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
)
@
clock
=
sinon
.
useFakeTimers
()
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")
afterEach
->
delete
window
.
UPLOAD_ASSET_CALLBACK_URL
@
xhr
.
restore
()
@
clock
.
restore
()
it
"removes itself after two seconds on successful upload"
,
->
@
view
.
upload
()
@
requests
[
0
].
respond
(
200
,
{
"Content-Type"
:
"application/json"
},
'{"displayname": "starfish", "url": "/uploaded/starfish.pdf"}'
)
expect
(
@
view
.
remove
).
not
.
toHaveBeenCalled
()
@
clock
.
tick
(
2001
)
expect
(
@
view
.
remove
).
toHaveBeenCalled
()
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"
,
->
@
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
(
@
model
.
get
(
"finished"
)).
toBeTruthy
()
expect
(
@
chapter
.
get
(
"name"
)).
toEqual
(
"starfish"
)
expect
(
@
chapter
.
get
(
"asset_path"
)).
toEqual
(
"/uploaded/starfish.pdf"
)
it
"can handle upload errors"
,
->
@
view
.
upload
()
@
requests
[
0
].
respond
(
500
)
expect
(
@
model
.
get
(
"title"
)).
toMatch
(
/error/
)
expect
(
@
view
.
remove
).
not
.
toHaveBeenCalled
()
it
"removes itself after two seconds on successful upload"
,
->
@
view
.
upload
()
@
requests
[
0
].
respond
(
200
,
{
"Content-Type"
:
"application/json"
},
'{"displayname": "starfish", "url": "/uploaded/starfish.pdf"}'
)
expect
(
@
view
.
remove
).
not
.
toHaveBeenCalled
()
@
clock
.
tick
(
2001
)
expect
(
@
view
.
remove
).
toHaveBeenCalled
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment