recordset.html revision 3f7177697b39b256b1f047c972d4d7cbf161b82c
2N/A ARRAYASSERT = Y.ArrayAssert,
2N/A BTNRUN.set("disabled", false);
2N/A var testBasic = new Y.Test.Case({
delete this.rs;
this.rs.on('change', function() {
this.rs.on('empty', function() {
Y.Assert.isTrue(flag);
myRecordset = new Y.Recordset({records: data});
console.log(myRecordset);
var rs = new Y.Recordset(),
rs.on('remove', function(e) {
rem = e.removed;
rs.add({a:1, b:2, c:3});
rs.add([{a:'hey', b:'yo', c:'hi!'}, {a:2, b:5, c:6}]);
rs.remove(2);
Y.ObjectAssert.areEqual(rem[0].getValue(), {a:2, b:5, c:6});
//this.rs.get('records');
// var newrs = new Y.Recordset({records: [{a:10,b:10,c:10}]});
// newrs.get('records');
newRecord1 = this.rs.getRecordByIndex(1);
newRecord2 = this.rs.getRecord(1);
Y.ObjectAssert.areEqual(newRecord1, newRecord2);
newRecord = this.rs.getRecordsByIndex(1,2);
id = this.rs.getRecordByIndex(0).get('id');
newRecord = this.rs.getRecord(id);
retval = this.rs.add(recToAdd);
//This is indirectly checking to make sure that the record that got added has the identical data as the object literal that was passed in.
this.changeTest(3);
retval = this.rs.add(recToAdd,i);
this.changeTest(i);
retval = this.rs.add(recsToAdd);
this.changeTest(3);
retval = this.rs.add(recsToAdd, i);
this.changeTest(i);
this.rs.on('remove', function(e) {
this.changeTest(2);
this.changeTest(1);
this.rs.on('remove', function(e) {
this.rs.remove(1);
this.rs.on('remove', function(e) {
this.changeTest(1);
this.rs.remove(1,2);
this.emptyTest(0);
retval = this.rs.getValuesByKey(key);
Y.Assert.isUndefined(retval[i]);
newRecord = new Y.Record({data:o});
oldRecord = this.rs.getRecordByIndex(index);
this.rs.on('update', function(e) {
this.rs.update(newRecord, index);
oldRecord = this.rs.getRecordsByIndex(index,2);
a = new Y.Record({data:{a:'newA', b:'newB', c:'newC'}});
b = new Y.Record({data:{a:'newD', b:'newE', c:'newF'}});
newRecords.push(a);
newRecords.push(b);
this.rs.on('update', function(e) {
this.rs.update(newRecords, index);
var hashTable = this.rs.get('table');
Y.ObjectAssert.areEqual(hashTable[this.rs.getRecordByIndex(0).get('id')], this.rs.getRecordByIndex(0));
Y.ObjectAssert.areEqual(hashTable[this.rs.getRecordByIndex(1).get('id')], this.rs.getRecordByIndex(1));
Y.ObjectAssert.areEqual(hashTable[this.rs.getRecordByIndex(2).get('id')], this.rs.getRecordByIndex(2));
this.rs.add({a:'hello', b:'hey', c:'yo!'});
Y.ObjectAssert.areEqual(hashTable[this.rs.getRecordByIndex(0).get('id')], this.rs.getRecordByIndex(0));
Y.ObjectAssert.areEqual(hashTable[this.rs.getRecordByIndex(1).get('id')], this.rs.getRecordByIndex(1));
Y.ObjectAssert.areEqual(hashTable[this.rs.getRecordByIndex(2).get('id')], this.rs.getRecordByIndex(2));
Y.ObjectAssert.areEqual(hashTable[this.rs.getRecordByIndex(3).get('id')], this.rs.getRecordByIndex(3));
this.rs.remove(1);
Y.ObjectAssert.areEqual(hashTable[this.rs.getRecordByIndex(0).get('id')], this.rs.getRecordByIndex(0));
Y.ObjectAssert.areEqual(hashTable[this.rs.getRecordByIndex(1).get('id')], this.rs.getRecordByIndex(1));
Y.ObjectAssert.areEqual(hashTable[this.rs.getRecordByIndex(2).get('id')], this.rs.getRecordByIndex(2));
this.rs.remove(0,2);
Y.ObjectAssert.areEqual(hashTable[this.rs.getRecordByIndex(0).get('id')], this.rs.getRecordByIndex(0));
this.rs.update({a:'new', b:'record', c:'added'}, 0);
Y.ObjectAssert.areEqual(hashTable[this.rs.getRecordByIndex(0).get('id')], this.rs.getRecordByIndex(0));
Y.ObjectAssert.areEqual(hashTable[this.rs.getRecordByIndex(1).get('id')], this.rs.getRecordByIndex(1));
this.rs.update([{a:'new', b:'record', c:'added'},{a:'another', b:'new', c:'record'}], 1);
Y.ObjectAssert.areEqual(hashTable[this.rs.getRecordByIndex(0).get('id')], this.rs.getRecordByIndex(0));
Y.ObjectAssert.areEqual(hashTable[this.rs.getRecordByIndex(1).get('id')], this.rs.getRecordByIndex(1));
Y.ObjectAssert.areEqual(hashTable[this.rs.getRecordByIndex(2).get('id')], this.rs.getRecordByIndex(2));
//console.log(hashTable);
this.rs.sort.sort('a',false);
this.rs.sort.sort('c',true);
this.rs.sort.sort('b',true);
this.rs.sort.sort('a',false);
this.rs.add({a:6,b:5,c:8});
this.rs.add([d,c,b,a]);
this.rs.add([d,c,b,a]);
this.rs.sort.sort('a',true);
//This is just a copy of Y.ArraySort.compare
if(!Y.Lang.isValue(a)) {
if(!Y.Lang.isValue(b)) {
else if(!Y.Lang.isValue(b)) {
if(Y.Lang.isString(a)) {
if(Y.Lang.isString(b)) {
this.rs.add([a,b,c,d]);
this.rs.sort.sort('a',false,customsort);
this.rs.each(function() {
recs[i] = this.getValue();
Y.ObjectAssert.areEqual({a:3, b:2, c:1}, recs[0]);
Y.ObjectAssert.areEqual({a:9, b:8, c:7}, recs[1]);
Y.ObjectAssert.areEqual({a:1, b:2, c:3}, recs[2]);
this.rs.some(function() {
v = this.getValue();
if (v.a !== 1) {
Y.ObjectAssert.areEqual({a:3, b:2, c:1}, recs[0]);
Y.ObjectAssert.areEqual({a:9, b:8, c:7}, recs[1]);
if (item.getValue('b') === 2) {
rs = this.rs.filter.filter(validator);
if (item.getValue('c') === 2) {
rs = this.rs.filter.filter(validator);
rs = this.rs.filter.filter('b',2);
if (item.getValue('b') === 2) {
rs = this.rs.filter.reject(validator);
if (item.getValue('c') === 2) {
rs = this.rs.filter.reject(validator);
//Map is tested on the actual array because it returns an array of booleans typically (atleast that's the use case I can think of)
if (item.getValue('b') === 2) {
Y.Assert.areEqual(true, rs[0]);
Y.Assert.areEqual(false, rs[1]);
Y.Assert.areEqual(true, rs[2]);
var hashA = this.rs.indexer.createTable('a');
var hashTables = this.rs.indexer.get('hashTables');
Y.ObjectAssert.areEqual(hashA[3].getValue(), {a:3, b:2, c:1});
Y.ObjectAssert.areEqual(hashA[9].getValue(), {a:9, b:8, c:7});
Y.ObjectAssert.areEqual(hashA[1].getValue(), {a:1, b:2, c:3});
var hashB = this.rs.indexer.createTable('b');
Y.ObjectAssert.areEqual(hashB[2].getValue(), {a:1, b:2, c:3});
Y.ObjectAssert.areEqual(hashB[8].getValue(), {a:9, b:8, c:7});
var hashA = this.rs.indexer.createTable('a'),
hashC = this.rs.indexer.createTable('c'),
hashTables = this.rs.indexer.get('hashTables');
this.rs.add({a:'adding', b:'this', c:'record'});
Y.ObjectAssert.areEqual(hashA[3].getValue(), {a:3, b:2, c:1});
Y.ObjectAssert.areEqual(hashA[9].getValue(), {a:9, b:8, c:7});
Y.ObjectAssert.areEqual(hashA[1].getValue(), {a:1, b:2, c:3});
Y.ObjectAssert.areEqual(hashA['adding'].getValue(), {a:'adding', b:'this', c:'record'});
Y.ObjectAssert.areEqual(hashC[1].getValue(), {a:3, b:2, c:1});
Y.ObjectAssert.areEqual(hashC[7].getValue(), {a:9, b:8, c:7});
Y.ObjectAssert.areEqual(hashC[3].getValue(), {a:1, b:2, c:3});
Y.ObjectAssert.areEqual(hashC['record'].getValue(), {a:'adding', b:'this', c:'record'});
this.rs.add({a:'another', b:'new', c:'record'}, 0);
Y.ObjectAssert.areEqual(hashA[3].getValue(), {a:3, b:2, c:1});
Y.ObjectAssert.areEqual(hashA[9].getValue(), {a:9, b:8, c:7});
Y.ObjectAssert.areEqual(hashA[1].getValue(), {a:1, b:2, c:3});
Y.ObjectAssert.areEqual(hashA['adding'].getValue(), {a:'adding', b:'this', c:'record'});
Y.ObjectAssert.areEqual(hashA['another'].getValue(), {a:'another', b:'new', c:'record'});
Y.ObjectAssert.areEqual(hashC[1].getValue(), {a:3, b:2, c:1});
Y.ObjectAssert.areEqual(hashC[7].getValue(), {a:9, b:8, c:7});
Y.ObjectAssert.areEqual(hashC[3].getValue(), {a:1, b:2, c:3});
Y.ObjectAssert.areEqual(hashC['record'].getValue(), {a:'another', b:'new', c:'record'});
this.rs.add([{a:'blah', b:'bloo', c:'bleh'},{a:'heres', b:'another', c:'one'}]);
Y.ObjectAssert.areEqual(hashA[3].getValue(), {a:3, b:2, c:1});
Y.ObjectAssert.areEqual(hashA[9].getValue(), {a:9, b:8, c:7});
Y.ObjectAssert.areEqual(hashA[1].getValue(), {a:1, b:2, c:3});
Y.ObjectAssert.areEqual(hashA['adding'].getValue(), {a:'adding', b:'this', c:'record'});
Y.ObjectAssert.areEqual(hashA['another'].getValue(), {a:'another', b:'new', c:'record'});
Y.ObjectAssert.areEqual(hashA['blah'].getValue(), {a:'blah', b:'bloo', c:'bleh'});
Y.ObjectAssert.areEqual(hashA['heres'].getValue(), {a:'heres', b:'another', c:'one'});
Y.ObjectAssert.areEqual(hashC[1].getValue(), {a:3, b:2, c:1});
Y.ObjectAssert.areEqual(hashC[7].getValue(), {a:9, b:8, c:7});
Y.ObjectAssert.areEqual(hashC[3].getValue(), {a:1, b:2, c:3});
Y.ObjectAssert.areEqual(hashC['record'].getValue(), {a:'another', b:'new', c:'record'});
Y.ObjectAssert.areEqual(hashC['bleh'].getValue(), {a:'blah', b:'bloo', c:'bleh'});
Y.ObjectAssert.areEqual(hashC['one'].getValue(), {a:'heres', b:'another', c:'one'});
var hashA = this.rs.indexer.createTable('a'),
hashC = this.rs.indexer.createTable('c'),
hashTables = this.rs.indexer.get('hashTables');
this.rs.remove(2);
Y.ObjectAssert.areEqual(hashA[3].getValue(), {a:3, b:2, c:1});
Y.ObjectAssert.areEqual(hashA[9].getValue(), {a:9, b:8, c:7});
Y.ObjectAssert.areEqual(hashC[1].getValue(), {a:3, b:2, c:1});
Y.ObjectAssert.areEqual(hashC[7].getValue(), {a:9, b:8, c:7});
this.rs.add({a:1, b:2, c:3});
this.rs.remove(0,2);
Y.ObjectAssert.areEqual(hashA[1].getValue(), {a:1, b:2, c:3});
Y.ObjectAssert.areEqual(hashC[3].getValue(), {a:1, b:2, c:3});
var hashA = this.rs.indexer.createTable('a'),
hashC = this.rs.indexer.createTable('c'),
hashTables = this.rs.indexer.get('hashTables');
this.rs.update({a:'one', b:'record', c:'added'}, 1);
Y.ObjectAssert.areEqual(hashA[3].getValue(), {a:3, b:2, c:1});
Y.ObjectAssert.areEqual(hashA[1].getValue(), {a:1, b:2, c:3});
Y.ObjectAssert.areEqual(hashA['one'].getValue(), {a:'one', b:'record', c:'added'});
Y.ObjectAssert.areEqual(hashC[1].getValue(), {a:3, b:2, c:1});
Y.ObjectAssert.areEqual(hashC[3].getValue(), {a:1, b:2, c:3});
Y.ObjectAssert.areEqual(hashC['added'].getValue(), {a:'one', b:'record', c:'added'});
this.rs.update([{a:'adding', b:'this', c:'record'}, {a:'heres', b:'another', c:'one'}], 2);
Y.ObjectAssert.areEqual(hashA[3].getValue(), {a:3, b:2, c:1});
Y.ObjectAssert.areEqual(hashA['adding'].getValue(), {a:'adding', b:'this', c:'record'});
Y.ObjectAssert.areEqual(hashA['heres'].getValue(), {a:'heres', b:'another', c:'one'});
Y.ObjectAssert.areEqual(hashC[1].getValue(), {a:3, b:2, c:1});
Y.ObjectAssert.areEqual(hashC['record'].getValue(), {a:'adding', b:'this', c:'record'});
Y.ObjectAssert.areEqual(hashC['one'].getValue(), {a:'heres', b:'another', c:'one'});
var suite = new Y.Test.Suite({name:"Recordset Test Suite"});
suite.add(testBasic);
Y.Test.Runner.setName("Recordset Test Runner");
Y.Test.Runner.add(suite);