Sha256: 4682f831ea985fe410deb55ae8878f5a24461c06393ccc99ba59046105a012c7

Contents?: true

Size: 1.76 KB

Versions: 13

Compression:

Stored size: 1.76 KB

Contents

// ==========================================================================
// Project:   SproutCore - JavaScript Application Framework
// Copyright: ©2006-2010 Apple Inc. and contributors.
// License:   Licensed under MIT license (see license.js)
// ==========================================================================

/*global module test equals context ok same notest */

var source, indexes, observer, obj ; // base array to work with
module("SC.RangeObserver#create", {
  setup: function() {
    
    // create array with 5 SC.Object's in them
    source = [1,2,3,4,5].map(function(x) {
      return SC.Object.create({ item: x, foo: "bar" }) ;
    }, this); 

    indexes = SC.IndexSet.create(2,2); // select 2..3
    
    observer = SC.Object.create({
      
      callCount: 0, 
      
      rangeDidChange: function() { 
        this.callCount++;
      }
      
    });

    obj = SC.RangeObserver.create(source, indexes, observer, observer.rangeDidChange, "context", YES);
    
  }
});

test("returns new instance", function() {
  ok(obj && obj.isRangeObserver, 'returns range observer');
});

test("sets up observing on properties for each object in range in index if isDeep", function() {
  var len = source.length, idx;
  for(idx=0;idx<len;idx++) {
    source[idx].set('foo', 'baz');
  }
  equals(observer.callCount, 2, 'range observer should fire twice');
});

test("does not observe object properties if isDeep is NO", function() {
  // remove unneeded observer
  obj.destroy();
  
  // use new observer
  obj = SC.RangeObserver.create(source, indexes, observer, observer.rangeDidChange, "context", NO);
  
  var len = source.length, idx;
  for(idx=0;idx<len;idx++) {
    source[idx].set('foo', 'baz');
  }
  equals(observer.callCount, 0, 'range observer should not fire');
});

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
sproutcore-1.4.5 lib/frameworks/sproutcore/frameworks/runtime/tests/system/range_observer/create.js
sproutcore-1.4.5-java lib/frameworks/sproutcore/frameworks/runtime/tests/system/range_observer/create.js
sproutcore-1.4.4-java lib/frameworks/sproutcore/frameworks/runtime/tests/system/range_observer/create.js
sproutcore-1.4.4 lib/frameworks/sproutcore/frameworks/runtime/tests/system/range_observer/create.js
sproutcore-1.4.3.1 lib/frameworks/sproutcore/frameworks/runtime/tests/system/range_observer/create.js
sproutcore-1.4.3-java lib/frameworks/sproutcore/frameworks/runtime/tests/system/range_observer/create.js
sproutcore-1.4.3 lib/frameworks/sproutcore/frameworks/runtime/tests/system/range_observer/create.js
sproutcore-1.4.2-java lib/frameworks/sproutcore/frameworks/runtime/tests/system/range_observer/create.js
sproutcore-1.4.2 lib/frameworks/sproutcore/frameworks/runtime/tests/system/range_observer/create.js
sproutcore-1.4.1-java lib/frameworks/sproutcore/frameworks/runtime/tests/system/range_observer/create.js
sproutcore-1.4.1 lib/frameworks/sproutcore/frameworks/runtime/tests/system/range_observer/create.js
sproutcore-1.4.0-java lib/frameworks/sproutcore/frameworks/runtime/tests/system/range_observer/create.js
sproutcore-1.4.0 lib/frameworks/sproutcore/frameworks/runtime/tests/system/range_observer/create.js