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
7b02932f
Commit
7b02932f
authored
Jun 21, 2013
by
David Baumgold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for CMS.Views.ChapterEdit, save content before opening upload dialog
parent
c750f08d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
0 deletions
+55
-0
cms/static/coffee/spec/views/textbook_spec.coffee
+51
-0
cms/static/js/views/textbook.js
+4
-0
No files found.
cms/static/coffee/spec/views/textbook_spec.coffee
View file @
7b02932f
...
...
@@ -119,6 +119,7 @@ describe "CMS.Views.ListTextbooks", ->
beforeEach
->
setFixtures
(
$
(
"<script>"
,
{
id
:
"no-textbooks-tpl"
,
type
:
"text/template"
}).
text
(
noTextbooksTpl
))
appendSetFixtures
(
$
(
"<script>"
,
{
id
:
"system-feedback-tpl"
,
type
:
"text/template"
}).
text
(
feedbackTpl
))
@
showSpies
=
spyOnConstructor
(
CMS
.
Views
,
"TextbookShow"
,
[
"render"
])
@
showSpies
.
render
.
andReturn
(
@
showSpies
)
# equivalent of `return this`
showEl
=
$
(
"<li>"
)
...
...
@@ -190,11 +191,61 @@ describe "CMS.Views.ListTextbooks", ->
expect
(
@
view
.
$el
).
not
.
toContain
(
@
showSpies
.
$el
)
describe
"CMS.Views.ChapterEdit"
,
->
tpl
=
readFixtures
(
"chapter.underscore"
)
beforeEach
->
setFixtures
(
$
(
"<script>"
,
{
id
:
"new-chapter-tpl"
,
type
:
"text/template"
}).
text
(
tpl
))
appendSetFixtures
(
$
(
"<script>"
,
{
id
:
"system-feedback-tpl"
,
type
:
"text/template"
}).
text
(
feedbackTpl
))
@
model
=
new
CMS
.
Models
.
Chapter
name
:
"Chapter 1"
asset_path
:
"/ch1.pdf"
@
collection
=
new
CMS
.
Collections
.
ChapterSet
()
@
collection
.
add
(
@
model
)
@
view
=
new
CMS
.
Views
.
ChapterEdit
({
model
:
@
model
})
spyOn
(
@
view
,
"remove"
).
andCallThrough
()
window
.
UPLOAD_ASSET_CALLBACK_URL
=
"/upload"
window
.
section
=
new
CMS
.
Models
.
Section
({
name
:
"abcde"
})
afterEach
->
delete
window
.
UPLOAD_ASSET_CALLBACK_URL
delete
window
.
section
it
"can render"
,
->
@
view
.
render
()
expect
(
@
view
.
$
(
"input.chapter-name"
).
val
()).
toEqual
(
"Chapter 1"
)
expect
(
@
view
.
$
(
"input.chapter-asset-path"
).
val
()).
toEqual
(
"/ch1.pdf"
)
it
"can delete itself"
,
->
@
view
.
render
().
$
(
".action-close"
).
click
()
expect
(
@
collection
.
length
).
toEqual
(
0
)
expect
(
@
view
.
remove
).
toHaveBeenCalled
()
it
"can open an upload dialog"
,
->
uploadSpies
=
spyOnConstructor
(
CMS
.
Views
,
"UploadDialog"
,
[
"show"
,
"el"
])
uploadSpies
.
show
.
andReturn
(
uploadSpies
)
@
view
.
render
().
$
(
".action-upload"
).
click
()
ctorOptions
=
uploadSpies
.
constructor
.
mostRecentCall
.
args
[
0
]
expect
(
ctorOptions
.
model
.
get
(
'title'
)).
toMatch
(
/abcde/
)
expect
(
ctorOptions
.
chapter
).
toBe
(
@
model
)
expect
(
uploadSpies
.
show
).
toHaveBeenCalled
()
it
"saves content when opening upload dialog"
,
->
@
view
.
render
()
@
view
.
$
(
"input.chapter-name"
).
val
(
"rainbows"
)
@
view
.
$
(
"input.chapter-asset-path"
).
val
(
"unicorns"
)
@
view
.
$
(
".action-upload"
).
click
()
expect
(
@
model
.
get
(
"name"
)).
toEqual
(
"rainbows"
)
expect
(
@
model
.
get
(
"asset_path"
)).
toEqual
(
"unicorns"
)
describe
"CMS.Views.UploadDialog"
,
->
tpl
=
readFixtures
(
"upload-dialog.underscore"
)
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
()
...
...
cms/static/js/views/textbook.js
View file @
7b02932f
...
...
@@ -217,6 +217,10 @@ CMS.Views.ChapterEdit = Backbone.View.extend({
},
openUploadDialog
:
function
(
e
)
{
if
(
e
&&
e
.
preventDefault
)
{
e
.
preventDefault
();
}
this
.
model
.
set
({
name
:
this
.
$
(
"input.chapter-name"
).
val
(),
asset_path
:
this
.
$
(
"input.chapter-asset-path"
).
val
()
});
var
msg
=
new
CMS
.
Models
.
FileUpload
({
title
:
_
.
str
.
sprintf
(
gettext
(
"Upload a new asset to %s"
),
section
.
escape
(
'name'
)),
...
...
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