recordset.html revision 929e243ba6f296a952d264d18103a1dcce91e087
0N/A ARRAYASSERT = Y.ArrayAssert,
0N/A BTNRUN.set("disabled", false);
0N/A var testBasic = new Y.Test.Case({
0N/A this.rs.on('change', function() {
0N/A this.rs.on('empty', function() {
0N/A Y.Assert.isTrue(flag);
0N/A newRecord1 = this.rs.getRecordByIndex(1);
0N/A newRecord2 = this.rs.getRecord(1);
0N/A Y.ObjectAssert.areEqual(newRecord1, newRecord2);
0N/A newRecord = this.rs.getRecordsByIndex(1,2);
0N/A id = this.rs.getRecordByIndex(0).get('id');
0N/A newRecord = this.rs.getRecord(id);
0N/A retval = this.rs.add(recToAdd);
0N/A //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.
0N/A this.changeTest(3);
0N/A retval = this.rs.add(recToAdd,i);
0N/A this.changeTest(i);
0N/A retval = this.rs.add(recsToAdd);
0N/A this.changeTest(3);
0N/A retval = this.rs.add(recsToAdd, i);
0N/A this.changeTest(i);
0N/A this.rs.on('remove', function(e) {
0N/A this.changeTest(2);
0N/A this.changeTest(1);
0N/A this.rs.on('remove', function(e) {
0N/A this.rs.remove(1);
0N/A this.rs.on('remove', function(e) {
0N/A this.changeTest(1);
0N/A this.rs.remove(1,2);
0N/A this.emptyTest(0);
retval = this.rs.getValuesByKey(key);
Y.Assert.isUndefined(retval[i]);
newRecord = new Y.Record({data:{a:'newA', b:'newB', c:'newC'}});
oldRecord = this.rs.getRecordByIndex(index);
this.rs.on('update', function(e) {
Y.ObjectAssert.areEqual(oldRecord, e.data.overwritten[0], 'Overwritten record is != to old record');
this.rs.update(newRecord, index);
oldRecord = this.rs.getRecordByIndex(index);
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) {
Y.ObjectAssert.areEqual(oldRecord, e.data.overwritten[0], 'Overwritten record is != to old record');
this.rs.update(newRecords, index);
newRecord = new Y.Record({data: {a:'newG', b:'newH', c:'newI'}});
oldRecord = this.rs.getRecordByIndex(index);
this.rs.on('update', function(e) {
Y.ObjectAssert.areEqual(oldRecord, e.data.overwritten[0], 'Overwritten record is != to old record');
this.rs.update(newRecord, index, true);
oldRecords = this.rs.getRecordsByIndex(index,3);
//console.log(oldRecords);
a = new Y.Record({data:{a:'newA', b:'newB', c:'newC'}});
b = new Y.Record({data:{a:'newD', b:'newE', c:'newF'}});
c = new Y.Record({data:{a:'newG', b:'newH', c:'newI'}});
newRecords.push(a);
newRecords.push(b);
newRecords.push(c);
this.rs.on('update', function(e) {
//Y.ObjectAssert.areEqual(oldRecords[i].getValue(), e.data.overwritten[i].getValue(), 'Overwritten record is != to old record');
Y.ObjectAssert.areEqual(oData, e.data.updated[0].getValue(), 'Updated record != equal to new record');
Y.ObjectAssert.areEqual(oldRecord, e.data.overwritten[0], 'Overwritten record != equal to old record');
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);