Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tests for Chaplin#780 #1

Merged
merged 6 commits into from
Jan 9, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"sinon": "http://sinonjs.org/releases/sinon-1.7.1.js",
"requirejs": "~2.1.8",
"davy": "~0.0.4",
"Backbone.NativeView": "0.3.1",
"backbone.nativeview": "0.3.1",
"exoskeleton": "~0.7.0"
},
"exportsOverride": {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"grunt-istanbul": "0.2.x",
"grunt-urequire": "git://github.com/concordusapps/grunt-urequire",
"grunt-coffeelint": "0.0.x",
"grunt-mocha": "0.2.x",
"grunt-mocha": "0.4.11",
"grunt-transbrute": "~0.2.0",
"prompt": "0.2.x",
"phantomjs": "1.9.x"
Expand Down
11 changes: 3 additions & 8 deletions src/chaplin/views/collection_view.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,9 @@ Backbone = require 'backbone'
View = require 'chaplin/views/view'
utils = require 'chaplin/lib/utils'

filterChildren = (nodeList, selector) ->
return nodeList unless selector
for node in nodeList when Backbone.utils.matchesSelector node, selector
node

toggleElement = (elem, visible) ->
if Backbone.$
$(elem).toggle visible
Backbone.$(elem).toggle visible
else
elem.style.display = (if visible then '' else 'none')

Expand All @@ -24,7 +19,7 @@ startAnimation = (elem, useCssAnimation, cls) ->

endAnimation = (elem, duration) ->
if Backbone.$
elem.animate {opacity: 1}, duration
Backbone.$(elem).animate {opacity: 1}, duration
else
elem.style.transition = "opacity #{(duration / 1000)}s"
elem.opacity = 1
Expand All @@ -35,7 +30,7 @@ insertView = (list, viewEl, position, length, itemSelector) ->

if insertInMiddle or itemSelector
# Get the children which originate from item views.
children = filterChildren list.children, itemSelector
children = list.querySelectorAll(itemSelector)
childrenLength = children.length

# Check if it needs to be inserted.
Expand Down
18 changes: 0 additions & 18 deletions test/spec/collection_view_spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -412,51 +412,36 @@ define [

it 'should animate the opacity of new items', ->
return unless jQuery
$css = sinon.stub jQuery.prototype, 'css', -> this
$animate = sinon.stub jQuery.prototype, 'animate', -> this

createCollection()
collectionView = new AnimatingCollectionView {collection}

expect($css.callCount).to.be collection.length
expect($css).was.calledWith 'opacity', 0

expect($animate.callCount).to.be collection.length
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wastn't so sure about all these tests. It felt weird to just test that style.opacity was '0' on all childs views.

args = $animate.firstCall.args
expect(args[0]).to.eql opacity: 1
expect(args[1]).to.be collectionView.animationDuration

expect($css.calledBefore($animate)).to.be true

addThree()
expect($css.callCount).to.be collection.length

$css.restore()
$animate.restore()

it 'should not animate if animationDuration is 0', ->
return unless jQuery

$css = sinon.spy jQuery.prototype, 'css'
$animate = sinon.spy jQuery.prototype, 'animate'

createCollection()
collectionView = new TestCollectionView {collection}

expect($css).was.notCalled()
expect($animate).was.notCalled()

addThree()
expect($css).was.notCalled()
expect($animate).was.notCalled()

$css.restore()
$animate.restore()

it 'should not animate when re-inserting', ->
return unless jQuery

$css = sinon.stub jQuery.prototype, 'css', -> this
$animate = sinon.stub jQuery.prototype, 'animate', -> this

model1 = new Model id: 1
Expand All @@ -466,15 +451,12 @@ define [
createCollection [model1, model2]
collectionView = new AnimatingCollectionView {collection}

expect($css).was.calledTwice()
expect($animate).was.calledTwice()

collection.reset [model1, model2, model3]

expect($css.callCount).to.be collection.length
expect($animate.callCount).to.be collection.length

$css.restore()
$animate.restore()

it 'should animate with CSS classes', (done) ->
Expand Down