Skip to content

Instantly share code, notes, and snippets.

@jrolfs
Created March 3, 2014 18:47
Show Gist options
  • Save jrolfs/9331803 to your computer and use it in GitHub Desktop.
Save jrolfs/9331803 to your computer and use it in GitHub Desktop.
describe 'Mixins SortableCollectionView', ->
#
# Sample Classes
class ItemView extends Backbone.Marionette.ItemView
template: ''
itemViewContainer: '.item-view-container'
class SortableCollectionView extends Backbone.Marionette.CollectionView
@include Mavenlink.Mixins.Views.SortableCollectionView
itemView: ItemView
class SortableCompositeView extends Backbone.Marionette.CompositeView
@include Mavenlink.Mixins.Views.SortableCollectionView
itemView: ItemView
template: '''
<div class="item-view-container></div>"
'''
#
# Specs
view = null
viewClass = null
collection = new Backbone.Collection(
[
new Backbone.Model(id: 1)
new Backbone.Model(id: 2)
new Backbone.Model(id: 3)
new Backbone.Model(id: 5)
new Backbone.Model(id: 6)
]
comparator: null # TODO: Implement this as 'id' when testing actual sorts
)
initView = (Class = SortableCollectionView) ->
viewClass = Class
view = new Class(collection: collection)
showView = (Class = SortableCollectionView) ->
initView(Class)
view.render()
showCompositView = ->
showView(SortableCompositeView)
beforeEach ->
spyOn(Backbone.Marionette.Renderer, 'render').andCallFake (tmpl, data) ->
_.template(tmpl)(data)
describe '#appendHtml', ->
context 'in a Marionette CollectionView', ->
it 'should splice a view into the $el children when supplied an index before the last collection index', ->
showView()
model = new Backbone.Model(id: 4)
view.collection.add model, at: 3
expect(view.$el.children().get(3)).toBe(view.children.findByModel(model).el)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment