Skip to content

Commit

Permalink
Merge pull request #1 from Florian-R/bb-view-hooks
Browse files Browse the repository at this point in the history
Fix tests for Chaplin#780
  • Loading branch information
akre54 committed Jan 9, 2015
2 parents 49b8854 + a1c6c52 commit cf2ab90
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 28 deletions.
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
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

0 comments on commit cf2ab90

Please sign in to comment.