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
9ba62468
Commit
9ba62468
authored
Jul 06, 2012
by
Prem Sichanugrist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update Views.ModuleEdit, also added test
parent
dd3ddeb9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
88 additions
and
3 deletions
+88
-3
cms/static/coffee/spec/views/module_edit_spec.coffee
+81
-0
cms/static/coffee/src/views/module_edit.coffee
+7
-3
No files found.
cms/static/coffee/spec/views/module_edit_spec.coffee
0 → 100644
View file @
9ba62468
describe
"CMS.Views.ModuleEdit"
,
->
beforeEach
->
@
stubModule
=
jasmine
.
createSpyObj
(
"Module"
,
[
"editUrl"
,
"loadModule"
])
spyOn
(
$
.
fn
,
"load"
)
setFixtures
"""
<div id="module-edit">
<a href="#" class="save-update">save</a>
<a href="#" class="cancel">cancel</a>
<ol>
<li>
<a href="#" class="module-edit" data-id="i4x://mitx.edu/course/module" data-type="html">submodule</a>
</li>
</ol>
</div>
"""
CMS
.
unbind
()
describe
"defaults"
,
->
it
"set the correct tagName"
,
->
expect
(
new
CMS
.
Views
.
ModuleEdit
(
model
:
@
stubModule
).
tagName
).
toEqual
(
"section"
)
it
"set the correct className"
,
->
expect
(
new
CMS
.
Views
.
ModuleEdit
(
model
:
@
stubModule
).
className
).
toEqual
(
"edit-pane"
)
describe
"view creation"
,
->
beforeEach
->
@
stubModule
.
editUrl
.
andReturn
(
"/edit_item?id=stub_module"
)
new
CMS
.
Views
.
ModuleEdit
(
el
:
$
(
"#module-edit"
),
model
:
@
stubModule
)
it
"load the edit from via ajax and pass to the model"
,
->
expect
(
$
.
fn
.
load
).
toHaveBeenCalledWith
(
"/edit_item?id=stub_module"
,
jasmine
.
any
(
Function
))
if
$
.
fn
.
load
.
mostRecentCall
$
.
fn
.
load
.
mostRecentCall
.
args
[
1
]()
expect
(
@
stubModule
.
loadModule
).
toHaveBeenCalledWith
(
$
(
"#module-edit"
).
get
(
0
))
describe
"save"
,
->
beforeEach
->
@
stubJqXHR
=
jasmine
.
createSpy
(
"stubJqXHR"
)
@
stubJqXHR
.
success
=
jasmine
.
createSpy
(
"stubJqXHR.success"
).
andReturn
(
@
stubJqXHR
)
@
stubJqXHR
.
error
=
jasmine
.
createSpy
(
"stubJqXHR.success"
).
andReturn
(
@
stubJqXHR
)
@
stubModule
.
save
=
jasmine
.
createSpy
(
"stubModule.save"
).
andReturn
(
@
stubJqXHR
)
new
CMS
.
Views
.
ModuleEdit
(
el
:
$
(
"#module-edit"
),
model
:
@
stubModule
)
spyOn
(
window
,
"alert"
)
$
(
".save-update"
).
click
()
it
"call save on the model"
,
->
expect
(
@
stubModule
.
save
).
toHaveBeenCalled
()
it
"alert user on success"
,
->
@
stubJqXHR
.
success
.
mostRecentCall
.
args
[
0
]()
expect
(
window
.
alert
).
toHaveBeenCalledWith
(
"Your changes have been saved."
)
it
"alert user on error"
,
->
@
stubJqXHR
.
error
.
mostRecentCall
.
args
[
0
]()
expect
(
window
.
alert
).
toHaveBeenCalledWith
(
"There was an error saving your changes. Please try again."
)
describe
"cancel"
,
->
beforeEach
->
spyOn
(
CMS
,
'popView'
)
@
view
=
new
CMS
.
Views
.
ModuleEdit
(
el
:
$
(
"#module-edit"
),
model
:
@
stubModule
)
$
(
".cancel"
).
click
()
it
"pop current view from viewStack"
,
->
expect
(
CMS
.
popView
).
toHaveBeenCalled
()
describe
"editSubmodule"
,
->
beforeEach
->
@
view
=
new
CMS
.
Views
.
ModuleEdit
(
el
:
$
(
"#module-edit"
),
model
:
@
stubModule
)
spyOn
(
CMS
,
"pushView"
)
spyOn
(
CMS
.
Views
,
"ModuleEdit"
)
.
andReturn
(
@
view
=
jasmine
.
createSpy
(
"Views.ModuleEdit"
))
spyOn
(
CMS
.
Models
,
"Module"
)
.
andReturn
(
@
model
=
jasmine
.
createSpy
(
"Models.Module"
))
$
(
".module-edit"
).
click
()
it
"push another module editing view into viewStack"
,
->
expect
(
CMS
.
pushView
).
toHaveBeenCalledWith
@
view
expect
(
CMS
.
Views
.
ModuleEdit
).
toHaveBeenCalledWith
model
:
@
model
expect
(
CMS
.
Models
.
Module
).
toHaveBeenCalledWith
id
:
"i4x://mitx.edu/course/module"
type
:
"html"
cms/static/coffee/src/views/module_edit.coffee
View file @
9ba62468
...
...
@@ -13,10 +13,14 @@ class CMS.Views.ModuleEdit extends Backbone.View
save
:
(
event
)
->
event
.
preventDefault
()
@
model
.
save
().
success
->
console
.
log
"Saved"
@
model
.
save
().
success
(
->
alert
(
"Your changes have been saved."
)
).
error
(
->
alert
(
"There was an error saving your changes. Please try again."
)
)
cancel
:
->
cancel
:
(
event
)
->
event
.
preventDefault
()
CMS
.
popView
()
editSubmodule
:
(
event
)
->
...
...
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