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
5a06c692
Commit
5a06c692
authored
May 17, 2013
by
David Baumgold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add toBeShown and toBeHiding matchers for Jasmine
To reduce redundancy in tests
parent
af51d648
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
33 deletions
+24
-33
cms/static/coffee/spec/views/feedback_spec.coffee
+24
-33
No files found.
cms/static/coffee/spec/views/feedback_spec.coffee
View file @
5a06c692
beforeEach
->
@
addMatchers
toBeShown
:
->
@
actual
.
hasClass
(
"is-shown"
)
and
not
@
actual
.
hasClass
(
"is-hiding"
)
toBeHiding
:
->
@
actual
.
hasClass
(
"is-hiding"
)
and
not
@
actual
.
hasClass
(
"is-shown"
)
describe
"CMS.Views.Alert as base class"
,
->
describe
"CMS.Views.Alert as base class"
,
->
tpl
=
readFixtures
(
'alert.underscore'
)
tpl
=
readFixtures
(
'alert.underscore'
)
...
@@ -19,7 +26,7 @@ describe "CMS.Views.Alert as base class", ->
...
@@ -19,7 +26,7 @@ describe "CMS.Views.Alert as base class", ->
it
"renders the template"
,
->
it
"renders the template"
,
->
view
=
new
CMS
.
Views
.
Alert
({
model
:
@
model
})
view
=
new
CMS
.
Views
.
Alert
({
model
:
@
model
})
expect
(
view
.
$
(
".action-close"
)).
toBeDefined
()
expect
(
view
.
$
(
".action-close"
)).
toBeDefined
()
expect
(
view
.
$
(
'.wrapper'
)).
to
HaveClass
(
"is-shown"
)
expect
(
view
.
$
(
'.wrapper'
)).
to
BeShown
(
)
expect
(
view
.
$el
).
toContainText
(
@
model
.
get
(
"title"
))
expect
(
view
.
$el
).
toContainText
(
@
model
.
get
(
"title"
))
expect
(
view
.
$el
).
toContainText
(
@
model
.
get
(
"message"
))
expect
(
view
.
$el
).
toContainText
(
@
model
.
get
(
"message"
))
...
@@ -30,8 +37,7 @@ describe "CMS.Views.Alert as base class", ->
...
@@ -30,8 +37,7 @@ describe "CMS.Views.Alert as base class", ->
view
.
$
(
".action-close"
).
click
()
view
.
$
(
".action-close"
).
click
()
expect
(
CMS
.
Views
.
Alert
.
prototype
.
hide
).
toHaveBeenCalled
()
expect
(
CMS
.
Views
.
Alert
.
prototype
.
hide
).
toHaveBeenCalled
()
expect
(
view
.
$
(
'.wrapper'
)).
not
.
toHaveClass
(
"is-shown"
)
expect
(
view
.
$
(
'.wrapper'
)).
toBeHiding
()
expect
(
view
.
$
(
'.wrapper'
)).
toHaveClass
(
"is-hiding"
)
describe
"CMS.Views.Prompt"
,
->
describe
"CMS.Views.Prompt"
,
->
tpl
=
readFixtures
(
'prompt.underscore'
)
tpl
=
readFixtures
(
'prompt.underscore'
)
...
@@ -114,63 +120,52 @@ describe "CMS.Views.Notification minShown and maxShown", ->
...
@@ -114,63 +120,52 @@ describe "CMS.Views.Notification minShown and maxShown", ->
it
"a minShown view should not hide too quickly"
,
->
it
"a minShown view should not hide too quickly"
,
->
view
=
new
CMS
.
Views
.
Notification
({
model
:
@
model
,
minShown
:
1000
})
view
=
new
CMS
.
Views
.
Notification
({
model
:
@
model
,
minShown
:
1000
})
expect
(
CMS
.
Views
.
Notification
.
prototype
.
show
).
toHaveBeenCalled
()
expect
(
CMS
.
Views
.
Notification
.
prototype
.
show
).
toHaveBeenCalled
()
expect
(
view
.
$
(
'.wrapper'
)).
toHaveClass
(
"is-shown"
)
expect
(
view
.
$
(
'.wrapper'
)).
toBeShown
()
expect
(
view
.
$
(
'.wrapper'
)).
not
.
toHaveClass
(
"is-hiding"
)
# call hide() on it, but the minShown should prevent it from hiding right away
# call hide() on it, but the minShown should prevent it from hiding right away
view
.
hide
()
view
.
hide
()
expect
(
view
.
$
(
'.wrapper'
)).
toHaveClass
(
"is-shown"
)
expect
(
view
.
$
(
'.wrapper'
)).
toBeShown
()
expect
(
view
.
$
(
'.wrapper'
)).
not
.
toHaveClass
(
"is-hiding"
)
# wait for the minShown timeout to expire, and check again
# wait for the minShown timeout to expire, and check again
@
clock
.
tick
(
1001
)
@
clock
.
tick
(
1001
)
expect
(
view
.
$
(
'.wrapper'
)).
not
.
toHaveClass
(
"is-shown"
)
expect
(
view
.
$
(
'.wrapper'
)).
toBeHiding
()
expect
(
view
.
$
(
'.wrapper'
)).
toHaveClass
(
"is-hiding"
)
it
"a maxShown view should hide by itself"
,
->
it
"a maxShown view should hide by itself"
,
->
view
=
new
CMS
.
Views
.
Notification
({
model
:
@
model
,
maxShown
:
1000
})
view
=
new
CMS
.
Views
.
Notification
({
model
:
@
model
,
maxShown
:
1000
})
expect
(
CMS
.
Views
.
Notification
.
prototype
.
show
).
toHaveBeenCalled
()
expect
(
CMS
.
Views
.
Notification
.
prototype
.
show
).
toHaveBeenCalled
()
expect
(
view
.
$
(
'.wrapper'
)).
toHaveClass
(
"is-shown"
)
expect
(
view
.
$
(
'.wrapper'
)).
toBeShown
()
expect
(
view
.
$
(
'.wrapper'
)).
not
.
toHaveClass
(
"is-hiding"
)
# wait for the maxShown timeout to expire, and check again
# wait for the maxShown timeout to expire, and check again
@
clock
.
tick
(
1001
)
@
clock
.
tick
(
1001
)
expect
(
view
.
$
(
'.wrapper'
)).
not
.
toHaveClass
(
"is-shown"
)
expect
(
view
.
$
(
'.wrapper'
)).
toBeHiding
()
expect
(
view
.
$
(
'.wrapper'
)).
toHaveClass
(
"is-hiding"
)
it
"a minShown view can stay visible longer"
,
->
it
"a minShown view can stay visible longer"
,
->
view
=
new
CMS
.
Views
.
Notification
({
model
:
@
model
,
minShown
:
1000
})
view
=
new
CMS
.
Views
.
Notification
({
model
:
@
model
,
minShown
:
1000
})
expect
(
CMS
.
Views
.
Notification
.
prototype
.
show
).
toHaveBeenCalled
()
expect
(
CMS
.
Views
.
Notification
.
prototype
.
show
).
toHaveBeenCalled
()
expect
(
view
.
$
(
'.wrapper'
)).
toHaveClass
(
"is-shown"
)
expect
(
view
.
$
(
'.wrapper'
)).
toBeShown
()
expect
(
view
.
$
(
'.wrapper'
)).
not
.
toHaveClass
(
"is-hiding"
)
# wait for the minShown timeout to expire, and check again
# wait for the minShown timeout to expire, and check again
@
clock
.
tick
(
1001
)
@
clock
.
tick
(
1001
)
expect
(
CMS
.
Views
.
Notification
.
prototype
.
hide
).
not
.
toHaveBeenCalled
()
expect
(
CMS
.
Views
.
Notification
.
prototype
.
hide
).
not
.
toHaveBeenCalled
()
expect
(
view
.
$
(
'.wrapper'
)).
toHaveClass
(
"is-shown"
)
expect
(
view
.
$
(
'.wrapper'
)).
toBeShown
()
expect
(
view
.
$
(
'.wrapper'
)).
not
.
toHaveClass
(
"is-hiding"
)
# can now hide immediately
# can now hide immediately
view
.
hide
()
view
.
hide
()
expect
(
view
.
$
(
'.wrapper'
)).
not
.
toHaveClass
(
"is-shown"
)
expect
(
view
.
$
(
'.wrapper'
)).
toBeHiding
()
expect
(
view
.
$
(
'.wrapper'
)).
toHaveClass
(
"is-hiding"
)
it
"a maxShown view can hide early"
,
->
it
"a maxShown view can hide early"
,
->
view
=
new
CMS
.
Views
.
Notification
({
model
:
@
model
,
maxShown
:
1000
})
view
=
new
CMS
.
Views
.
Notification
({
model
:
@
model
,
maxShown
:
1000
})
expect
(
CMS
.
Views
.
Notification
.
prototype
.
show
).
toHaveBeenCalled
()
expect
(
CMS
.
Views
.
Notification
.
prototype
.
show
).
toHaveBeenCalled
()
expect
(
view
.
$
(
'.wrapper'
)).
toHaveClass
(
"is-shown"
)
expect
(
view
.
$
(
'.wrapper'
)).
toBeShown
()
expect
(
view
.
$
(
'.wrapper'
)).
not
.
toHaveClass
(
"is-hiding"
)
# wait 50 milliseconds, and hide it early
# wait 50 milliseconds, and hide it early
@
clock
.
tick
(
50
)
@
clock
.
tick
(
50
)
view
.
hide
()
view
.
hide
()
expect
(
view
.
$
(
'.wrapper'
)).
not
.
toHaveClass
(
"is-shown"
)
expect
(
view
.
$
(
'.wrapper'
)).
toBeHiding
()
expect
(
view
.
$
(
'.wrapper'
)).
toHaveClass
(
"is-hiding"
)
# wait for timeout to expire, make sure it doesn't do anything weird
# wait for timeout to expire, make sure it doesn't do anything weird
@
clock
.
tick
(
1000
)
@
clock
.
tick
(
1000
)
expect
(
view
.
$
(
'.wrapper'
)).
not
.
toHaveClass
(
"is-shown"
)
expect
(
view
.
$
(
'.wrapper'
)).
toBeHiding
()
expect
(
view
.
$
(
'.wrapper'
)).
toHaveClass
(
"is-hiding"
)
it
"a view can have both maxShown and minShown"
,
->
it
"a view can have both maxShown and minShown"
,
->
view
=
new
CMS
.
Views
.
Notification
({
model
:
@
model
,
minShown
:
1000
,
maxShown
:
2000
})
view
=
new
CMS
.
Views
.
Notification
({
model
:
@
model
,
minShown
:
1000
,
maxShown
:
2000
})
...
@@ -178,17 +173,13 @@ describe "CMS.Views.Notification minShown and maxShown", ->
...
@@ -178,17 +173,13 @@ describe "CMS.Views.Notification minShown and maxShown", ->
# can't hide early
# can't hide early
@
clock
.
tick
(
50
)
@
clock
.
tick
(
50
)
view
.
hide
()
view
.
hide
()
expect
(
view
.
$
(
'.wrapper'
)).
toHaveClass
(
"is-shown"
)
expect
(
view
.
$
(
'.wrapper'
)).
toBeShown
()
expect
(
view
.
$
(
'.wrapper'
)).
not
.
toHaveClass
(
"is-hiding"
)
@
clock
.
tick
(
1000
)
@
clock
.
tick
(
1000
)
expect
(
view
.
$
(
'.wrapper'
)).
not
.
toHaveClass
(
"is-shown"
)
expect
(
view
.
$
(
'.wrapper'
)).
toBeHiding
()
expect
(
view
.
$
(
'.wrapper'
)).
toHaveClass
(
"is-hiding"
)
# show it again, and let it hide automatically
# show it again, and let it hide automatically
view
.
show
()
view
.
show
()
@
clock
.
tick
(
1050
)
@
clock
.
tick
(
1050
)
expect
(
view
.
$
(
'.wrapper'
)).
toHaveClass
(
"is-shown"
)
expect
(
view
.
$
(
'.wrapper'
)).
toBeShown
()
expect
(
view
.
$
(
'.wrapper'
)).
not
.
toHaveClass
(
"is-hiding"
)
@
clock
.
tick
(
1000
)
@
clock
.
tick
(
1000
)
expect
(
view
.
$
(
'.wrapper'
)).
not
.
toHaveClass
(
"is-shown"
)
expect
(
view
.
$
(
'.wrapper'
)).
toBeHiding
()
expect
(
view
.
$
(
'.wrapper'
)).
toHaveClass
(
"is-hiding"
)
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