forked from emberjs/ember.js
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
197289a
commit dadcaaf
Showing
1 changed file
with
72 additions
and
0 deletions.
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
packages/ember-runtime/tests/system/array_proxy/length_test.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,72 @@ | ||
import ArrayProxy from 'ember-runtime/system/array_proxy'; | ||
import Object from 'ember-runtime/system/object'; | ||
import { observer } from 'ember-metal/mixin'; | ||
import { computed } from 'ember-metal/computed'; | ||
import { A as a } from 'ember-runtime/system/native_array'; | ||
|
||
QUnit.module('Ember.ArrayProxy - content change (length)'); | ||
|
||
QUnit.test('asdfasdf', function() { | ||
var aCalled, bCalled, cCalled, dCalled, eCalled; | ||
|
||
aCalled = bCalled = cCalled = dCalled = eCalled = 0; | ||
|
||
var obj = Object.extend({ | ||
colors: computed.reads('model'), | ||
length: computed.reads('colors.length'), | ||
|
||
a: observer('length', function() { | ||
aCalled++; | ||
}), | ||
|
||
b: observer('colors.length', function() { | ||
bCalled++; | ||
}), | ||
|
||
c: observer('colors.content.length', function() { | ||
cCalled++; | ||
}), | ||
|
||
d: observer('colors.[]', function() { | ||
dCalled++; | ||
}), | ||
|
||
e: observer('colors.content.[]', function() { | ||
eCalled++; | ||
}) | ||
}).create(); | ||
|
||
obj.set('model', ArrayProxy.create({ | ||
content: a([ | ||
'red', | ||
'yellow', | ||
'blue' | ||
]) | ||
}) | ||
); | ||
|
||
equal(obj.get('colors.content.length'), 3); | ||
equal(obj.get('colors.length'), 3); | ||
equal(obj.get('length'), 3); | ||
|
||
equal(aCalled, 1, 'expected observer `length` to be called ONCE'); | ||
equal(bCalled, 1, 'expected observer `colors.length` to be called ONCE'); | ||
equal(cCalled, 1, 'expected observer `colors.content.length` to be called ONCE'); | ||
equal(dCalled, 1, 'expected observer `colors.[]` to be called ONCE'); | ||
equal(eCalled, 1, 'expected observer `colors.content.[]` to be called ONCE'); | ||
|
||
obj.get('colors').pushObjects([ | ||
'green', | ||
'red' | ||
]); | ||
|
||
equal(obj.get('colors.content.length'), 5); | ||
equal(obj.get('colors.length'), 5); | ||
equal(obj.get('length'), 5); | ||
|
||
equal(aCalled, 2, 'expected observer `length` to be called TWICE'); | ||
equal(bCalled, 2, 'expected observer `colors.length` to be called TWICE'); | ||
equal(cCalled, 2, 'expected observer `colors.content.length` to be called TWICE'); | ||
equal(dCalled, 2, 'expected observer `colors.[]` to be called TWICE'); | ||
equal(eCalled, 2, 'expected observer `colors.content.[]` to be called TWICE'); | ||
}); |