Browse files

select and deselect specs for collections

  • Loading branch information...
1 parent cfd9f0f commit e3cf8ccb8ef44c4969eee5b4f58ca61d9ee56bad @derickbailey committed May 25, 2012
View
102 spec/javascripts/multiSelect.deselect.spec.js
@@ -0,0 +1,102 @@
+describe("multi-select collection deselecting", function(){
+ var Model = Backbone.Model.extend({
+ initialize: function(){
+ var selectable = new Backbone.Picky.Selectable();
+ _.extend(this, selectable);
+ }
+ });
+
+ var Collection = Backbone.Collection.extend({
+ model: Model,
+
+ initialize: function(){
+ var multiSelect = new Backbone.Picky.MultiSelect();
+ _.extend(this, multiSelect);
+ }
+ });
+
+ describe("when no models are selected, and deselecting all", function(){
+ var m1, m2, collection;
+
+ beforeEach(function(){
+ m1 = new Model();
+ m2 = new Model();
+
+ collection = new Collection([m1, m2]);
+ spyOn(collection, "trigger").andCallThrough();
+
+ collection.selectNone();
+ });
+
+ it("should trigger 'none' selected event", function(){
+ expect(collection.trigger).toHaveBeenCalledWith("select:none", collection);
+ });
+
+ it("should have a selected count of 0", function(){
+ expect(collection.selectedLength).toBe(0);
+ });
+
+ it("should have any models in the selected list", function(){
+ var size = _.size(collection.selected);
+ expect(size).toBe(0);
+ });
+ });
+
+ describe("when 1 model is selected, and deselecting all", function(){
+ var m1, m2, collection;
+
+ beforeEach(function(){
+ m1 = new Model();
+ m2 = new Model();
+
+ collection = new Collection([m1, m2]);
+ m1.select();
+
+ spyOn(collection, "trigger").andCallThrough();
+ collection.selectNone();
+ });
+
+ it("should trigger 'none' selected event", function(){
+ expect(collection.trigger).toHaveBeenCalledWith("select:none", collection);
+ });
+
+ it("should have a selected count of 0", function(){
+ expect(collection.selectedLength).toBe(0);
+ });
+
+ it("should have the first selected model in the selected list", function(){
+ var size = _.size(collection.selected);
+ expect(size).toBe(0);
+ });
+ });
+
+ describe("when all models are selected, and deselecting all", function(){
+ var m1, m2, collection;
+
+ beforeEach(function(){
+ m1 = new Model();
+ m2 = new Model();
+
+ collection = new Collection([m1, m2]);
+ m1.select();
+ m2.select();
+
+ spyOn(collection, "trigger").andCallThrough();
+ collection.selectNone();
+ });
+
+ it("should trigger 'none' selected event", function(){
+ expect(collection.trigger).toHaveBeenCalledWith("select:none", collection);
+ });
+
+ it("should have a selected count of 0", function(){
+ expect(collection.selectedLength).toBe(0);
+ });
+
+ it("should have the first selected model in the selected list", function(){
+ var size = _.size(collection.selected);
+ expect(size).toBe(0);
+ });
+ });
+
+});
View
111 spec/javascripts/multiSelect.select.spec.js
@@ -0,0 +1,111 @@
+describe("multi-select collection selecting", function(){
+ var Model = Backbone.Model.extend({
+ initialize: function(){
+ var selectable = new Backbone.Picky.Selectable();
+ _.extend(this, selectable);
+ }
+ });
+
+ var Collection = Backbone.Collection.extend({
+ model: Model,
+
+ initialize: function(){
+ var multiSelect = new Backbone.Picky.MultiSelect();
+ _.extend(this, multiSelect);
+ }
+ });
+
+ describe("when no models are selected, and selecting all", function(){
+ var m1, m2, collection;
+
+ beforeEach(function(){
+ m1 = new Model();
+ m2 = new Model();
+
+ collection = new Collection([m1, m2]);
+ spyOn(collection, "trigger").andCallThrough();
+
+ collection.selectAll();
+ });
+
+ it("should trigger 'all' selected event", function(){
+ expect(collection.trigger).toHaveBeenCalledWith("select:all", collection);
+ });
+
+ it("should have a selected count of 2", function(){
+ expect(collection.selectedLength).toBe(2);
+ });
+
+ it("should have the first selected model in the selected list", function(){
+ expect(collection.selected[m1.cid]).not.toBeUndefined();
+ });
+
+ it("should have the second selected model in the selected list", function(){
+ expect(collection.selected[m2.cid]).not.toBeUndefined();
+ });
+ });
+
+ describe("when 1 model is selected, and selecting all", function(){
+ var m1, m2, collection;
+
+ beforeEach(function(){
+ m1 = new Model();
+ m2 = new Model();
+
+ collection = new Collection([m1, m2]);
+ m1.select();
+
+ spyOn(collection, "trigger").andCallThrough();
+ collection.selectAll();
+ });
+
+ it("should trigger 'all' selected event", function(){
+ expect(collection.trigger).toHaveBeenCalledWith("select:all", collection);
+ });
+
+ it("should have a selected count of 2", function(){
+ expect(collection.selectedLength).toBe(2);
+ });
+
+ it("should have the first selected model in the selected list", function(){
+ expect(collection.selected[m1.cid]).not.toBeUndefined();
+ });
+
+ it("should have the second selected model in the selected list", function(){
+ expect(collection.selected[m2.cid]).not.toBeUndefined();
+ });
+ });
+
+ describe("when all models are selected, and selecting all", function(){
+ var m1, m2, collection;
+
+ beforeEach(function(){
+ m1 = new Model();
+ m2 = new Model();
+
+ collection = new Collection([m1, m2]);
+ m1.select();
+ m2.select();
+
+ spyOn(collection, "trigger").andCallThrough();
+ collection.selectAll();
+ });
+
+ it("should trigger 'all' selected event", function(){
+ expect(collection.trigger).toHaveBeenCalledWith("select:all", collection);
+ });
+
+ it("should have a selected count of 2", function(){
+ expect(collection.selectedLength).toBe(2);
+ });
+
+ it("should have the first selected model in the selected list", function(){
+ expect(collection.selected[m1.cid]).not.toBeUndefined();
+ });
+
+ it("should have the second selected model in the selected list", function(){
+ expect(collection.selected[m2.cid]).not.toBeUndefined();
+ });
+ });
+
+});
View
2 spec/javascripts/multiSelect.spec.js → ...ultiSelect.selectable.interaction.spec.js
@@ -1,4 +1,4 @@
-describe("multi-select collection", function(){
+describe("multi-select selectable interaction", function(){
var Model = Backbone.Model.extend({
initialize: function(){
var selectable = new Backbone.Picky.Selectable();

0 comments on commit e3cf8cc

Please sign in to comment.