|
@@ -841,6 +841,50 @@ describe('Ember.computed macros', function () {
|
|
|
|
|
|
});
|
|
|
|
|
|
+ describe('#someByKey', function () {
|
|
|
+
|
|
|
+ beforeEach(function () {
|
|
|
+ App.setProperties({
|
|
|
+ someAnotherKey: 2
|
|
|
+ });
|
|
|
+ this.obj = Em.Object.create({
|
|
|
+ prop1: [{a: 1}, {a: 2}, {a: 3}],
|
|
|
+ prop2: Em.computed.someByKey('prop1', 'a', 'value1'),
|
|
|
+ prop3: Em.computed.someByKey('prop1', 'a', 'App.someRandomTestingKey'),
|
|
|
+ value1: 2
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ it('`true` if some collection item has needed property value', function () {
|
|
|
+ expect(this.obj.get('prop2')).to.be.true;
|
|
|
+ });
|
|
|
+
|
|
|
+ it('`false` if on one collection item doesn\'t have needed property value', function () {
|
|
|
+ this.obj.set('prop1.1.a', 3);
|
|
|
+ expect(this.obj.get('prop2')).to.be.false;
|
|
|
+ });
|
|
|
+
|
|
|
+ it('`false` for null/undefined collection', function () {
|
|
|
+ this.obj.set('prop1', null);
|
|
|
+ expect(this.obj.get('prop2')).to.be.false;
|
|
|
+ });
|
|
|
+
|
|
|
+ it('`prop2` has valid dependent keys', function () {
|
|
|
+ expect(Em.meta(this.obj).descs.prop2._dependentKeys).to.eql(['prop1.@each.a', 'value1']);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('`prop3` has valid dependent keys', function () {
|
|
|
+ expect(Em.meta(this.obj).descs.prop3._dependentKeys).to.eql(['prop1.@each.a', 'App.someRandomTestingKey']);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('`prop3` depends on App.* key', function () {
|
|
|
+ expect(this.obj.get('prop3')).to.be.true;
|
|
|
+ this.obj.set('prop1.1.a', 3);
|
|
|
+ expect(this.obj.get('prop3')).to.be.false;
|
|
|
+ });
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
describe('#everyBy', function () {
|
|
|
|
|
|
beforeEach(function () {
|
|
@@ -870,6 +914,49 @@ describe('Ember.computed macros', function () {
|
|
|
|
|
|
});
|
|
|
|
|
|
+ describe('#everyByKey', function () {
|
|
|
+ beforeEach(function () {
|
|
|
+ App.setProperties({
|
|
|
+ someAnotherKey: 2
|
|
|
+ });
|
|
|
+ this.obj = Em.Object.create({
|
|
|
+ prop1: [{a: 2}, {a: 2}, {a: 2}],
|
|
|
+ prop2: Em.computed.everyByKey('prop1', 'a', 'value1'),
|
|
|
+ prop3: Em.computed.everyByKey('prop1', 'a', 'App.someRandomTestingKey'),
|
|
|
+ value1: 2
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ it('`true` if all collection items have needed property value', function () {
|
|
|
+ expect(this.obj.get('prop2')).to.be.true;
|
|
|
+ });
|
|
|
+
|
|
|
+ it('`false` if at least one collection item doesn\'t have needed property value', function () {
|
|
|
+ this.obj.set('prop1.1.a', 3);
|
|
|
+ expect(this.obj.get('prop2')).to.be.false;
|
|
|
+ });
|
|
|
+
|
|
|
+ it('`false` for null/undefined collection', function () {
|
|
|
+ this.obj.set('prop1', null);
|
|
|
+ expect(this.obj.get('prop2')).to.be.false;
|
|
|
+ });
|
|
|
+
|
|
|
+ it('`prop2` has valid dependent keys', function () {
|
|
|
+ expect(Em.meta(this.obj).descs.prop2._dependentKeys).to.eql(['prop1.@each.a', 'value1']);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('`prop3` has valid dependent keys', function () {
|
|
|
+ expect(Em.meta(this.obj).descs.prop3._dependentKeys).to.eql(['prop1.@each.a', 'App.someRandomTestingKey']);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('`prop3` depends on App.* key', function () {
|
|
|
+ expect(this.obj.get('prop3')).to.be.true;
|
|
|
+ this.obj.set('prop1.1.a', 3);
|
|
|
+ expect(this.obj.get('prop3')).to.be.false;
|
|
|
+ });
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
describe('#mapBy', function () {
|
|
|
|
|
|
beforeEach(function () {
|
|
@@ -928,6 +1015,50 @@ describe('Ember.computed macros', function () {
|
|
|
|
|
|
});
|
|
|
|
|
|
+ describe('#filterByKey', function () {
|
|
|
+
|
|
|
+ beforeEach(function () {
|
|
|
+ App.setProperties({
|
|
|
+ someAnotherKey: 2
|
|
|
+ });
|
|
|
+ this.obj = Em.Object.create({
|
|
|
+ prop1: [{a: 2}, {a: 2}, {a: 3}],
|
|
|
+ prop2: Em.computed.filterByKey('prop1', 'a', 'value1'),
|
|
|
+ prop3: Em.computed.filterByKey('prop1', 'a', 'App.someRandomTestingKey'),
|
|
|
+ value1: 2
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ it('should filter dependent property', function () {
|
|
|
+ expect(this.obj.get('prop2')).to.eql([{a: 2}, {a: 2}]);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('should filter dependent property (2)', function () {
|
|
|
+ this.obj.get('prop1').pushObject({a: 2});
|
|
|
+ expect(this.obj.get('prop2')).to.eql([{a: 2}, {a: 2}, {a: 2}]);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('`[]` for null/undefined collection', function () {
|
|
|
+ this.obj.set('prop1', null);
|
|
|
+ expect(this.obj.get('prop2')).to.eql([]);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('`prop2` has valid dependent keys', function () {
|
|
|
+ expect(Em.meta(this.obj).descs.prop2._dependentKeys).to.eql(['prop1.@each.a', 'value1']);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('`prop3` has valid dependent keys', function () {
|
|
|
+ expect(Em.meta(this.obj).descs.prop3._dependentKeys).to.eql(['prop1.@each.a', 'App.someRandomTestingKey']);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('`prop3` depends on App.* key', function () {
|
|
|
+ expect(this.obj.get('prop3')).to.eql([{a: 2}, {a: 2}]);
|
|
|
+ this.obj.set('prop1.1.a', 3);
|
|
|
+ expect(this.obj.get('prop3')).to.eql([{a: 2}]);
|
|
|
+ });
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
describe('#findBy', function () {
|
|
|
|
|
|
beforeEach(function () {
|
|
@@ -957,6 +1088,50 @@ describe('Ember.computed macros', function () {
|
|
|
|
|
|
});
|
|
|
|
|
|
+ describe('#findByKey', function () {
|
|
|
+
|
|
|
+ beforeEach(function () {
|
|
|
+ App.setProperties({
|
|
|
+ someAnotherKey: 2
|
|
|
+ });
|
|
|
+ this.obj = Em.Object.create({
|
|
|
+ prop1: [{b: 1, a: 2}, {b: 2, a: 2}, {a: 3}],
|
|
|
+ prop2: Em.computed.findByKey('prop1', 'a', 'value1'),
|
|
|
+ prop3: Em.computed.findByKey('prop1', 'a', 'App.someRandomTestingKey'),
|
|
|
+ value1: 2
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ it('should filter dependent property', function () {
|
|
|
+ expect(this.obj.get('prop2')).to.eql({b:1, a: 2});
|
|
|
+ });
|
|
|
+
|
|
|
+ it('should filter dependent property (2)', function () {
|
|
|
+ this.obj.get('prop1').pushObject({b: 3, a: 2});
|
|
|
+ expect(this.obj.get('prop2')).to.eql({b: 1, a: 2});
|
|
|
+ });
|
|
|
+
|
|
|
+ it('`null` for null/undefined collection', function () {
|
|
|
+ this.obj.set('prop1', null);
|
|
|
+ expect(this.obj.get('prop2')).to.be.null;
|
|
|
+ });
|
|
|
+
|
|
|
+ it('`prop2` has valid dependent keys', function () {
|
|
|
+ expect(Em.meta(this.obj).descs.prop2._dependentKeys).to.eql(['prop1.@each.a', 'value1']);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('`prop3` has valid dependent keys', function () {
|
|
|
+ expect(Em.meta(this.obj).descs.prop3._dependentKeys).to.eql(['prop1.@each.a', 'App.someRandomTestingKey']);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('`prop3` depends on App.* key', function () {
|
|
|
+ expect(this.obj.get('prop3')).to.eql({b: 1, a: 2});
|
|
|
+ this.obj.get('prop1').pushObject({b: 3, a: 2});
|
|
|
+ expect(this.obj.get('prop3')).to.eql({b: 1, a: 2});
|
|
|
+ });
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
describe('#alias', function() {
|
|
|
|
|
|
beforeEach(function () {
|