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
2b01273f
Commit
2b01273f
authored
May 15, 2013
by
David Baumgold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added some Jasmine tests for section views in Backbone
parent
90a9c386
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
84 additions
and
4 deletions
+84
-4
cms/static/coffee/fixtures/section-name-edit.underscore
+2
-0
cms/static/coffee/spec/views/feedback_spec.coffee
+2
-3
cms/static/coffee/spec/views/section_spec.coffee
+79
-0
cms/static/js/views/section.js
+1
-1
No files found.
cms/static/coffee/fixtures/section-name-edit.underscore
0 → 120000
View file @
2b01273f
../../../templates/js/section-name-edit.underscore
\ No newline at end of file
cms/static/coffee/spec/views/feedback_spec.coffee
View file @
2b01273f
...
...
@@ -20,9 +20,8 @@ describe "CMS.Views.Alert as base class", ->
view
=
new
CMS
.
Views
.
Alert
({
model
:
@
model
})
expect
(
view
.
$
(
".action-close"
)).
toBeDefined
()
expect
(
view
.
$
(
'.wrapper'
)).
toHaveClass
(
"is-shown"
)
text
=
view
.
$el
.
text
()
expect
(
text
).
toMatch
(
/Portal/
)
expect
(
text
).
toMatch
(
/Aperture Science/
)
expect
(
view
.
$el
).
toContainText
(
@
model
.
get
(
"title"
))
expect
(
view
.
$el
).
toContainText
(
@
model
.
get
(
"message"
))
it
"close button sends a .hide() message"
,
->
spyOn
(
CMS
.
Views
.
Alert
.
prototype
,
'hide'
).
andCallThrough
()
...
...
cms/static/coffee/spec/views/section_spec.coffee
0 → 100644
View file @
2b01273f
describe
"CMS.Views.SectionShow"
,
->
describe
"Basic"
,
->
beforeEach
->
spyOn
(
CMS
.
Views
.
SectionShow
.
prototype
,
"switchToEditView"
)
.
andCallThrough
()
@
model
=
new
CMS
.
Models
.
Section
({
id
:
42
name
:
"Life, the Universe, and Everything"
})
@
view
=
new
CMS
.
Views
.
SectionShow
({
model
:
@
model
})
@
view
.
render
()
it
"should contain the model name"
,
->
expect
(
@
view
.
$el
).
toHaveText
(
@
model
.
get
(
'name'
))
it
"should call switchToEditView when clicked"
,
->
@
view
.
$el
.
click
()
expect
(
@
view
.
switchToEditView
).
toHaveBeenCalled
()
it
"should pass the same element to SectionEdit when switching views"
,
->
spyOn
(
CMS
.
Views
.
SectionEdit
.
prototype
,
'initialize'
).
andCallThrough
()
@
view
.
switchToEditView
()
expect
(
CMS
.
Views
.
SectionEdit
.
prototype
.
initialize
).
toHaveBeenCalled
()
expect
(
CMS
.
Views
.
SectionEdit
.
prototype
.
initialize
.
mostRecentCall
.
args
[
0
].
el
).
toEqual
(
@
view
.
el
)
describe
"CMS.Views.SectionEdit"
,
->
describe
"Basic"
,
->
tpl
=
readFixtures
(
'section-name-edit.underscore'
)
beforeEach
->
setFixtures
(
$
(
"<script>"
,
{
id
:
"section-name-edit-tpl"
,
type
:
"text/template"
}).
text
(
tpl
))
spyOn
(
CMS
.
Views
.
SectionEdit
.
prototype
,
"switchToShowView"
)
.
andCallThrough
()
spyOn
(
CMS
.
Views
.
SectionEdit
.
prototype
,
"showErrorMessage"
)
.
andCallThrough
()
window
.
analytics
=
jasmine
.
createSpyObj
(
'analytics'
,
[
'track'
])
window
.
course_location_analytics
=
jasmine
.
createSpy
()
@
requests
=
requests
=
[]
@
xhr
=
sinon
.
useFakeXMLHttpRequest
()
@
xhr
.
onCreate
=
(
xhr
)
->
requests
.
push
(
xhr
)
@
model
=
new
CMS
.
Models
.
Section
({
id
:
42
name
:
"Life, the Universe, and Everything"
})
@
view
=
new
CMS
.
Views
.
SectionEdit
({
model
:
@
model
})
@
view
.
render
()
afterEach
->
@
xhr
.
restore
()
delete
window
.
analytics
delete
window
.
course_location_analytics
it
"should have the model name as the default text value"
,
->
expect
(
@
view
.
$
(
"input[type=text]"
).
val
()).
toEqual
(
@
model
.
get
(
'name'
))
it
"should call switchToShowView when cancel button is clicked"
,
->
@
view
.
$
(
"input.cancel-button"
).
click
()
expect
(
@
view
.
switchToShowView
).
toHaveBeenCalled
()
it
"should save model when save button is clicked"
,
->
spyOn
(
@
model
,
'save'
)
@
view
.
$
(
"input[type=submit]"
).
click
()
expect
(
@
model
.
save
).
toHaveBeenCalled
()
it
"should call switchToShowView when save() is successful"
,
->
@
view
.
$
(
"input[type=submit]"
).
click
()
@
requests
[
0
].
respond
(
200
)
expect
(
@
view
.
switchToShowView
).
toHaveBeenCalled
()
it
"should call showErrorMessage when save() is unsuccessful"
,
->
@
view
.
$
(
"input[type=submit]"
).
click
()
@
requests
[
0
].
respond
(
500
)
expect
(
@
view
.
showErrorMessage
).
toHaveBeenCalled
()
expect
(
@
view
.
switchToShowView
).
not
.
toHaveBeenCalled
()
cms/static/js/views/section.js
View file @
2b01273f
...
...
@@ -19,13 +19,13 @@ CMS.Views.SectionShow = Backbone.View.extend({
});
CMS
.
Views
.
SectionEdit
=
Backbone
.
View
.
extend
({
template
:
_
.
template
(
$
(
"#section-name-edit-tpl"
).
text
()),
render
:
function
()
{
this
.
$el
.
html
(
this
.
template
(
this
.
model
.
attributes
));
this
.
delegateEvents
();
return
this
;
},
initialize
:
function
()
{
this
.
template
=
_
.
template
(
$
(
"#section-name-edit-tpl"
).
text
());
this
.
listenTo
(
this
.
model
,
"invalid"
,
this
.
showErrorMessage
);
this
.
render
();
},
...
...
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