Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

core multiselect tests

  • Loading branch information...
commit cfd9f0f5276204cded27c4100f3512800aaf6cfd 1 parent 9147c70
@derickbailey authored
Showing with 106 additions and 3 deletions.
  1. +0 −1  Gemfile
  2. +0 −2  Gemfile.lock
  3. +106 −0 spec/javascripts/multiSelect.spec.js
View
1  Gemfile
@@ -1,5 +1,4 @@
source :rubygems
gem "jasmine", "1.2.0"
-gem "fsevents"
gem "rb-fsevent"
View
2  Gemfile.lock
@@ -6,7 +6,6 @@ GEM
ffi (~> 1.0.6)
diff-lcs (1.1.3)
ffi (1.0.11)
- fsevents (0.1.1)
jasmine (1.2.0)
jasmine-core (>= 1.2.0)
rack (~> 1.0)
@@ -38,6 +37,5 @@ PLATFORMS
ruby
DEPENDENCIES
- fsevents
jasmine (= 1.2.0)
rb-fsevent
View
106 spec/javascripts/multiSelect.spec.js
@@ -0,0 +1,106 @@
+describe("multi-select collection", 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 1 out of 2 models in a collection is selected", function(){
+ var m1, m2, collection;
+
+ beforeEach(function(){
+ m1 = new Model();
+ m2 = new Model();
+
+ collection = new Collection([m1, m2]);
+ spyOn(collection, "trigger").andCallThrough();
+
+ m1.select();
+ });
+
+ it("should trigger 'some' selected event", function(){
+ expect(collection.trigger).toHaveBeenCalledWith("select:some", collection);
+ });
+
+ it("should have a selected count of 1", function(){
+ expect(collection.selectedLength).toBe(1);
+ });
+
+ it("should have the selected model in the selected list", function(){
+ expect(collection.selected[m1.cid]).not.toBeUndefined();
+ });
+
+ it("should not have the unselected model in the selected list", function(){
+ expect(collection.selected[m2.cid]).toBeUndefined();
+ });
+
+ });
+
+ describe("when 2 out of 2 models in a collection are selected", function(){
+ var m1, m2, collection;
+
+ beforeEach(function(){
+ m1 = new Model();
+ m2 = new Model();
+
+ collection = new Collection([m1, m2]);
+ spyOn(collection, "trigger").andCallThrough();
+
+ m1.select();
+ m2.select();
+ });
+
+ 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 a model is selected and then deselected", function(){
+ var m1, collection;
+
+ beforeEach(function(){
+ m1 = new Model();
+
+ collection = new Collection([m1]);
+ m1.select();
+ spyOn(collection, "trigger").andCallThrough();
+
+ m1.deselect();
+ });
+
+ 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 not have the model in the selected list", function(){
+ expect(collection.selected[m1.cid]).toBeUndefined();
+ });
+ });
+
+});
Please sign in to comment.
Something went wrong with that request. Please try again.