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
27398a5c
Commit
27398a5c
authored
Jun 17, 2013
by
David Baumgold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added tests for CMS.Views.ListTextbooks
parent
8ba21ca3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
76 additions
and
0 deletions
+76
-0
cms/static/coffee/fixtures/no-textbooks.underscore
+2
-0
cms/static/coffee/spec/views/textbook_spec.coffee
+74
-0
No files found.
cms/static/coffee/fixtures/no-textbooks.underscore
0 → 120000
View file @
27398a5c
../../../templates/js/no-textbooks.underscore
\ No newline at end of file
cms/static/coffee/spec/views/textbook_spec.coffee
View file @
27398a5c
...
...
@@ -112,3 +112,77 @@ describe "CMS.Views.TextbookEdit", ->
expect
(
@
collection
.
save
).
not
.
toHaveBeenCalled
()
expect
(
@
collection
.
editing
).
toBeUndefined
()
describe
"CMS.Views.ListTextbooks"
,
->
noTextbooksTpl
=
readFixtures
(
"no-textbooks.underscore"
)
beforeEach
->
setFixtures
(
$
(
"<script>"
,
{
id
:
"no-textbooks-tpl"
,
type
:
"text/template"
}).
text
(
noTextbooksTpl
))
@
showSpies
=
spyOnConstructor
(
CMS
.
Views
,
"TextbookShow"
,
[
"render"
])
@
showSpies
.
render
.
andReturn
(
@
showSpies
)
# equivalent of `return this`
showEl
=
$
(
"<li>"
)
@
showSpies
.
$el
=
showEl
@
showSpies
.
el
=
showEl
.
get
(
0
)
@
editSpies
=
spyOnConstructor
(
CMS
.
Views
,
"TextbookEdit"
,
[
"render"
])
editEl
=
$
(
"<li>"
)
@
editSpies
.
render
.
andReturn
(
@
editSpies
)
@
editSpies
.
$el
=
editEl
@
editSpies
.
el
=
editEl
.
get
(
0
)
@
collection
=
new
CMS
.
Collections
.
TextbookSet
@
view
=
new
CMS
.
Views
.
ListTextbooks
({
collection
:
@
collection
})
@
view
.
render
()
@
showSpies
.
constructor
.
reset
()
@
editSpies
.
constructor
.
reset
()
it
"should render the empty template if there are no textbooks"
,
->
expect
(
@
view
.
$el
).
toContainText
(
"You haven't added any textbooks to this course yet"
)
expect
(
@
view
.
$el
).
toContain
(
".new-button"
)
it
"should render TextbookShow views by default if no textbook is being edited"
,
->
# add three empty textbooks to the collection
@
collection
.
add
([{},
{},
{}])
# reset spies due to re-rendering on collection modification
@
showSpies
.
constructor
.
reset
()
@
editSpies
.
constructor
.
reset
()
# render once and test
@
view
.
render
()
expect
(
@
view
.
$el
).
not
.
toContainText
(
"You haven't added any textbooks to this course yet"
)
expect
(
@
view
.
$el
).
toBe
(
"ul"
)
expect
(
@
showSpies
.
constructor
).
toHaveBeenCalled
()
expect
(
@
showSpies
.
constructor
.
calls
.
length
).
toEqual
(
3
);
expect
(
@
editSpies
.
constructor
).
not
.
toHaveBeenCalled
()
it
"should render a TextbookEdit view for a textbook being edited"
,
->
# add three empty textbooks to the collection
@
collection
.
add
([{},
{},
{}])
# mark the second one as being edited
editing
=
@
collection
.
at
(
1
)
@
collection
.
trigger
(
'editOne'
,
editing
)
# reset spies
@
showSpies
.
constructor
.
reset
()
@
editSpies
.
constructor
.
reset
()
# render once and test
@
view
.
render
()
expect
(
@
showSpies
.
constructor
).
toHaveBeenCalled
()
expect
(
@
showSpies
.
constructor
.
calls
.
length
).
toEqual
(
2
)
expect
(
@
showSpies
.
constructor
).
not
.
toHaveBeenCalledWith
({
model
:
editing
})
expect
(
@
editSpies
.
constructor
).
toHaveBeenCalled
()
expect
(
@
editSpies
.
constructor
.
calls
.
length
).
toEqual
(
1
)
expect
(
@
editSpies
.
constructor
).
toHaveBeenCalledWith
({
model
:
editing
})
it
"should add a new textbook when the new-button is clicked"
,
->
@
view
.
$
(
".new-button"
).
click
()
expect
(
@
collection
.
length
).
toEqual
(
1
)
expect
(
@
collection
.
editing
).
toBeDefined
()
editing
=
@
collection
.
editing
expect
(
editing
).
toEqual
(
@
collection
.
at
(
0
))
expect
(
@
editSpies
.
constructor
).
toHaveBeenCalledWith
({
model
:
editing
})
expect
(
@
view
.
$el
).
toContain
(
@
editSpies
.
$el
)
expect
(
@
view
.
$el
).
not
.
toContain
(
@
showSpies
.
$el
)
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