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
66b53926
Commit
66b53926
authored
Apr 20, 2016
by
Andy Armstrong
Committed by
Usman Khalid
Apr 22, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix spec initialization ordering
parent
fefc88b0
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
60 additions
and
60 deletions
+60
-60
cms/static/coffee/spec/views/upload_spec.coffee
+60
-60
No files found.
cms/static/coffee/spec/views/upload_spec.coffee
View file @
66b53926
...
...
@@ -7,72 +7,78 @@ define ["js/models/uploads", "js/views/uploads", "js/models/chapter", "common/js
modal_helpers
.
installModalTemplates
()
appendSetFixtures
(
$
(
"<script>"
,
{
id
:
"upload-dialog-tpl"
,
type
:
"text/template"
}).
text
(
tpl
))
CMS
.
URL
.
UPLOAD_ASSET
=
"/upload"
@
model
=
new
FileUpload
(
mimeTypes
:
[
'application/pdf'
]
)
@
dialogResponse
=
dialogResponse
=
[]
@
view
=
new
UploadDialog
(
model
:
@
model
,
@
mockFiles
=
[]
afterEach
->
delete
CMS
.
URL
.
UPLOAD_ASSET
if
(
@
lastView
&&
modal_helpers
.
isShowingModal
(
@
lastView
))
@
lastView
.
hide
()
createTestView
=
(
test
)
->
view
=
new
UploadDialog
(
model
:
test
.
model
,
url
:
CMS
.
URL
.
UPLOAD_ASSET
,
onSuccess
:
(
response
)
=>
dialogResponse
.
push
(
response
.
response
)
test
.
dialogResponse
.
push
(
response
.
response
)
)
spyOn
(
@
view
,
'remove'
).
and
.
callThrough
()
spyOn
(
view
,
'remove'
).
and
.
callThrough
()
# create mock file input, so that we aren't subject to browser restrictions
@
mockFiles
=
[]
mockFileInput
=
jasmine
.
createSpy
(
'mockFileInput'
)
mockFileInput
.
files
=
@
mockFiles
mockFileInput
.
files
=
test
.
mockFiles
jqMockFileInput
=
jasmine
.
createSpyObj
(
'jqMockFileInput'
,
[
'get'
,
'replaceWith'
])
jqMockFileInput
.
get
.
and
.
returnValue
(
mockFileInput
)
realMethod
=
@
view
.
$
spyOn
(
@
view
,
"$"
).
and
.
callFake
(
selector
)
->
originalView$
=
view
.
$
spyOn
(
view
,
"$"
).
and
.
callFake
(
selector
)
->
if
selector
==
"input[type=file]"
jqMockFileInput
else
realMethod
.
apply
(
this
,
arguments
)
afterEach
->
delete
CMS
.
URL
.
UPLOAD_ASSET
if
(
@
view
&&
modal_helpers
.
isShowingModal
(
@
view
))
@
view
.
hide
()
originalView$
.
apply
(
this
,
arguments
)
@
lastView
=
view
describe
"Basic"
,
->
it
"should render without a file selected"
,
->
@
view
.
render
()
expect
(
@
view
.
$el
).
toContainElement
(
"input[type=file]"
)
expect
(
@
view
.
$
(
".action-upload"
)).
toHaveClass
(
"disabled"
)
view
=
createTestView
(
this
)
view
.
render
()
expect
(
view
.
$el
).
toContainElement
(
"input[type=file]"
)
expect
(
view
.
$
(
".action-upload"
)).
toHaveClass
(
"disabled"
)
it
"should render with a PDF selected"
,
->
view
=
createTestView
(
this
)
file
=
{
name
:
"fake.pdf"
,
"type"
:
"application/pdf"
}
@
mockFiles
.
push
(
file
)
@
model
.
set
(
"selectedFile"
,
file
)
@
view
.
render
()
expect
(
@
view
.
$el
).
toContainElement
(
"input[type=file]"
)
expect
(
@
view
.
$el
).
not
.
toContainElement
(
"#upload_error"
)
expect
(
@
view
.
$
(
".action-upload"
)).
not
.
toHaveClass
(
"disabled"
)
view
.
render
()
expect
(
view
.
$el
).
toContainElement
(
"input[type=file]"
)
expect
(
view
.
$el
).
not
.
toContainElement
(
"#upload_error"
)
expect
(
view
.
$
(
".action-upload"
)).
not
.
toHaveClass
(
"disabled"
)
it
"should render an error with an invalid file type selected"
,
->
view
=
createTestView
(
this
)
file
=
{
name
:
"fake.png"
,
"type"
:
"image/png"
}
@
mockFiles
.
push
(
file
)
@
model
.
set
(
"selectedFile"
,
file
)
@
view
.
render
()
expect
(
@
view
.
$el
).
toContainElement
(
"input[type=file]"
)
expect
(
@
view
.
$el
).
toContainElement
(
"#upload_error"
)
expect
(
@
view
.
$
(
".action-upload"
)).
toHaveClass
(
"disabled"
)
view
.
render
()
expect
(
view
.
$el
).
toContainElement
(
"input[type=file]"
)
expect
(
view
.
$el
).
toContainElement
(
"#upload_error"
)
expect
(
view
.
$
(
".action-upload"
)).
toHaveClass
(
"disabled"
)
it
"should render an error with an invalid file type after a correct file type selected"
,
->
view
=
createTestView
(
this
)
correctFile
=
{
name
:
"fake.pdf"
,
"type"
:
"application/pdf"
}
inCorrectFile
=
{
name
:
"fake.png"
,
"type"
:
"image/png"
}
event
=
{}
@
view
.
render
()
view
.
render
()
event
.
target
=
{
"files"
:
[
correctFile
]}
@
view
.
selectFile
(
event
)
expect
(
@
view
.
$el
).
toContainElement
(
"input[type=file]"
)
expect
(
@
view
.
$el
).
not
.
toContainElement
(
"#upload_error"
)
expect
(
@
view
.
$
(
".action-upload"
)).
not
.
toHaveClass
(
"disabled"
)
view
.
selectFile
(
event
)
expect
(
view
.
$el
).
toContainElement
(
"input[type=file]"
)
expect
(
view
.
$el
).
not
.
toContainElement
(
"#upload_error"
)
expect
(
view
.
$
(
".action-upload"
)).
not
.
toHaveClass
(
"disabled"
)
realMethod
=
@
model
.
set
spyOn
(
@
model
,
"set"
).
and
.
callFake
(
data
)
->
...
...
@@ -83,10 +89,10 @@ define ["js/models/uploads", "js/views/uploads", "js/models/chapter", "common/js
realMethod
.
apply
(
this
,
arguments
)
event
.
target
=
{
"files"
:
[
inCorrectFile
]}
@
view
.
selectFile
(
event
)
expect
(
@
view
.
$el
).
toContainElement
(
"input[type=file]"
)
expect
(
@
view
.
$el
).
toContainElement
(
"#upload_error"
)
expect
(
@
view
.
$
(
".action-upload"
)).
toHaveClass
(
"disabled"
)
view
.
selectFile
(
event
)
expect
(
view
.
$el
).
toContainElement
(
"input[type=file]"
)
expect
(
view
.
$el
).
toContainElement
(
"#upload_error"
)
expect
(
view
.
$
(
".action-upload"
)).
toHaveClass
(
"disabled"
)
describe
"Uploads"
,
->
beforeEach
->
...
...
@@ -96,38 +102,32 @@ define ["js/models/uploads", "js/views/uploads", "js/models/chapter", "common/js
@
clock
.
restore
()
it
"can upload correctly"
,
->
requests
=
AjaxHelpers
[
"requests"
](
this
)
@
view
.
render
()
@
view
.
upload
()
requests
=
AjaxHelpers
.
requests
(
this
);
view
=
createTestView
(
this
)
view
.
render
()
view
.
upload
()
expect
(
@
model
.
get
(
"uploading"
)).
toBeTruthy
()
expect
(
requests
.
length
).
toEqual
(
1
)
request
=
requests
[
0
]
expect
(
request
.
url
).
toEqual
(
"/upload"
)
expect
(
request
.
method
).
toEqual
(
"POST"
)
request
.
respond
(
200
,
{
"Content-Type"
:
"application/json"
},
'{"response": "dummy_response"}'
)
AjaxHelpers
.
expectRequest
(
requests
,
"POST"
,
"/upload"
)
AjaxHelpers
.
respondWithJson
(
requests
,
{
response
:
"dummy_response"
})
expect
(
@
model
.
get
(
"uploading"
)).
toBeFalsy
()
expect
(
@
model
.
get
(
"finished"
)).
toBeTruthy
()
expect
(
@
dialogResponse
.
pop
()).
toEqual
(
"dummy_response"
)
it
"can handle upload errors"
,
->
requests
=
AjaxHelpers
[
"requests"
](
this
)
@
view
.
render
()
@
view
.
upload
()
requests
[
0
].
respond
(
500
)
requests
=
AjaxHelpers
.
requests
(
this
);
view
=
createTestView
(
this
)
view
.
render
()
view
.
upload
()
AjaxHelpers
.
respondWithError
(
requests
)
expect
(
@
model
.
get
(
"title"
)).
toMatch
(
/error/
)
expect
(
@
view
.
remove
).
not
.
toHaveBeenCalled
()
expect
(
view
.
remove
).
not
.
toHaveBeenCalled
()
it
"removes itself after two seconds on successful upload"
,
->
requests
=
AjaxHelpers
[
"requests"
](
this
)
@
view
.
render
()
@
view
.
upload
()
requests
[
0
].
respond
(
200
,
{
"Content-Type"
:
"application/json"
},
'{"response": "dummy_response"}'
)
expect
(
modal_helpers
.
isShowingModal
(
@
view
)).
toBeTruthy
();
requests
=
AjaxHelpers
.
requests
(
this
);
view
=
createTestView
(
this
)
view
.
render
()
view
.
upload
()
AjaxHelpers
.
respondWithJson
(
requests
,
{
response
:
"dummy_response"
})
expect
(
modal_helpers
.
isShowingModal
(
view
)).
toBeTruthy
();
@
clock
.
tick
(
2001
)
expect
(
modal_helpers
.
isShowingModal
(
@
view
)).
toBeFalsy
();
expect
(
modal_helpers
.
isShowingModal
(
view
)).
toBeFalsy
();
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