062bd352b8466cb337cea7a9e2727fe82970582cJenny Donnelly<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
062bd352b8466cb337cea7a9e2727fe82970582cJenny Donnelly<html>
062bd352b8466cb337cea7a9e2727fe82970582cJenny Donnelly<head>
062bd352b8466cb337cea7a9e2727fe82970582cJenny Donnelly<title>Recordset Tests</title>
e939a4999f191c557c3cbfae767c2ab84260cebfTilo Mitra<script type="text/javascript" src="/build/yui/yui-min.js"></script>
062bd352b8466cb337cea7a9e2727fe82970582cJenny Donnelly</head>
062bd352b8466cb337cea7a9e2727fe82970582cJenny Donnelly
062bd352b8466cb337cea7a9e2727fe82970582cJenny Donnelly<body class="yui3-skin-sam">
062bd352b8466cb337cea7a9e2727fe82970582cJenny Donnelly<h1>Recordset Tests</h1>
062bd352b8466cb337cea7a9e2727fe82970582cJenny Donnelly<p><input type="button" value="Run Tests" id="btnRun" disabled=true></p>
062bd352b8466cb337cea7a9e2727fe82970582cJenny Donnelly
062bd352b8466cb337cea7a9e2727fe82970582cJenny Donnelly<script type="text/javascript">
062bd352b8466cb337cea7a9e2727fe82970582cJenny Donnelly(function() {
062bd352b8466cb337cea7a9e2727fe82970582cJenny Donnelly YUI({
c77d701a41f1b77424b988c2e63f2a8e6829c7e6Luke Smith filter: (window.location.search.match(/[?&]filter=([^&]+)/) || [])[1] || 'min',
c77d701a41f1b77424b988c2e63f2a8e6829c7e6Luke Smith allowRollup: false
aa98a71005a957b8f7ab7b119f9e9df62419b206Tilo Mitra }).use("console", "test", "dump", "recordset", function(Y) {
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra
062bd352b8466cb337cea7a9e2727fe82970582cJenny Donnelly // Set up the page
062bd352b8466cb337cea7a9e2727fe82970582cJenny Donnelly var ASSERT = Y.Assert,
062bd352b8466cb337cea7a9e2727fe82970582cJenny Donnelly ARRAYASSERT = Y.ArrayAssert,
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra BTNRUN = Y.one("#btnRun");
062bd352b8466cb337cea7a9e2727fe82970582cJenny Donnelly BTNRUN.set("disabled", false);
062bd352b8466cb337cea7a9e2727fe82970582cJenny Donnelly Y.on("click", function(e){
062bd352b8466cb337cea7a9e2727fe82970582cJenny Donnelly Y.Test.Runner.run();
062bd352b8466cb337cea7a9e2727fe82970582cJenny Donnelly }, BTNRUN);
062bd352b8466cb337cea7a9e2727fe82970582cJenny Donnelly var myConsole = new Y.Console().render();
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra
062bd352b8466cb337cea7a9e2727fe82970582cJenny Donnelly
062bd352b8466cb337cea7a9e2727fe82970582cJenny Donnelly var testBasic = new Y.Test.Case({
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra name: "API Tests",
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra initialData: [{a:3, b:2, c:1}, {a:9, b:8, c:7}, {a:1, b:2, c:3}],
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra //---------------------------------------------
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra // Setup and tear down
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra //---------------------------------------------
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra setUp : function () {
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra //create recordset
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra this.rs = new Y.Recordset({records:this.initialData});
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra //Some Ways to access recordset properties
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra //Y.log(rs.getRecordByIndex(0).getValue('a'));
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra //Y.log(rs.get('records').length);
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra },
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra tearDown : function () {
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra delete this.rs;
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra },
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra //---------------------------------------------
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra // Event Helpers
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra //---------------------------------------------
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra
df648c649330effe9ab7aeb7c339313f0da428c9Tilo Mitra changeTest: function(i) {
df648c649330effe9ab7aeb7c339313f0da428c9Tilo Mitra this.rs.on('change', function() {
5bf6831624d4a5676e761720f4f304f92e7550fbTilo Mitra //Y.Assert.areEqual(e.index, i);
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra });
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra },
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra
df648c649330effe9ab7aeb7c339313f0da428c9Tilo Mitra emptyTest: function() {
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra var flag = false;
df648c649330effe9ab7aeb7c339313f0da428c9Tilo Mitra this.rs.on('empty', function() {
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra flag = true;
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra Y.Assert.isTrue(flag);
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra });
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra },
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra //---------------------------------------------
072ee71c8a8aa16f3ad0f592fda5d41b45ba725aTilo Mitra // Instantiation
3bbab7db2010c87c1d3922da8362d206d73943c8Tilo Mitra //---------------------------------------------
3f7177697b39b256b1f047c972d4d7cbf161b82cTilo Mitra
3bbab7db2010c87c1d3922da8362d206d73943c8Tilo Mitra testCreateEmptyRecordset: function() {
072ee71c8a8aa16f3ad0f592fda5d41b45ba725aTilo Mitra var rs = new Y.Recordset(),
072ee71c8a8aa16f3ad0f592fda5d41b45ba725aTilo Mitra rem;
072ee71c8a8aa16f3ad0f592fda5d41b45ba725aTilo Mitra
072ee71c8a8aa16f3ad0f592fda5d41b45ba725aTilo Mitra rs.on('remove', function(e) {
072ee71c8a8aa16f3ad0f592fda5d41b45ba725aTilo Mitra rem = e.removed;
072ee71c8a8aa16f3ad0f592fda5d41b45ba725aTilo Mitra });
67073c302882de4baf70c80993d9120188400cd9Tilo Mitra
67073c302882de4baf70c80993d9120188400cd9Tilo Mitra //instantiate empty recordset
3bbab7db2010c87c1d3922da8362d206d73943c8Tilo Mitra Y.Assert.isTrue(rs instanceof Y.Recordset);
67073c302882de4baf70c80993d9120188400cd9Tilo Mitra
072ee71c8a8aa16f3ad0f592fda5d41b45ba725aTilo Mitra
67073c302882de4baf70c80993d9120188400cd9Tilo Mitra //perform operations on it
67073c302882de4baf70c80993d9120188400cd9Tilo Mitra rs.add({a:1, b:2, c:3});
67073c302882de4baf70c80993d9120188400cd9Tilo Mitra Y.ObjectAssert.areEqual(rs.getRecord(0).getValue(), {a:1, b:2, c:3});
67073c302882de4baf70c80993d9120188400cd9Tilo Mitra
67073c302882de4baf70c80993d9120188400cd9Tilo Mitra rs.add([{a:'hey', b:'yo', c:'hi!'}, {a:2, b:5, c:6}]);
67073c302882de4baf70c80993d9120188400cd9Tilo Mitra Y.ObjectAssert.areEqual(rs.getRecord(2).getValue(), {a:2, b:5, c:6});
67073c302882de4baf70c80993d9120188400cd9Tilo Mitra Y.Assert.areEqual(3, rs.getLength());
67073c302882de4baf70c80993d9120188400cd9Tilo Mitra
072ee71c8a8aa16f3ad0f592fda5d41b45ba725aTilo Mitra rs.remove(2);
67073c302882de4baf70c80993d9120188400cd9Tilo Mitra Y.Assert.areEqual(2, rs.getLength());
072ee71c8a8aa16f3ad0f592fda5d41b45ba725aTilo Mitra Y.ObjectAssert.areEqual(rem[0].getValue(), {a:2, b:5, c:6});
072ee71c8a8aa16f3ad0f592fda5d41b45ba725aTilo Mitra
3bbab7db2010c87c1d3922da8362d206d73943c8Tilo Mitra },
3bbab7db2010c87c1d3922da8362d206d73943c8Tilo Mitra
3bbab7db2010c87c1d3922da8362d206d73943c8Tilo Mitra //---------------------------------------------
3bbab7db2010c87c1d3922da8362d206d73943c8Tilo Mitra // Get Records
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra //---------------------------------------------
52104662d2bf71db0aa6dba39f7e6b3d1982f60bTilo Mitra
52104662d2bf71db0aa6dba39f7e6b3d1982f60bTilo Mitra testGetRecords: function() {
b41c27a66cb2271249d8117d3d5395ab17594f86Tilo Mitra var newRecord,newRecord1, newRecord2, id;
072ee71c8a8aa16f3ad0f592fda5d41b45ba725aTilo Mitra //this.rs.get('records');
072ee71c8a8aa16f3ad0f592fda5d41b45ba725aTilo Mitra // var newrs = new Y.Recordset({records: [{a:10,b:10,c:10}]});
072ee71c8a8aa16f3ad0f592fda5d41b45ba725aTilo Mitra // newrs.get('records');
072ee71c8a8aa16f3ad0f592fda5d41b45ba725aTilo Mitra
52104662d2bf71db0aa6dba39f7e6b3d1982f60bTilo Mitra //Single Record
b41c27a66cb2271249d8117d3d5395ab17594f86Tilo Mitra newRecord1 = this.rs.getRecordByIndex(1);
b41c27a66cb2271249d8117d3d5395ab17594f86Tilo Mitra newRecord2 = this.rs.getRecord(1);
b41c27a66cb2271249d8117d3d5395ab17594f86Tilo Mitra
b41c27a66cb2271249d8117d3d5395ab17594f86Tilo Mitra Y.ObjectAssert.areEqual(newRecord1.getValue(), this.initialData[1]);
b41c27a66cb2271249d8117d3d5395ab17594f86Tilo Mitra Y.ObjectAssert.areEqual(newRecord1, newRecord2);
b41c27a66cb2271249d8117d3d5395ab17594f86Tilo Mitra
52104662d2bf71db0aa6dba39f7e6b3d1982f60bTilo Mitra
52104662d2bf71db0aa6dba39f7e6b3d1982f60bTilo Mitra //Multiple Records
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra newRecord = this.rs.getRecordsByIndex(1,2);
405904c4430a9e537ac2ef07a33447e71611d249Tilo Mitra Y.ObjectAssert.areEqual(newRecord[0].getValue(), this.initialData[1]);
405904c4430a9e537ac2ef07a33447e71611d249Tilo Mitra Y.ObjectAssert.areEqual(newRecord[1].getValue(), this.initialData[2]);
52104662d2bf71db0aa6dba39f7e6b3d1982f60bTilo Mitra
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra //By ID
e81af05b77b6bb6ebfc812494de2d3a621272d90Tilo Mitra id = this.rs.getRecordByIndex(0).get('id');
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra newRecord = this.rs.getRecord(id);
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.ObjectAssert.areEqual(newRecord, this.rs.getRecordByIndex(0));
52104662d2bf71db0aa6dba39f7e6b3d1982f60bTilo Mitra },
52104662d2bf71db0aa6dba39f7e6b3d1982f60bTilo Mitra
52104662d2bf71db0aa6dba39f7e6b3d1982f60bTilo Mitra //---------------------------------------------
52104662d2bf71db0aa6dba39f7e6b3d1982f60bTilo Mitra // Add Records
52104662d2bf71db0aa6dba39f7e6b3d1982f60bTilo Mitra //---------------------------------------------
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra testAddSingleRecordToEnd: function() {
df648c649330effe9ab7aeb7c339313f0da428c9Tilo Mitra var recToAdd = {a:'8', b:'9', c:'10'}, retval;
6e68ea305b4b0d893038382499a7e0fe96478948Tilo Mitra retval = this.rs.add(recToAdd);
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra //Test Recordset Length
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra Y.Assert.areEqual(4, this.rs.get('records').length, "Array lengths not equal.");
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra //Assert on last object
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra //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.
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.ObjectAssert.areEqual(recToAdd, this.rs.getRecordByIndex(3).getValue());
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.ObjectAssert.areEqual(retval.getRecordByIndex(3).getValue(3), recToAdd);
df648c649330effe9ab7aeb7c339313f0da428c9Tilo Mitra this.changeTest(3);
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra },
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra testAddSingleRecordToIndex: function() {
405904c4430a9e537ac2ef07a33447e71611d249Tilo Mitra var recToAdd, i=2;
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra recToAdd = {a:'8', b:'9', c:'10'};
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra
6e68ea305b4b0d893038382499a7e0fe96478948Tilo Mitra retval = this.rs.add(recToAdd,i);
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.Assert.areEqual(recToAdd, this.rs.getRecordByIndex(i).getValue());
52104662d2bf71db0aa6dba39f7e6b3d1982f60bTilo Mitra
52104662d2bf71db0aa6dba39f7e6b3d1982f60bTilo Mitra //assertion with output
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.ObjectAssert.areEqual(retval.getRecordByIndex(i).getValue(), recToAdd);
52104662d2bf71db0aa6dba39f7e6b3d1982f60bTilo Mitra
df648c649330effe9ab7aeb7c339313f0da428c9Tilo Mitra this.changeTest(i);
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra },
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra testAddMultipleRecordsToEnd: function() {
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra var recsToAdd = [{a:'11', b:'22', c:'33'}, {a:'44', b:'55', c:'66'}];
6e68ea305b4b0d893038382499a7e0fe96478948Tilo Mitra retval = this.rs.add(recsToAdd);
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra //Assertions with recordset
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.ObjectAssert.areEqual(recsToAdd[0], this.rs.getRecordByIndex(3).getValue());
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.ObjectAssert.areEqual(recsToAdd[1], this.rs.getRecordByIndex(4).getValue());
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra
52104662d2bf71db0aa6dba39f7e6b3d1982f60bTilo Mitra //assertions with output
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.ObjectAssert.areEqual(retval.getRecordByIndex(3).getValue(), recsToAdd[0]);
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.ObjectAssert.areEqual(retval.getRecordByIndex(4).getValue(), recsToAdd[1]);
52104662d2bf71db0aa6dba39f7e6b3d1982f60bTilo Mitra
df648c649330effe9ab7aeb7c339313f0da428c9Tilo Mitra this.changeTest(3);
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra },
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra testAddMultipleRecordsToIndex: function() {
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra var recsToAdd, i;
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra recsToAdd = [{a:'11', b:'22', c:'33'}, {a:'44', b:'55', c:'66'}];
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra i = 1;
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra
6e68ea305b4b0d893038382499a7e0fe96478948Tilo Mitra retval = this.rs.add(recsToAdd, i);
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra //Assertions with recordset
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.ObjectAssert.areEqual(recsToAdd[0], this.rs.getRecordByIndex(1).getValue());
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.ObjectAssert.areEqual(recsToAdd[1], this.rs.getRecordByIndex(2).getValue());
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra
df648c649330effe9ab7aeb7c339313f0da428c9Tilo Mitra this.changeTest(i);
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra },
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra //---------------------------------------------
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra // Delete Records
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra //---------------------------------------------
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra testDeleteSingleRecordFromEnd: function() {
46c91c32e9f555734bdd918e4157fb8a92746ae0Tilo Mitra var rem;
46c91c32e9f555734bdd918e4157fb8a92746ae0Tilo Mitra this.rs.on('remove', function(e) {
46c91c32e9f555734bdd918e4157fb8a92746ae0Tilo Mitra rem = e;
46c91c32e9f555734bdd918e4157fb8a92746ae0Tilo Mitra })
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra
46c91c32e9f555734bdd918e4157fb8a92746ae0Tilo Mitra this.changeTest(2);
46c91c32e9f555734bdd918e4157fb8a92746ae0Tilo Mitra this.rs.remove();
46c91c32e9f555734bdd918e4157fb8a92746ae0Tilo Mitra Y.ObjectAssert.areEqual(this.initialData[2], rem.removed[0].getValue());
46c91c32e9f555734bdd918e4157fb8a92746ae0Tilo Mitra Y.Assert.areEqual(2, rem.index);
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra },
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra testDeleteSingleRecordFromIndex: function() {
df648c649330effe9ab7aeb7c339313f0da428c9Tilo Mitra this.changeTest(1);
46c91c32e9f555734bdd918e4157fb8a92746ae0Tilo Mitra var rem;
46c91c32e9f555734bdd918e4157fb8a92746ae0Tilo Mitra this.rs.on('remove', function(e) {
46c91c32e9f555734bdd918e4157fb8a92746ae0Tilo Mitra rem = e;
46c91c32e9f555734bdd918e4157fb8a92746ae0Tilo Mitra });
46c91c32e9f555734bdd918e4157fb8a92746ae0Tilo Mitra this.rs.remove(1);
46c91c32e9f555734bdd918e4157fb8a92746ae0Tilo Mitra Y.ObjectAssert.areEqual(this.initialData[1], rem.removed[0].getValue());
46c91c32e9f555734bdd918e4157fb8a92746ae0Tilo Mitra Y.Assert.areEqual(1, rem.index);
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra },
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra testDeleteRangeOfRecords: function() {
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra //Delete 2 records from index 1
46c91c32e9f555734bdd918e4157fb8a92746ae0Tilo Mitra var rem;
46c91c32e9f555734bdd918e4157fb8a92746ae0Tilo Mitra this.rs.on('remove', function(e) {
46c91c32e9f555734bdd918e4157fb8a92746ae0Tilo Mitra rem = e;
46c91c32e9f555734bdd918e4157fb8a92746ae0Tilo Mitra });
46c91c32e9f555734bdd918e4157fb8a92746ae0Tilo Mitra
df648c649330effe9ab7aeb7c339313f0da428c9Tilo Mitra this.changeTest(1);
46c91c32e9f555734bdd918e4157fb8a92746ae0Tilo Mitra this.rs.remove(1,2);
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra
46c91c32e9f555734bdd918e4157fb8a92746ae0Tilo Mitra Y.ObjectAssert.areEqual(this.initialData[1], rem.removed[0].getValue());
46c91c32e9f555734bdd918e4157fb8a92746ae0Tilo Mitra Y.ObjectAssert.areEqual(this.initialData[2], rem.removed[1].getValue());
46c91c32e9f555734bdd918e4157fb8a92746ae0Tilo Mitra Y.Assert.areEqual(1, rem.index);
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra },
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra //---------------------------------------------
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra // Empty Recordset
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra //---------------------------------------------
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra testEmptyRecordSet: function() {
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra
df648c649330effe9ab7aeb7c339313f0da428c9Tilo Mitra this.emptyTest(0);
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra this.rs.empty();
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra Y.Assert.areEqual(0, this.rs.get('records').length);
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra },
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra //---------------------------------------------
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra // GetValuesByKey
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra //---------------------------------------------
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra testGetValuesByKey: function() {
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra var key, retval, i;
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra key = 'a';
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra retval = this.rs.getValuesByKey(key);
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra for (i=0; i < this.initialData.length; i++) {
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra Y.Assert.areEqual(this.initialData[i][key], retval[i]);
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra }
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra },
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra testGetValuesByKeyWithInvalidKey: function() {
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra var key = 'd';
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra retval = this.rs.getValuesByKey(key);
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra for (i=0; i < this.initialData.length; i++) {
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra Y.Assert.isUndefined(retval[i]);
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra }
75659cb0e2deef88afd156725ab2726ee4f963a7Tilo Mitra },
5bf6831624d4a5676e761720f4f304f92e7550fbTilo Mitra
df648c649330effe9ab7aeb7c339313f0da428c9Tilo Mitra testUpdateRecordAtIndex: function() {
df648c649330effe9ab7aeb7c339313f0da428c9Tilo Mitra var newRecord, oldRecord, index=1;
68d857a0977716b866bdf530e6fa92d746df3579Tilo Mitra var o = {a:'newG', b:'newH', c:'newI'};
68d857a0977716b866bdf530e6fa92d746df3579Tilo Mitra newRecord = new Y.Record({data:o});
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra oldRecord = this.rs.getRecordByIndex(index);
df648c649330effe9ab7aeb7c339313f0da428c9Tilo Mitra
df648c649330effe9ab7aeb7c339313f0da428c9Tilo Mitra this.rs.on('update', function(e) {
f0b3da068a86e6d396175c502d04069b6afbc49cTilo Mitra Y.ObjectAssert.areEqual(newRecord, e.updated[0], 'Updated record is != to new record');
f0b3da068a86e6d396175c502d04069b6afbc49cTilo Mitra Y.ObjectAssert.areEqual(oldRecord, e.overwritten[0], 'Overwritten record is != to old record');
f0b3da068a86e6d396175c502d04069b6afbc49cTilo Mitra Y.Assert.areEqual(1, e.overwritten.length, 'overwritten array is not of expected length');
f0b3da068a86e6d396175c502d04069b6afbc49cTilo Mitra Y.Assert.areEqual(1, e.updated.length);
f0b3da068a86e6d396175c502d04069b6afbc49cTilo Mitra Y.Assert.areEqual(index, e.index, "correct index was modified");
df648c649330effe9ab7aeb7c339313f0da428c9Tilo Mitra });
df648c649330effe9ab7aeb7c339313f0da428c9Tilo Mitra
df648c649330effe9ab7aeb7c339313f0da428c9Tilo Mitra
df648c649330effe9ab7aeb7c339313f0da428c9Tilo Mitra this.rs.update(newRecord, index);
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.ObjectAssert.areEqual(newRecord.getValue(), this.rs.getRecordByIndex(index).getValue());
df648c649330effe9ab7aeb7c339313f0da428c9Tilo Mitra },
df648c649330effe9ab7aeb7c339313f0da428c9Tilo Mitra
df648c649330effe9ab7aeb7c339313f0da428c9Tilo Mitra testUpdateRecordAtIndices:function(){
df648c649330effe9ab7aeb7c339313f0da428c9Tilo Mitra var newRecords = [], index=0, oldRecord = [], a, b;
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra oldRecord = this.rs.getRecordsByIndex(index,2);
df648c649330effe9ab7aeb7c339313f0da428c9Tilo Mitra a = new Y.Record({data:{a:'newA', b:'newB', c:'newC'}});
df648c649330effe9ab7aeb7c339313f0da428c9Tilo Mitra b = new Y.Record({data:{a:'newD', b:'newE', c:'newF'}});
df648c649330effe9ab7aeb7c339313f0da428c9Tilo Mitra
df648c649330effe9ab7aeb7c339313f0da428c9Tilo Mitra newRecords.push(a);
df648c649330effe9ab7aeb7c339313f0da428c9Tilo Mitra newRecords.push(b);
df648c649330effe9ab7aeb7c339313f0da428c9Tilo Mitra
df648c649330effe9ab7aeb7c339313f0da428c9Tilo Mitra this.rs.on('update', function(e) {
46c91c32e9f555734bdd918e4157fb8a92746ae0Tilo Mitra Y.ObjectAssert.areEqual(newRecords, e.updated, 'Updated record is != to new record');
46c91c32e9f555734bdd918e4157fb8a92746ae0Tilo Mitra Y.ObjectAssert.areEqual(oldRecord, e.overwritten, 'Overwritten record is != to old record');
46c91c32e9f555734bdd918e4157fb8a92746ae0Tilo Mitra Y.Assert.areEqual(2, e.overwritten.length, 'overwritten array is not of expected length');
df648c649330effe9ab7aeb7c339313f0da428c9Tilo Mitra Y.Assert.areEqual(index, e.index, "correct index was modified");
df648c649330effe9ab7aeb7c339313f0da428c9Tilo Mitra });
df648c649330effe9ab7aeb7c339313f0da428c9Tilo Mitra
df648c649330effe9ab7aeb7c339313f0da428c9Tilo Mitra this.rs.update(newRecords, index);
df648c649330effe9ab7aeb7c339313f0da428c9Tilo Mitra
df648c649330effe9ab7aeb7c339313f0da428c9Tilo Mitra //check that the two elements in the recordset are the same as the ones pushed in
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.ObjectAssert.areEqual(a.getValue(), this.rs.getRecordByIndex(0).getValue());
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.ObjectAssert.areEqual(b.getValue(), this.rs.getRecordByIndex(1).getValue());
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.ObjectAssert.areEqual(this.initialData[2], this.rs.getRecordByIndex(2).getValue());
df648c649330effe9ab7aeb7c339313f0da428c9Tilo Mitra
df648c649330effe9ab7aeb7c339313f0da428c9Tilo Mitra //3 initial records + 1 more added (the other was just over-written)= 4 total records in recordset
df648c649330effe9ab7aeb7c339313f0da428c9Tilo Mitra Y.Assert.areEqual(3, this.rs.get('records').length);
df648c649330effe9ab7aeb7c339313f0da428c9Tilo Mitra },
df648c649330effe9ab7aeb7c339313f0da428c9Tilo Mitra
df648c649330effe9ab7aeb7c339313f0da428c9Tilo Mitra
df648c649330effe9ab7aeb7c339313f0da428c9Tilo Mitra
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra //---------------------------------------------
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra // Hashing in Base
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra //---------------------------------------------
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra testDefaultHash: function() {
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra var hashTable = this.rs.get('table');
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.ObjectAssert.areEqual(hashTable[this.rs.getRecordByIndex(0).get('id')], this.rs.getRecordByIndex(0));
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.ObjectAssert.areEqual(hashTable[this.rs.getRecordByIndex(1).get('id')], this.rs.getRecordByIndex(1));
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.ObjectAssert.areEqual(hashTable[this.rs.getRecordByIndex(2).get('id')], this.rs.getRecordByIndex(2));
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.Assert.areEqual(3, Y.Object.size(hashTable));
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra //check hashtable sync when adding
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra this.rs.add({a:'hello', b:'hey', c:'yo!'});
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.ObjectAssert.areEqual(hashTable[this.rs.getRecordByIndex(0).get('id')], this.rs.getRecordByIndex(0));
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.ObjectAssert.areEqual(hashTable[this.rs.getRecordByIndex(1).get('id')], this.rs.getRecordByIndex(1));
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.ObjectAssert.areEqual(hashTable[this.rs.getRecordByIndex(2).get('id')], this.rs.getRecordByIndex(2));
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.ObjectAssert.areEqual(hashTable[this.rs.getRecordByIndex(3).get('id')], this.rs.getRecordByIndex(3));
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.Assert.areEqual(4, Y.Object.size(hashTable));
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra //check hashtable sync when removing 1 object
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra this.rs.remove(1);
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.ObjectAssert.areEqual(hashTable[this.rs.getRecordByIndex(0).get('id')], this.rs.getRecordByIndex(0));
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.ObjectAssert.areEqual(hashTable[this.rs.getRecordByIndex(1).get('id')], this.rs.getRecordByIndex(1));
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.ObjectAssert.areEqual(hashTable[this.rs.getRecordByIndex(2).get('id')], this.rs.getRecordByIndex(2));
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.Assert.areEqual(3, Y.Object.size(hashTable));
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra //check hashtable sync when removing multiple records
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra this.rs.remove(0,2);
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.ObjectAssert.areEqual(hashTable[this.rs.getRecordByIndex(0).get('id')], this.rs.getRecordByIndex(0));
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.Assert.areEqual(1, Y.Object.size(hashTable));
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra //update single record
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra this.rs.update({a:'new', b:'record', c:'added'}, 0);
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra Y.ObjectAssert.areEqual(hashTable[this.rs.getRecordByIndex(0).get('id')], this.rs.getRecordByIndex(0));
bed61f6a58b746270933d9e188561f090001ee6aLuke Smith //Y.ObjectAssert.areEqual(hashTable[this.rs.getRecordByIndex(1).get('id')], this.rs.getRecordByIndex(1));
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra
bed61f6a58b746270933d9e188561f090001ee6aLuke Smith //Y.Assert.areEqual(2, Y.Object.size(hashTable));
bed61f6a58b746270933d9e188561f090001ee6aLuke Smith Y.Assert.areEqual(1, Y.Object.size(hashTable));
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra
bed61f6a58b746270933d9e188561f090001ee6aLuke Smith this.rs.update([
bed61f6a58b746270933d9e188561f090001ee6aLuke Smith {a:'new', b:'record', c:'added'},
bed61f6a58b746270933d9e188561f090001ee6aLuke Smith {a:'another', b:'new', c:'record'}
bed61f6a58b746270933d9e188561f090001ee6aLuke Smith ], 1);
bed61f6a58b746270933d9e188561f090001ee6aLuke Smith
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra Y.ObjectAssert.areEqual(hashTable[this.rs.getRecordByIndex(0).get('id')], this.rs.getRecordByIndex(0));
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra Y.ObjectAssert.areEqual(hashTable[this.rs.getRecordByIndex(1).get('id')], this.rs.getRecordByIndex(1));
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra Y.ObjectAssert.areEqual(hashTable[this.rs.getRecordByIndex(2).get('id')], this.rs.getRecordByIndex(2));
f8bb88ccd33cb2f5daa9f93c589d10a438d518c8Luke Smith Y.Assert.areEqual(3, Y.Object.size(hashTable));
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra },
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra
df648c649330effe9ab7aeb7c339313f0da428c9Tilo Mitra
df648c649330effe9ab7aeb7c339313f0da428c9Tilo Mitra
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra //---------------------------------------------
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra // Sort Plugin
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra //---------------------------------------------
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra //initialData: [{a:3, b:2, c:1}, {a:9, b:8, c:7}, {a:1, b:2, c:3}],
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra testDefaultSort: function() {
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra this.rs.plug(Y.Plugin.RecordsetSort);
d291538c94e99bf25eb23d4ecb9ff41f6527389cTilo Mitra
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra //Test ascending order
35efc9511ecb6deca970c97d13bc6c3fb9cb9a28Tilo Mitra Y.Assert.isFalse(this.rs.sort.get('isSorted'));
35efc9511ecb6deca970c97d13bc6c3fb9cb9a28Tilo Mitra
35efc9511ecb6deca970c97d13bc6c3fb9cb9a28Tilo Mitra
d291538c94e99bf25eb23d4ecb9ff41f6527389cTilo Mitra this.rs.sort.sort('a',false);
35efc9511ecb6deca970c97d13bc6c3fb9cb9a28Tilo Mitra
35efc9511ecb6deca970c97d13bc6c3fb9cb9a28Tilo Mitra Y.Assert.isTrue(this.rs.sort.get('isSorted'));
35efc9511ecb6deca970c97d13bc6c3fb9cb9a28Tilo Mitra
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.ObjectAssert.areEqual({a:1, b:2, c:3}, this.rs.getRecordByIndex(0).getValue());
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.ObjectAssert.areEqual({a:3, b:2, c:1}, this.rs.getRecordByIndex(1).getValue());
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.ObjectAssert.areEqual({a:9, b:8, c:7}, this.rs.getRecordByIndex(2).getValue());
d291538c94e99bf25eb23d4ecb9ff41f6527389cTilo Mitra Y.Assert.areEqual(3, this.rs.getLength());
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra //Test Descending Order
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra this.rs.sort.sort('c',true);
35efc9511ecb6deca970c97d13bc6c3fb9cb9a28Tilo Mitra Y.Assert.isTrue(this.rs.sort.get('isSorted'));
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.ObjectAssert.areEqual({a:9, b:8, c:7}, this.rs.getRecordByIndex(0).getValue());
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.ObjectAssert.areEqual({a:1, b:2, c:3}, this.rs.getRecordByIndex(1).getValue());
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.ObjectAssert.areEqual({a:3, b:2, c:1}, this.rs.getRecordByIndex(2).getValue());
d291538c94e99bf25eb23d4ecb9ff41f6527389cTilo Mitra Y.Assert.areEqual(3, this.rs.getLength());
d291538c94e99bf25eb23d4ecb9ff41f6527389cTilo Mitra
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra //Test sort when values are equal (sorts by ID)
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra this.rs.sort.sort('b',true);
35efc9511ecb6deca970c97d13bc6c3fb9cb9a28Tilo Mitra Y.Assert.isTrue(this.rs.sort.get('isSorted'));
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.ObjectAssert.areEqual({a:9, b:8, c:7}, this.rs.getRecordByIndex(0).getValue());
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.ObjectAssert.areEqual({a:1, b:2, c:3}, this.rs.getRecordByIndex(1).getValue());
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.ObjectAssert.areEqual({a:3, b:2, c:1}, this.rs.getRecordByIndex(2).getValue());
d291538c94e99bf25eb23d4ecb9ff41f6527389cTilo Mitra Y.Assert.areEqual(3, this.rs.getLength());
d291538c94e99bf25eb23d4ecb9ff41f6527389cTilo Mitra
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra },
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra //initialData: [{a:3, b:2, c:1}, {a:9, b:8, c:7}, {a:1, b:2, c:3}]
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra testResort: function() {
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra this.rs.plug(Y.Plugin.RecordsetSort);
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra
35efc9511ecb6deca970c97d13bc6c3fb9cb9a28Tilo Mitra Y.Assert.isFalse(this.rs.sort.get('isSorted'));
35efc9511ecb6deca970c97d13bc6c3fb9cb9a28Tilo Mitra
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra //Test ascending order
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra this.rs.sort.sort('a',false);
35efc9511ecb6deca970c97d13bc6c3fb9cb9a28Tilo Mitra Y.Assert.isTrue(this.rs.sort.get('isSorted'));
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.ObjectAssert.areEqual({a:1, b:2, c:3}, this.rs.getRecordByIndex(0).getValue());
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.ObjectAssert.areEqual({a:3, b:2, c:1}, this.rs.getRecordByIndex(1).getValue());
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.ObjectAssert.areEqual({a:9, b:8, c:7}, this.rs.getRecordByIndex(2).getValue());
d291538c94e99bf25eb23d4ecb9ff41f6527389cTilo Mitra Y.Assert.areEqual(3, this.rs.getLength());
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra //Add another record to the end of the recordset
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra this.rs.add({a:6,b:5,c:8});
35efc9511ecb6deca970c97d13bc6c3fb9cb9a28Tilo Mitra Y.Assert.isFalse(this.rs.sort.get('isSorted'));
35efc9511ecb6deca970c97d13bc6c3fb9cb9a28Tilo Mitra
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.ObjectAssert.areEqual({a:6,b:5,c:8}, this.rs.getRecordByIndex(3).getValue());
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra //Refresh Sorter
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra this.rs.sort.resort();
35efc9511ecb6deca970c97d13bc6c3fb9cb9a28Tilo Mitra Y.Assert.isTrue(this.rs.sort.get('isSorted'));
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra //make sure the added record was sorted into the recordset using the existing sort properties
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.ObjectAssert.areEqual({a:1, b:2, c:3}, this.rs.getRecordByIndex(0).getValue());
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.ObjectAssert.areEqual({a:3, b:2, c:1}, this.rs.getRecordByIndex(1).getValue());
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.ObjectAssert.areEqual({a:6,b:5,c:8}, this.rs.getRecordByIndex(2).getValue());
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.ObjectAssert.areEqual({a:9, b:8, c:7}, this.rs.getRecordByIndex(3).getValue());
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra Y.Assert.areEqual(4, this.rs.getLength());
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra },
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra //initialData: [{a:3, b:2, c:1}, {a:9, b:8, c:7}, {a:1, b:2, c:3}
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra testReverseBeforeSort: function() {
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra a = {a:'a', b:'b', c:'c'},
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra b = {a:'d', b:'e', c:'f'},
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra c = {a:'g', b:'h', c:'i'},
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra d = {a:'j', b:'k', c:'l'};
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra this.rs.plug(Y.Plugin.RecordsetSort);
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra //adding in some records backwards to understand if reversing is working properly
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra this.rs.add([d,c,b,a]);
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra this.rs.sort.reverse();
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.ObjectAssert.areEqual({a:3, b:2, c:1}, this.rs.getRecordByIndex(6).getValue());
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.ObjectAssert.areEqual({a:9, b:8, c:7}, this.rs.getRecordByIndex(5).getValue());
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.ObjectAssert.areEqual({a:1, b:2, c:3}, this.rs.getRecordByIndex(4).getValue());
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.ObjectAssert.areEqual(d, this.rs.getRecordByIndex(3).getValue());
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.ObjectAssert.areEqual(c, this.rs.getRecordByIndex(2).getValue());
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.ObjectAssert.areEqual(b, this.rs.getRecordByIndex(1).getValue());
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.ObjectAssert.areEqual(a, this.rs.getRecordByIndex(0).getValue());
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra Y.Assert.areEqual(7, this.rs.getLength());
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra },
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra //initialData: [{a:3, b:2, c:1}, {a:9, b:8, c:7}, {a:1, b:2, c:3}
35efc9511ecb6deca970c97d13bc6c3fb9cb9a28Tilo Mitra testFlipAfterSort: function() {
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra a = {a:1, b:'b', c:'c'},
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra b = {a:2, b:'e', c:'f'},
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra c = {a:3, b:'h', c:'i'},
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra d = {a:4, b:'k', c:'l'};
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra this.rs.plug(Y.Plugin.RecordsetSort);
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra //adding in some records backwards to understand if reversing is working properly
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra this.rs.add([d,c,b,a]);
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra this.rs.sort.sort('a',true);
35efc9511ecb6deca970c97d13bc6c3fb9cb9a28Tilo Mitra this.rs.sort.flip();
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra //1s
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra Y.ObjectAssert.areEqual({a:1, b:2, c:3}, this.rs.getRecordByIndex(0).getValue());
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra Y.ObjectAssert.areEqual(a, this.rs.getRecordByIndex(1).getValue());
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra //2s
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.ObjectAssert.areEqual(b, this.rs.getRecordByIndex(2).getValue());
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra //3s
b41c27a66cb2271249d8117d3d5395ab17594f86Tilo Mitra Y.ObjectAssert.areEqual({a:3, b:2, c:1}, this.rs.getRecordByIndex(3).getValue());
b41c27a66cb2271249d8117d3d5395ab17594f86Tilo Mitra Y.ObjectAssert.areEqual(c, this.rs.getRecordByIndex(4).getValue());
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.ObjectAssert.areEqual(d, this.rs.getRecordByIndex(5).getValue());
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.ObjectAssert.areEqual({a:9, b:8, c:7}, this.rs.getRecordByIndex(6).getValue());
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra Y.Assert.areEqual(7, this.rs.getLength());
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra },
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra //initialData: [{a:3, b:2, c:1}, {a:9, b:8, c:7}, {a:1, b:2, c:3}],
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra testCustomSort: function() {
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra
35efc9511ecb6deca970c97d13bc6c3fb9cb9a28Tilo Mitra var a = {a:1, b:1, c:4},
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra b = {a:2, b:2, c:5},
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra c = {a:3, b:2, c:4},
35efc9511ecb6deca970c97d13bc6c3fb9cb9a28Tilo Mitra d = {a:4, b:4, c:7},
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra //This is just a copy of Y.ArraySort.compare
35efc9511ecb6deca970c97d13bc6c3fb9cb9a28Tilo Mitra compare = function(a, b, desc) {
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra if(!Y.Lang.isValue(a)) {
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra if(!Y.Lang.isValue(b)) {
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra return 0;
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra }
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra else {
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra return 1;
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra }
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra }
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra else if(!Y.Lang.isValue(b)) {
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra return -1;
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra }
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra if(Y.Lang.isString(a)) {
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra a.toLowerCase();
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra }
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra if(Y.Lang.isString(b)) {
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra b.toLowerCase();
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra }
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra if(a < b) {
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra return (desc) ? 1 : -1;
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra }
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra else if (a > b) {
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra return (desc) ? -1 : 1;
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra }
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra else {
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra return 0;
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra }
35efc9511ecb6deca970c97d13bc6c3fb9cb9a28Tilo Mitra },
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra //custom sort where if the values in the given fieldA are equal, the values in fieldB are checked
35efc9511ecb6deca970c97d13bc6c3fb9cb9a28Tilo Mitra customsort = function(recA, recB, field, desc) {
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra var first_sorted = compare(recA.getValue(field), recB.getValue(field), desc);
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra if(first_sorted === 0) {
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra var second_sorted = compare(recA.getValue('b'), recB.getValue('b'), desc);
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra if (second_sorted === 0) {
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra return compare(recA.get("id"), recB.get("id"), desc);
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra }
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra else {
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra return second_sorted;
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra }
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra }
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra else {
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra return first_sorted;
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra }
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra };
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra this.rs.plug(Y.Plugin.RecordsetSort);
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra this.rs.add([a,b,c,d]);
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra this.rs.sort.sort('a',false,customsort);
3322431c6a880983db785beaa61932d3697116aaTilo Mitra
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra //initialData: [{a:3, b:2, c:1}, {a:9, b:8, c:7}, {a:1, b:2, c:3}],
35efc9511ecb6deca970c97d13bc6c3fb9cb9a28Tilo Mitra //when the numbers are equal - the object that was added later should be first
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.ObjectAssert.areEqual({a:1, b:1, c:4}, this.rs.getRecordByIndex(0).getValue());
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.ObjectAssert.areEqual({a:1, b:2, c:3}, this.rs.getRecordByIndex(1).getValue());
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.ObjectAssert.areEqual({a:2, b:2, c:5}, this.rs.getRecordByIndex(2).getValue());
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.ObjectAssert.areEqual({a:3, b:2, c:1}, this.rs.getRecordByIndex(3).getValue());
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.ObjectAssert.areEqual({a:3, b:2, c:4}, this.rs.getRecordByIndex(4).getValue());
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.ObjectAssert.areEqual({a:4, b:4, c:7}, this.rs.getRecordByIndex(5).getValue());
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.ObjectAssert.areEqual({a:9, b:8, c:7}, this.rs.getRecordByIndex(6).getValue());
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra
cd9cac4bf3a2269cbfcd93238311a194be800b5fTilo Mitra Y.Assert.areEqual(7, this.rs.getLength());
2c517b2611a8e6f11a23c19984a436ca0607a881Tilo Mitra },
2c517b2611a8e6f11a23c19984a436ca0607a881Tilo Mitra
8f31ee83a62db697e7f623307f2d3412d374a9efTilo Mitra //---------------------------------------------
8f31ee83a62db697e7f623307f2d3412d374a9efTilo Mitra // ArrayList Methods
8f31ee83a62db697e7f623307f2d3412d374a9efTilo Mitra //---------------------------------------------
8f31ee83a62db697e7f623307f2d3412d374a9efTilo Mitra
f0b3da068a86e6d396175c502d04069b6afbc49cTilo Mitra
8f31ee83a62db697e7f623307f2d3412d374a9efTilo Mitra
8f31ee83a62db697e7f623307f2d3412d374a9efTilo Mitra testSize: function() {
8f31ee83a62db697e7f623307f2d3412d374a9efTilo Mitra Y.Assert.areEqual(3, this.rs.getLength());
8f31ee83a62db697e7f623307f2d3412d374a9efTilo Mitra },
8f31ee83a62db697e7f623307f2d3412d374a9efTilo Mitra
35efc9511ecb6deca970c97d13bc6c3fb9cb9a28Tilo Mitra //initialData: [{a:3, b:2, c:1}, {a:9, b:8, c:7}, {a:1, b:2, c:3}],
35efc9511ecb6deca970c97d13bc6c3fb9cb9a28Tilo Mitra testEach: function() {
35efc9511ecb6deca970c97d13bc6c3fb9cb9a28Tilo Mitra var i = 0, recs = [];
35efc9511ecb6deca970c97d13bc6c3fb9cb9a28Tilo Mitra this.rs.each(function() {
35efc9511ecb6deca970c97d13bc6c3fb9cb9a28Tilo Mitra recs[i] = this.getValue();
35efc9511ecb6deca970c97d13bc6c3fb9cb9a28Tilo Mitra i++;
35efc9511ecb6deca970c97d13bc6c3fb9cb9a28Tilo Mitra });
35efc9511ecb6deca970c97d13bc6c3fb9cb9a28Tilo Mitra
35efc9511ecb6deca970c97d13bc6c3fb9cb9a28Tilo Mitra Y.ObjectAssert.areEqual({a:3, b:2, c:1}, recs[0]);
35efc9511ecb6deca970c97d13bc6c3fb9cb9a28Tilo Mitra Y.ObjectAssert.areEqual({a:9, b:8, c:7}, recs[1]);
35efc9511ecb6deca970c97d13bc6c3fb9cb9a28Tilo Mitra Y.ObjectAssert.areEqual({a:1, b:2, c:3}, recs[2]);
35efc9511ecb6deca970c97d13bc6c3fb9cb9a28Tilo Mitra Y.Assert.areEqual(3, recs.length);
35efc9511ecb6deca970c97d13bc6c3fb9cb9a28Tilo Mitra },
35efc9511ecb6deca970c97d13bc6c3fb9cb9a28Tilo Mitra
35efc9511ecb6deca970c97d13bc6c3fb9cb9a28Tilo Mitra testSome: function() {
35efc9511ecb6deca970c97d13bc6c3fb9cb9a28Tilo Mitra var recs=[], i=0, v={};
35efc9511ecb6deca970c97d13bc6c3fb9cb9a28Tilo Mitra
35efc9511ecb6deca970c97d13bc6c3fb9cb9a28Tilo Mitra
35efc9511ecb6deca970c97d13bc6c3fb9cb9a28Tilo Mitra this.rs.some(function() {
35efc9511ecb6deca970c97d13bc6c3fb9cb9a28Tilo Mitra v = this.getValue();
35efc9511ecb6deca970c97d13bc6c3fb9cb9a28Tilo Mitra
35efc9511ecb6deca970c97d13bc6c3fb9cb9a28Tilo Mitra if (v.a !== 1) {
35efc9511ecb6deca970c97d13bc6c3fb9cb9a28Tilo Mitra recs[i] = v;
35efc9511ecb6deca970c97d13bc6c3fb9cb9a28Tilo Mitra i++;
35efc9511ecb6deca970c97d13bc6c3fb9cb9a28Tilo Mitra return false;
35efc9511ecb6deca970c97d13bc6c3fb9cb9a28Tilo Mitra }
35efc9511ecb6deca970c97d13bc6c3fb9cb9a28Tilo Mitra else {
35efc9511ecb6deca970c97d13bc6c3fb9cb9a28Tilo Mitra return true;
35efc9511ecb6deca970c97d13bc6c3fb9cb9a28Tilo Mitra }
35efc9511ecb6deca970c97d13bc6c3fb9cb9a28Tilo Mitra
35efc9511ecb6deca970c97d13bc6c3fb9cb9a28Tilo Mitra });
35efc9511ecb6deca970c97d13bc6c3fb9cb9a28Tilo Mitra
35efc9511ecb6deca970c97d13bc6c3fb9cb9a28Tilo Mitra Y.ObjectAssert.areEqual({a:3, b:2, c:1}, recs[0]);
35efc9511ecb6deca970c97d13bc6c3fb9cb9a28Tilo Mitra Y.ObjectAssert.areEqual({a:9, b:8, c:7}, recs[1]);
35efc9511ecb6deca970c97d13bc6c3fb9cb9a28Tilo Mitra Y.Assert.areEqual(2, recs.length);
35efc9511ecb6deca970c97d13bc6c3fb9cb9a28Tilo Mitra },
df648c649330effe9ab7aeb7c339313f0da428c9Tilo Mitra
2c517b2611a8e6f11a23c19984a436ca0607a881Tilo Mitra //---------------------------------------------
2c517b2611a8e6f11a23c19984a436ca0607a881Tilo Mitra // Filter Plugin
2c517b2611a8e6f11a23c19984a436ca0607a881Tilo Mitra //---------------------------------------------
2c517b2611a8e6f11a23c19984a436ca0607a881Tilo Mitra
f0b3da068a86e6d396175c502d04069b6afbc49cTilo Mitra testFilter: function() {
2c517b2611a8e6f11a23c19984a436ca0607a881Tilo Mitra this.rs.plug(Y.Plugin.RecordsetFilter);
f0b3da068a86e6d396175c502d04069b6afbc49cTilo Mitra var validator = function(item) {
f0b3da068a86e6d396175c502d04069b6afbc49cTilo Mitra if (item.getValue('b') === 2) {
f0b3da068a86e6d396175c502d04069b6afbc49cTilo Mitra return true;
f0b3da068a86e6d396175c502d04069b6afbc49cTilo Mitra }
f0b3da068a86e6d396175c502d04069b6afbc49cTilo Mitra else {
f0b3da068a86e6d396175c502d04069b6afbc49cTilo Mitra return false;
f0b3da068a86e6d396175c502d04069b6afbc49cTilo Mitra }
35efc9511ecb6deca970c97d13bc6c3fb9cb9a28Tilo Mitra },
35efc9511ecb6deca970c97d13bc6c3fb9cb9a28Tilo Mitra rs = this.rs.filter.filter(validator);
f0b3da068a86e6d396175c502d04069b6afbc49cTilo Mitra
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.ObjectAssert.areEqual({a:3, b:2, c:1}, rs.getRecordByIndex(0).getValue());
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.ObjectAssert.areEqual({a:1, b:2, c:3}, rs.getRecordByIndex(1).getValue());
f0b3da068a86e6d396175c502d04069b6afbc49cTilo Mitra Y.Assert.areEqual(2, rs.getLength());
f0b3da068a86e6d396175c502d04069b6afbc49cTilo Mitra
f0b3da068a86e6d396175c502d04069b6afbc49cTilo Mitra //test a filter that doesn't return anything from recordset
f0b3da068a86e6d396175c502d04069b6afbc49cTilo Mitra validator = function(item) {
f0b3da068a86e6d396175c502d04069b6afbc49cTilo Mitra if (item.getValue('c') === 2) {
f0b3da068a86e6d396175c502d04069b6afbc49cTilo Mitra return true;
f0b3da068a86e6d396175c502d04069b6afbc49cTilo Mitra }
f0b3da068a86e6d396175c502d04069b6afbc49cTilo Mitra else {
f0b3da068a86e6d396175c502d04069b6afbc49cTilo Mitra return false;
f0b3da068a86e6d396175c502d04069b6afbc49cTilo Mitra }
f0b3da068a86e6d396175c502d04069b6afbc49cTilo Mitra };
f0b3da068a86e6d396175c502d04069b6afbc49cTilo Mitra
f0b3da068a86e6d396175c502d04069b6afbc49cTilo Mitra rs = this.rs.filter.filter(validator);
f0b3da068a86e6d396175c502d04069b6afbc49cTilo Mitra Y.Assert.areEqual(0, rs.getLength());
f0b3da068a86e6d396175c502d04069b6afbc49cTilo Mitra
f0b3da068a86e6d396175c502d04069b6afbc49cTilo Mitra
f0b3da068a86e6d396175c502d04069b6afbc49cTilo Mitra //Test Filter with Key Value pair
f0b3da068a86e6d396175c502d04069b6afbc49cTilo Mitra rs = this.rs.filter.filter('b',2);
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.ObjectAssert.areEqual({a:3, b:2, c:1}, rs.getRecordByIndex(0).getValue());
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.ObjectAssert.areEqual({a:1, b:2, c:3}, rs.getRecordByIndex(1).getValue());
f0b3da068a86e6d396175c502d04069b6afbc49cTilo Mitra Y.Assert.areEqual(2, rs.getLength());
f0b3da068a86e6d396175c502d04069b6afbc49cTilo Mitra
8f31ee83a62db697e7f623307f2d3412d374a9efTilo Mitra },
8f31ee83a62db697e7f623307f2d3412d374a9efTilo Mitra
3322431c6a880983db785beaa61932d3697116aaTilo Mitra testReject: function() {
2c517b2611a8e6f11a23c19984a436ca0607a881Tilo Mitra this.rs.plug(Y.Plugin.RecordsetFilter);
2c517b2611a8e6f11a23c19984a436ca0607a881Tilo Mitra
2c517b2611a8e6f11a23c19984a436ca0607a881Tilo Mitra var validator = function(item) {
2c517b2611a8e6f11a23c19984a436ca0607a881Tilo Mitra if (item.getValue('b') === 2) {
2c517b2611a8e6f11a23c19984a436ca0607a881Tilo Mitra return true;
2c517b2611a8e6f11a23c19984a436ca0607a881Tilo Mitra }
2c517b2611a8e6f11a23c19984a436ca0607a881Tilo Mitra else {
2c517b2611a8e6f11a23c19984a436ca0607a881Tilo Mitra return false;
2c517b2611a8e6f11a23c19984a436ca0607a881Tilo Mitra }
2c517b2611a8e6f11a23c19984a436ca0607a881Tilo Mitra },
2c517b2611a8e6f11a23c19984a436ca0607a881Tilo Mitra
3322431c6a880983db785beaa61932d3697116aaTilo Mitra rs = this.rs.filter.reject(validator);
3322431c6a880983db785beaa61932d3697116aaTilo Mitra
3322431c6a880983db785beaa61932d3697116aaTilo Mitra //initialData: [{a:3, b:2, c:1}, {a:9, b:8, c:7}, {a:1, b:2, c:3}],
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.ObjectAssert.areEqual({a:9, b:8, c:7}, rs.getRecordByIndex(0).getValue());
3322431c6a880983db785beaa61932d3697116aaTilo Mitra Y.Assert.areEqual(1, rs.getLength());
3322431c6a880983db785beaa61932d3697116aaTilo Mitra
2c517b2611a8e6f11a23c19984a436ca0607a881Tilo Mitra
3322431c6a880983db785beaa61932d3697116aaTilo Mitra //try it with a validator that always returns false
3322431c6a880983db785beaa61932d3697116aaTilo Mitra validator = function(item) {
3322431c6a880983db785beaa61932d3697116aaTilo Mitra if (item.getValue('c') === 2) {
3322431c6a880983db785beaa61932d3697116aaTilo Mitra return true;
3322431c6a880983db785beaa61932d3697116aaTilo Mitra }
3322431c6a880983db785beaa61932d3697116aaTilo Mitra else {
3322431c6a880983db785beaa61932d3697116aaTilo Mitra return false;
3322431c6a880983db785beaa61932d3697116aaTilo Mitra }
3322431c6a880983db785beaa61932d3697116aaTilo Mitra };
3322431c6a880983db785beaa61932d3697116aaTilo Mitra
3322431c6a880983db785beaa61932d3697116aaTilo Mitra rs = this.rs.filter.reject(validator);
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.ObjectAssert.areEqual(this.rs.getRecordByIndex(0).getValue(), rs.getRecordByIndex(0).getValue());
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.ObjectAssert.areEqual(this.rs.getRecordByIndex(1).getValue(), rs.getRecordByIndex(1).getValue());
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.ObjectAssert.areEqual(this.rs.getRecordByIndex(2).getValue(), rs.getRecordByIndex(2).getValue());
3322431c6a880983db785beaa61932d3697116aaTilo Mitra
3322431c6a880983db785beaa61932d3697116aaTilo Mitra Y.Assert.areEqual(this.rs.getLength(), rs.getLength());
3322431c6a880983db785beaa61932d3697116aaTilo Mitra
3322431c6a880983db785beaa61932d3697116aaTilo Mitra },
3322431c6a880983db785beaa61932d3697116aaTilo Mitra
3322431c6a880983db785beaa61932d3697116aaTilo Mitra
3322431c6a880983db785beaa61932d3697116aaTilo Mitra //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)
3322431c6a880983db785beaa61932d3697116aaTilo Mitra testMap: function() {
3322431c6a880983db785beaa61932d3697116aaTilo Mitra var f = function(item) {
3322431c6a880983db785beaa61932d3697116aaTilo Mitra if (item.getValue('b') === 2) {
3322431c6a880983db785beaa61932d3697116aaTilo Mitra return true;
3322431c6a880983db785beaa61932d3697116aaTilo Mitra }
3322431c6a880983db785beaa61932d3697116aaTilo Mitra else {
3322431c6a880983db785beaa61932d3697116aaTilo Mitra return false;
3322431c6a880983db785beaa61932d3697116aaTilo Mitra }
3322431c6a880983db785beaa61932d3697116aaTilo Mitra },
3322431c6a880983db785beaa61932d3697116aaTilo Mitra rs = Y.Array.map(this.rs.get('records'),f);
3322431c6a880983db785beaa61932d3697116aaTilo Mitra Y.Assert.areEqual(true, rs[0]);
3322431c6a880983db785beaa61932d3697116aaTilo Mitra Y.Assert.areEqual(false, rs[1]);
3322431c6a880983db785beaa61932d3697116aaTilo Mitra Y.Assert.areEqual(true, rs[2]);
3322431c6a880983db785beaa61932d3697116aaTilo Mitra Y.Assert.areEqual(3, rs.length);
5ac15977325958d11cea905bc4819664d096eb5cTilo Mitra },
5ac15977325958d11cea905bc4819664d096eb5cTilo Mitra
5ac15977325958d11cea905bc4819664d096eb5cTilo Mitra //---------------------------------------------
5ac15977325958d11cea905bc4819664d096eb5cTilo Mitra // Indexer Plugin
5ac15977325958d11cea905bc4819664d096eb5cTilo Mitra //---------------------------------------------
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra //initialData: [{a:3, b:2, c:1}, {a:9, b:8, c:7}, {a:1, b:2, c:3}],
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra testCustomHashTableInitialization: function() {
5ac15977325958d11cea905bc4819664d096eb5cTilo Mitra this.rs.plug(Y.Plugin.RecordsetIndexer);
5ac15977325958d11cea905bc4819664d096eb5cTilo Mitra
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra var hashA = this.rs.indexer.createTable('a');
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra var hashTables = this.rs.indexer.get('hashTables');
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra //check hashA
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra Y.ObjectAssert.areEqual(hashA[3].getValue(), {a:3, b:2, c:1});
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra Y.ObjectAssert.areEqual(hashA[9].getValue(), {a:9, b:8, c:7});
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra Y.ObjectAssert.areEqual(hashA[1].getValue(), {a:1, b:2, c:3});
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra //check main table (contains all the subtables)
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra Y.ObjectAssert.areEqual(hashTables.a[3].getValue(), {a:3, b:2, c:1});
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra Y.ObjectAssert.areEqual(hashTables.a[9].getValue(), {a:9, b:8, c:7});
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra Y.ObjectAssert.areEqual(hashTables.a[1].getValue(), {a:1, b:2, c:3});
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.ObjectAssert.areEqual(hashA, hashTables.a);
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra var hashB = this.rs.indexer.createTable('b');
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra Y.ObjectAssert.areEqual(hashTables.b[2].getValue(), {a:1, b:2, c:3});
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra Y.ObjectAssert.areEqual(hashTables.b[8].getValue(), {a:9, b:8, c:7});
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra Y.ObjectAssert.areEqual(hashB[2].getValue(), {a:1, b:2, c:3});
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra Y.ObjectAssert.areEqual(hashB[8].getValue(), {a:9, b:8, c:7});
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra Y.ObjectAssert.areEqual(hashB, hashTables.b);
65b27c0c1a6d67d8df030e28b6568929bb214418Tilo Mitra
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra },
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra //initialData: [{a:3, b:2, c:1}, {a:9, b:8, c:7}, {a:1, b:2, c:3}],
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra testCustomHashTableAddingRecord: function() {
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra this.rs.plug(Y.Plugin.RecordsetIndexer);
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra var hashA = this.rs.indexer.createTable('a'),
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra hashC = this.rs.indexer.createTable('c'),
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra hashTables = this.rs.indexer.get('hashTables');
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra //add to the end
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra this.rs.add({a:'adding', b:'this', c:'record'});
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra Y.ObjectAssert.areEqual(hashA[3].getValue(), {a:3, b:2, c:1});
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra Y.ObjectAssert.areEqual(hashA[9].getValue(), {a:9, b:8, c:7});
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra Y.ObjectAssert.areEqual(hashA[1].getValue(), {a:1, b:2, c:3});
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra Y.ObjectAssert.areEqual(hashA['adding'].getValue(), {a:'adding', b:'this', c:'record'});
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra Y.Assert.areEqual(4, Y.Object.size(hashA));
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra Y.ObjectAssert.areEqual(hashA, hashTables.a);
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra Y.ObjectAssert.areEqual(hashC[1].getValue(), {a:3, b:2, c:1});
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra Y.ObjectAssert.areEqual(hashC[7].getValue(), {a:9, b:8, c:7});
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra Y.ObjectAssert.areEqual(hashC[3].getValue(), {a:1, b:2, c:3});
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra Y.ObjectAssert.areEqual(hashC['record'].getValue(), {a:'adding', b:'this', c:'record'});
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra Y.Assert.areEqual(4, Y.Object.size(hashC));
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra Y.ObjectAssert.areEqual(hashC, hashTables.c);
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra //adding record to a specific index
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra this.rs.add({a:'another', b:'new', c:'record'}, 0);
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra Y.ObjectAssert.areEqual(hashA[3].getValue(), {a:3, b:2, c:1});
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra Y.ObjectAssert.areEqual(hashA[9].getValue(), {a:9, b:8, c:7});
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra Y.ObjectAssert.areEqual(hashA[1].getValue(), {a:1, b:2, c:3});
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra Y.ObjectAssert.areEqual(hashA['adding'].getValue(), {a:'adding', b:'this', c:'record'});
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra Y.ObjectAssert.areEqual(hashA['another'].getValue(), {a:'another', b:'new', c:'record'});
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra Y.Assert.areEqual(5, Y.Object.size(hashA));
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra Y.ObjectAssert.areEqual(hashA, hashTables.a);
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra //'record' will overwrite the previous added record.
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra Y.ObjectAssert.areEqual(hashC[1].getValue(), {a:3, b:2, c:1});
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra Y.ObjectAssert.areEqual(hashC[7].getValue(), {a:9, b:8, c:7});
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra Y.ObjectAssert.areEqual(hashC[3].getValue(), {a:1, b:2, c:3});
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra Y.ObjectAssert.areEqual(hashC['record'].getValue(), {a:'another', b:'new', c:'record'});
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra Y.Assert.areEqual(4, Y.Object.size(hashC));
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra Y.ObjectAssert.areEqual(hashC, hashTables.c);
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra //adding multiple records
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra this.rs.add([{a:'blah', b:'bloo', c:'bleh'},{a:'heres', b:'another', c:'one'}]);
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra Y.ObjectAssert.areEqual(hashA[3].getValue(), {a:3, b:2, c:1});
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra Y.ObjectAssert.areEqual(hashA[9].getValue(), {a:9, b:8, c:7});
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra Y.ObjectAssert.areEqual(hashA[1].getValue(), {a:1, b:2, c:3});
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra Y.ObjectAssert.areEqual(hashA['adding'].getValue(), {a:'adding', b:'this', c:'record'});
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra Y.ObjectAssert.areEqual(hashA['another'].getValue(), {a:'another', b:'new', c:'record'});
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra Y.ObjectAssert.areEqual(hashA['blah'].getValue(), {a:'blah', b:'bloo', c:'bleh'});
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra Y.ObjectAssert.areEqual(hashA['heres'].getValue(), {a:'heres', b:'another', c:'one'});
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra Y.Assert.areEqual(7, Y.Object.size(hashA));
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra Y.ObjectAssert.areEqual(hashA, hashTables.a);
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra //'record' will overwrite the previous added record.
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra Y.ObjectAssert.areEqual(hashC[1].getValue(), {a:3, b:2, c:1});
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra Y.ObjectAssert.areEqual(hashC[7].getValue(), {a:9, b:8, c:7});
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra Y.ObjectAssert.areEqual(hashC[3].getValue(), {a:1, b:2, c:3});
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra Y.ObjectAssert.areEqual(hashC['record'].getValue(), {a:'another', b:'new', c:'record'});
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra Y.ObjectAssert.areEqual(hashC['bleh'].getValue(), {a:'blah', b:'bloo', c:'bleh'});
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra Y.ObjectAssert.areEqual(hashC['one'].getValue(), {a:'heres', b:'another', c:'one'});
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra Y.Assert.areEqual(6, Y.Object.size(hashC));
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra Y.ObjectAssert.areEqual(hashC, hashTables.c);
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra },
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra testCustomHashTableRemovingRecord: function() {
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra this.rs.plug(Y.Plugin.RecordsetIndexer);
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra var hashA = this.rs.indexer.createTable('a'),
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra hashC = this.rs.indexer.createTable('c'),
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra hashTables = this.rs.indexer.get('hashTables');
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra this.rs.remove(2);
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra Y.ObjectAssert.areEqual(hashA[3].getValue(), {a:3, b:2, c:1});
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra Y.ObjectAssert.areEqual(hashA[9].getValue(), {a:9, b:8, c:7});
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra Y.Assert.areEqual(2, Y.Object.size(hashA));
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra Y.ObjectAssert.areEqual(hashA, hashTables.a);
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra //'record' will overwrite the previous added record.
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra Y.ObjectAssert.areEqual(hashC[1].getValue(), {a:3, b:2, c:1});
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra Y.ObjectAssert.areEqual(hashC[7].getValue(), {a:9, b:8, c:7});
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra Y.Assert.areEqual(2, Y.Object.size(hashC));
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra Y.ObjectAssert.areEqual(hashC, hashTables.c);
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra //try removing more than 1 record at a time
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra this.rs.add({a:1, b:2, c:3});
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra this.rs.remove(0,2);
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra Y.ObjectAssert.areEqual(hashA[1].getValue(), {a:1, b:2, c:3});
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra Y.Assert.areEqual(1, Y.Object.size(hashA));
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra Y.ObjectAssert.areEqual(hashA, hashTables.a);
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra Y.ObjectAssert.areEqual(hashC[3].getValue(), {a:1, b:2, c:3});
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra Y.Assert.areEqual(1, Y.Object.size(hashC));
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra Y.ObjectAssert.areEqual(hashC, hashTables.c);
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra },
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra //initialData: [{a:3, b:2, c:1}, {a:9, b:8, c:7}, {a:1, b:2, c:3}],
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra testCustomHashTableUpdatingRecord: function() {
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra this.rs.plug(Y.Plugin.RecordsetIndexer);
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra var hashA = this.rs.indexer.createTable('a'),
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra hashC = this.rs.indexer.createTable('c'),
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra hashTables = this.rs.indexer.get('hashTables');
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra this.rs.update({a:'one', b:'record', c:'added'}, 1);
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra Y.ObjectAssert.areEqual(hashA[3].getValue(), {a:3, b:2, c:1});
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra Y.ObjectAssert.areEqual(hashA[1].getValue(), {a:1, b:2, c:3});
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra Y.ObjectAssert.areEqual(hashA['one'].getValue(), {a:'one', b:'record', c:'added'});
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra Y.Assert.areEqual(3, Y.Object.size(hashA));
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra Y.ObjectAssert.areEqual(hashA, hashTables.a);
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra //'record' will overwrite the previous added record.
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra Y.ObjectAssert.areEqual(hashC[1].getValue(), {a:3, b:2, c:1});
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra Y.ObjectAssert.areEqual(hashC[3].getValue(), {a:1, b:2, c:3});
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra Y.ObjectAssert.areEqual(hashC['added'].getValue(), {a:'one', b:'record', c:'added'});
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra Y.Assert.areEqual(3, Y.Object.size(hashC));
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra Y.ObjectAssert.areEqual(hashC, hashTables.c);
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra //update multiple records
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra this.rs.update([{a:'adding', b:'this', c:'record'}, {a:'heres', b:'another', c:'one'}], 2);
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra Y.ObjectAssert.areEqual(hashA[3].getValue(), {a:3, b:2, c:1});
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra Y.ObjectAssert.areEqual(hashA['adding'].getValue(), {a:'adding', b:'this', c:'record'});
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra Y.ObjectAssert.areEqual(hashA['heres'].getValue(), {a:'heres', b:'another', c:'one'});
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra Y.Assert.areEqual(4, Y.Object.size(hashA));
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra Y.ObjectAssert.areEqual(hashA, hashTables.a);
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra //'record' will overwrite the previous added record.
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra Y.ObjectAssert.areEqual(hashC[1].getValue(), {a:3, b:2, c:1});
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra Y.ObjectAssert.areEqual(hashC['record'].getValue(), {a:'adding', b:'this', c:'record'});
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra Y.ObjectAssert.areEqual(hashC['one'].getValue(), {a:'heres', b:'another', c:'one'});
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra Y.Assert.areEqual(4, Y.Object.size(hashC));
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra Y.ObjectAssert.areEqual(hashC, hashTables.c);
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra
41a8ce8581ada11d736d1d0517b47d3315b70de8Tilo Mitra
5ac15977325958d11cea905bc4819664d096eb5cTilo Mitra }
8213b4dd7b4809bae2906f654b95102cd6c96d38Tilo Mitra
5d8d3401ad8bc8975c27975c7fffc1c4d18cf81cTilo Mitra
062bd352b8466cb337cea7a9e2727fe82970582cJenny Donnelly });
062bd352b8466cb337cea7a9e2727fe82970582cJenny Donnelly
062bd352b8466cb337cea7a9e2727fe82970582cJenny Donnelly var suite = new Y.Test.Suite({name:"Recordset Test Suite"});
062bd352b8466cb337cea7a9e2727fe82970582cJenny Donnelly suite.add(testBasic);
062bd352b8466cb337cea7a9e2727fe82970582cJenny Donnelly
062bd352b8466cb337cea7a9e2727fe82970582cJenny Donnelly Y.Test.Runner.setName("Recordset Test Runner");
062bd352b8466cb337cea7a9e2727fe82970582cJenny Donnelly Y.Test.Runner.add(suite);
062bd352b8466cb337cea7a9e2727fe82970582cJenny Donnelly Y.Test.Runner.run();
062bd352b8466cb337cea7a9e2727fe82970582cJenny Donnelly });
062bd352b8466cb337cea7a9e2727fe82970582cJenny Donnelly})();
062bd352b8466cb337cea7a9e2727fe82970582cJenny Donnelly</script>
062bd352b8466cb337cea7a9e2727fe82970582cJenny Donnelly</body>
062bd352b8466cb337cea7a9e2727fe82970582cJenny Donnelly</html>