-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Posting this for style suggestions and notes. Trying to make it more ES6 and utilize block scope vs attaching everything to `this`. I’m also attempting to _not_ call
- Loading branch information
1 parent
614cdcc
commit 5603b0e
Showing
7 changed files
with
264 additions
and
0 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
test/unit/next-collection-view/collection-view-children.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Tests for the children container integration | ||
|
||
import _ from 'underscore'; | ||
import Backbone from 'backbone'; | ||
import CollectionView from '../../../src/next-collection-view'; | ||
|
||
describe('next CollectionView Children', function() { | ||
// init | ||
// render render:children | ||
//addChildView | ||
//detachChildView | ||
//removeChildView | ||
//destroy | ||
//add:child remove:child | ||
//child render / attach / detach / destroy | ||
//destroy destroy:children | ||
}); |
13 changes: 13 additions & 0 deletions
13
test/unit/next-collection-view/collection-view-data.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Anything related to Bb.collection events | ||
|
||
import _ from 'underscore'; | ||
import Backbone from 'backbone'; | ||
import CollectionView from '../../../src/next-collection-view'; | ||
|
||
describe('next CollectionView Data', function() { | ||
// render | ||
// collection update | ||
// collection sort | ||
// sortWithCollection | ||
// collection reset | ||
}); |
16 changes: 16 additions & 0 deletions
16
test/unit/next-collection-view/collection-view-empty.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Anything related to emptyView | ||
|
||
import _ from 'underscore'; | ||
import Backbone from 'backbone'; | ||
import CollectionView from '../../../src/next-collection-view'; | ||
|
||
describe('next CollectionView Empty', function() { | ||
// init region | ||
// showChildren | ||
// showEmpty | ||
// getEmpty | ||
// getEmptyViewOptions | ||
// renderChildren empty/filter | ||
// destroyEmpty | ||
// removeChild | ||
}); |
13 changes: 13 additions & 0 deletions
13
test/unit/next-collection-view/collection-view-filtering.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Anything viewFilter related | ||
|
||
import _ from 'underscore'; | ||
import Backbone from 'backbone'; | ||
import CollectionView from '../../../src/next-collection-view'; | ||
|
||
describe('next CollectionView Filtering', function() { | ||
// filter | ||
// setFilter | ||
// removeFilter | ||
// before:filter filter | ||
// empty | ||
}); |
12 changes: 12 additions & 0 deletions
12
test/unit/next-collection-view/collection-view-sorting.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Anything viewComparator related | ||
|
||
import _ from 'underscore'; | ||
import Backbone from 'backbone'; | ||
import CollectionView from '../../../src/next-collection-view'; | ||
|
||
describe('next CollectionView Sorting', function() { | ||
//sort | ||
//sortChildren | ||
// viewComparator | ||
// before:sort sort | ||
}); |
178 changes: 178 additions & 0 deletions
178
test/unit/next-collection-view/collection-view-viewmixin.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
// Anything testing the integration of the ViewMixin, but not the ViewMixin itself. | ||
|
||
import _ from 'underscore'; | ||
import Backbone from 'backbone'; | ||
import CollectionView from '../../../src/next-collection-view'; | ||
import View from '../../../src/view'; | ||
|
||
describe('next CollectionView ViewMixin', function() { | ||
|
||
describe('when initializing a CollectionView', function() { | ||
let collectionView; | ||
let initBehaviorsSpy; | ||
let initializeSpy; | ||
let delegateEntityEventsSpy; | ||
|
||
const mergeOptions = { | ||
behaviors: {}, | ||
childViewEventPrefix: 'child', | ||
childViewEvents: {}, | ||
childViewTriggers: {}, | ||
collectionEvents: {}, | ||
modelEvents: {}, | ||
triggers: {}, | ||
ui: {} | ||
}; | ||
|
||
beforeEach(function(){ | ||
const MyCollectionView = CollectionView.extend(); | ||
|
||
initBehaviorsSpy = this.sinon.spy(MyCollectionView.prototype, '_initBehaviors'); | ||
initializeSpy = this.sinon.spy(MyCollectionView.prototype, 'initialize'); | ||
delegateEntityEventsSpy = this.sinon.spy(MyCollectionView.prototype, 'delegateEntityEvents'); | ||
|
||
collectionView = new MyCollectionView(mergeOptions); | ||
}); | ||
|
||
_.each(mergeOptions, function(value, key) { | ||
it(`should merge ViewMixin option ${ key }`, function() { | ||
expect(collectionView[key]).to.equal(value); | ||
}); | ||
}); | ||
|
||
it('should call _initBehaviors', function() { | ||
expect(initBehaviorsSpy) | ||
.to.have.been.calledOnce | ||
.and.to.have.been.calledBefore(initializeSpy); | ||
}); | ||
|
||
it('should call delegateEntityEvents', function() { | ||
expect(delegateEntityEventsSpy) | ||
.to.have.been.calledOnce | ||
.and.to.have.been.calledAfter(initializeSpy); | ||
}); | ||
}); | ||
|
||
//_childViewEventHandler | ||
describe('when an event is triggered on a childView', function() { | ||
let collectionView; | ||
let handlerSpy; | ||
|
||
const eventArg = 'foo'; | ||
const dataArg = 'bar'; | ||
|
||
beforeEach(function() { | ||
const MyCollectionView = CollectionView.extend({ | ||
childView: View.extend({ template: false }) | ||
}); | ||
const collection = new Backbone.Collection([{}, {}]); | ||
|
||
collectionView = new MyCollectionView({ collection }); | ||
|
||
handlerSpy = this.sinon.spy(collectionView, '_childViewEventHandler'); | ||
|
||
collectionView.render(); | ||
}); | ||
|
||
it('should call _childViewEventHandler', function() { | ||
const childView = collectionView.children.findByIndex(0); | ||
|
||
handlerSpy.reset(); | ||
|
||
childView.triggerMethod(eventArg, dataArg); | ||
|
||
expect(handlerSpy) | ||
.to.be.calledOnce | ||
.and.to.be.calledWith(eventArg, dataArg); | ||
}); | ||
|
||
describe('when the childView is removed from the collectionView', function() { | ||
it('should not call _childViewEventHandler', function() { | ||
const childView = collectionView.children.findByIndex(0); | ||
|
||
collectionView.removeChildView(childView); | ||
|
||
handlerSpy.reset(); | ||
|
||
childView.triggerMethod(eventArg, dataArg); | ||
|
||
expect(handlerSpy).to.not.be.called; | ||
}); | ||
}); | ||
}); | ||
|
||
describe('#_getImmediateChildren', function() { | ||
let collectionView; | ||
|
||
describe('when empty', function() { | ||
beforeEach(function() { | ||
collectionView = new CollectionView(); | ||
}); | ||
|
||
it('should return an empty array for getImmediateChildren', function() { | ||
expect(collectionView._getImmediateChildren()) | ||
.to.be.instanceof(Array) | ||
.and.to.have.length(0); | ||
}); | ||
}); | ||
|
||
describe('when there are children', function() { | ||
let childOne; | ||
let childTwo; | ||
|
||
beforeEach(function() { | ||
collectionView = new CollectionView({ | ||
collection: new Backbone.Collection([{}, {}]), | ||
childView: View.extend({ template: false }) | ||
}); | ||
collectionView.render(); | ||
|
||
const children = collectionView.children; | ||
|
||
childOne = children.findByIndex(0); | ||
childTwo = children.findByIndex(1); | ||
}); | ||
|
||
it('should return an empty array for getImmediateChildren', function() { | ||
expect(collectionView._getImmediateChildren()) | ||
.to.be.instanceof(Array) | ||
.and.to.have.length(2) | ||
.and.to.contain(childOne) | ||
.and.to.contain(childTwo); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('#_removeChildren', function() { | ||
let collectionView; | ||
let childOne; | ||
let childTwo; | ||
|
||
beforeEach(function() { | ||
collectionView = new CollectionView({ | ||
collection: new Backbone.Collection([{}, {}]), | ||
childView: View.extend({ template: false }) | ||
}); | ||
collectionView.render(); | ||
|
||
const children = collectionView.children; | ||
|
||
childOne = children.findByIndex(0); | ||
childTwo = children.findByIndex(1); | ||
|
||
collectionView._removeChildren(); | ||
}); | ||
|
||
// Since the collectionView is destroyed we | ||
// don't need to worry about emptying the children | ||
it('should not empty the children', function() { | ||
|
||
expect(collectionView.children.length).to.equal(2); | ||
}); | ||
|
||
it('should have destroyed all of the children', function() { | ||
expect(childOne.isDestroyed()).to.be.true; | ||
expect(childTwo.isDestroyed()).to.be.true; | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Life-cycle and base functions | ||
|
||
import _ from 'underscore'; | ||
import Backbone from 'backbone'; | ||
import CollectionView from '../../../src/next-collection-view'; | ||
|
||
describe('next CollectionView', function() { | ||
//constructor | ||
//childView | ||
//childViewOptions | ||
//buildChildView | ||
//setElement | ||
//render | ||
//destroy | ||
}); |