From 7ad49aeae93bf2218f545ed96fd0e3b87d33710e Mon Sep 17 00:00:00 2001 From: Richard Wall Date: Sun, 7 Aug 2011 17:13:18 +0100 Subject: 80 col wrapping --- jarmon/jarmon.test.js | 54 +++++++++++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 23 deletions(-) (limited to 'jarmon/jarmon.test.js') diff --git a/jarmon/jarmon.test.js b/jarmon/jarmon.test.js index 7b009d7..5f832ec 100644 --- a/jarmon/jarmon.test.js +++ b/jarmon/jarmon.test.js @@ -35,7 +35,8 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { function(self, ret) { self.resume(function() { Y.Assert.isInstanceOf(jarmon.BinaryFile, ret); - Y.Assert.areEqual(String.fromCharCode(0), ret.getRawData()); + Y.Assert.areEqual( + String.fromCharCode(0), ret.getRawData()); }); }, this); @@ -136,7 +137,7 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { for(var i=0; i
').appendTo($('body')); + var $tpl = $( + '
').appendTo($('body')); var c = new jarmon.Chart($tpl, jarmon.Chart.BASE_OPTIONS); // c.options.xaxis.tzoffset = 0; - c.addData('speed', new jarmon.RrdQueryRemote('build/test.rrd', 'm/s'), true); + c.addData( + 'speed', + new jarmon.RrdQueryRemote('build/test.rrd', 'm/s'), + true); var d = c.setTimeRange(RRD_STARTTIME, RRD_ENDTIME); d.addCallback( function(self) { @@ -396,7 +402,7 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { }); }, this); this.wait(); - }, + } })); @@ -404,7 +410,7 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { name: "jarmon.RrdChooser", setUp: function() { - this.$tpl = $('
').appendTo($('body')) + this.$tpl = $('
').appendTo($('body')); var c = new jarmon.RrdChooser(this.$tpl); c.drawRrdUrlForm(); }, @@ -437,13 +443,15 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { * list of further DS label fields **/ var self = this; - this.$tpl.find('form input[name=rrd_url]').val('build/test.rrd').submit(); + this.$tpl.find( + 'form input[name=rrd_url]').val('build/test.rrd').submit(); this.wait( function() { - Y.Assert.areEqual(self.$tpl.find('input[name=rrd_ds_label]').size(), 1); + Y.Assert.areEqual( + self.$tpl.find('input[name=rrd_ds_label]').size(), 1); }, 1000 ); - }, + } })); @@ -451,7 +459,7 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { name: "jarmon.ChartEditor", setUp: function() { - this.$tpl = $('
').appendTo($('body')) + this.$tpl = $('
').appendTo($('body')); var c = new jarmon.ChartEditor( this.$tpl, { -- cgit v1.2.3 From 6af415eae45cf2b7faa24650f63e82212e7c239e Mon Sep 17 00:00:00 2001 From: Richard Wall Date: Sun, 7 Aug 2011 20:54:05 +0100 Subject: use jQuery.deferred in the tests --- jarmon/jarmon.test.js | 147 +++++++++++++++++++++++++++----------------------- 1 file changed, 79 insertions(+), 68 deletions(-) (limited to 'jarmon/jarmon.test.js') diff --git a/jarmon/jarmon.test.js b/jarmon/jarmon.test.js index 5f832ec..90eb28a 100644 --- a/jarmon/jarmon.test.js +++ b/jarmon/jarmon.test.js @@ -13,14 +13,15 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { * When url cannot be found, the deferred should errback with status * 404. **/ + var self = this; var d = new jarmon.downloadBinary('non-existent-file.html'); - d.addBoth( - function(self, ret) { + d.always( + function(ret) { self.resume(function() { Y.Assert.isInstanceOf(Error, ret); Y.Assert.areEqual(404, ret.message); }); - }, this); + }); this.wait(); }, @@ -30,15 +31,16 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { * When url is found, the deferred should callback with an instance * of javascriptrrd.BinaryFile **/ + var self = this; var d = new jarmon.downloadBinary('testfile.bin'); - d.addBoth( - function(self, ret) { + d.always( + function(ret) { self.resume(function() { Y.Assert.isInstanceOf(jarmon.BinaryFile, ret); Y.Assert.areEqual( String.fromCharCode(0), ret.getRawData()); }); - }, this); + }); this.wait(); } @@ -57,12 +59,11 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { name: "jarmon.RRDFile", setUp: function() { - this.d = new jarmon.downloadBinary('build/test.rrd') - .addCallback( - function(self, binary) { + var self = this; + this.d = new jarmon.downloadBinary('build/test.rrd').pipe( + function(binary) { return new RRDFile(binary); - }, this) - .addErrback( + }, function(ret) { console.log(ret); }); @@ -73,13 +74,14 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { * The generated rrd file should have a lastupdate date of * 1980-01-01 00:50:01 **/ - this.d.addCallback( - function(self, rrd) { + var self = this; + this.d.done( + function(rrd) { self.resume(function() { Y.Assert.areEqual( RRD_ENDTIME/1000+1, rrd.getLastUpdate()); }); - }, this); + }); this.wait(); }, @@ -89,8 +91,9 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { * 'speed'. A RangeError is thrown if the requested index or dsName * doesnt exist. **/ - this.d.addCallback( - function(self, rrd) { + var self = this; + this.d.done( + function(rrd) { self.resume(function() { Y.Assert.areEqual(RRD_DSNAME, rrd.getDS(0).getName()); Y.Assert.areEqual( @@ -103,7 +106,7 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { } Y.assert(error instanceof RangeError); }); - }, this); + }); this.wait(); }, @@ -111,12 +114,13 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { /** * The generated rrd file should have a single RRA **/ - this.d.addCallback( - function(self, rrd) { + var self = this; + this.d.done( + function(rrd) { self.resume(function() { Y.Assert.areEqual(RRD_RRACOUNT, rrd.getNrRRAs()); }); - }, this); + }); this.wait(); }, @@ -127,8 +131,9 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { * rra.getEl throws a RangeError if asked for row which doesn't * exist. **/ - this.d.addCallback( - function(self, rrd) { + var self = this; + this.d.done( + function(rrd) { self.resume(function() { var rra = rrd.getRRA(0); Y.Assert.areEqual('AVERAGE', rra.getCFName()); @@ -145,7 +150,7 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { } Y.assert(error instanceof RangeError); }); - }, this); + }); this.wait(); } })); @@ -154,12 +159,10 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { name: "jarmon.RrdQuery", setUp: function() { - this.d = new jarmon.downloadBinary('build/test.rrd') - .addCallback( - function(self, binary) { + this.d = new jarmon.downloadBinary('build/test.rrd').pipe( + function(binary) { return new RRDFile(binary); - }, this) - .addErrback( + }, function(ret) { console.log(ret); }); @@ -169,19 +172,21 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { /** * The starttime must be less than the endtime **/ - this.d.addCallback( - function(self, rrd) { - self.resume(function() { - var rq = new jarmon.RrdQuery(rrd, ''); - var error = null; - try { - rq.getData(1, 0); - } catch(e) { - error = e; - } - Y.Assert.isInstanceOf(RangeError, error); - }); - }, this); + var self = this; + this.d.done( + function(rrd) { + self.resume( + function() { + var rq = new jarmon.RrdQuery(rrd, ''); + var error; + try { + rq.getData(1, 0); + } catch(e) { + error = e; + } + Y.Assert.isInstanceOf(RangeError, error); + }); + }); this.wait(); }, @@ -191,8 +196,9 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { * Error is raised if the rrd file doesn't contain an RRA with the * requested consolidation function (CF) **/ - this.d.addCallback( - function(self, rrd) { + var self = this; + this.d.done( + function(rrd) { self.resume(function() { var rq = new jarmon.RrdQuery(rrd, ''); var error = null; @@ -203,7 +209,7 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { } Y.Assert.isInstanceOf(TypeError, error); }); - }, this); + }); this.wait(); }, @@ -215,8 +221,9 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { * Result should include a data points with times > starttime and * <= endTime **/ - this.d.addCallback( - function(self, rrd) { + var self = this; + this.d.done( + function(rrd) { self.resume(function() { var rq = new jarmon.RrdQuery(rrd, ''); @@ -255,7 +262,7 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { RRD_ENDTIME-RRD_STEP*1000*2, data.data[data.data.length-1][0]); }); - }, this); + }); this.wait(); }, @@ -264,14 +271,15 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { * If the requested time range is outside the range of the RRD file * we should not get any values back **/ - this.d.addCallback( - function(self, rrd) { + var self = this; + this.d.done( + function(rrd) { self.resume(function() { var rq = new jarmon.RrdQuery(rrd, ''); var data = rq.getData(RRD_ENDTIME, RRD_ENDTIME+1000); Y.Assert.areEqual(0, data.data.length); }); - }, this); + }); this.wait(); } @@ -289,12 +297,13 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { /** * The starttime must be less than the endtime **/ - this.rq.getData(1, 0).addBoth( - function(self, res) { + var self = this; + this.rq.getData(1, 0).fail( + function(res) { self.resume(function() { Y.Assert.isInstanceOf(RangeError, res); }); - }, this); + }); this.wait(); }, @@ -304,12 +313,13 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { * Error is raised if the rrd file doesn't contain an RRA with the * requested consolidation function (CF) **/ - this.rq.getData(RRD_STARTTIME, RRD_ENDTIME, 0, 'FOO').addBoth( - function(self, res) { + var self = this; + this.rq.getData(RRD_STARTTIME, RRD_ENDTIME, 0, 'FOO').always( + function(res) { self.resume(function() { Y.Assert.isInstanceOf(TypeError, res); }); - }, this); + }); this.wait(); }, @@ -321,9 +331,10 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { * Result should include a data points with times > starttime and * <= endTime **/ + var self = this; this.rq.getData(RRD_STARTTIME + (RRD_STEP+1) * 1000, - RRD_ENDTIME - (RRD_STEP-1) * 1000).addBoth( - function(self, data) { + RRD_ENDTIME - (RRD_STEP-1) * 1000).always( + function(data) { self.resume(function() { /* We request data starting 1 STEP +1s after the RRD file first val and ending 1 STEP -1s @@ -356,7 +367,7 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { RRD_ENDTIME-RRD_STEP*1000*2, data.data[data.data.length-1][0]); }); - }, this); + }); this.wait(); }, @@ -365,15 +376,15 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { * If the requested time range is outside the range of the RRD file * we should not get any values back **/ - this.rq.getData(RRD_ENDTIME, RRD_ENDTIME+1000).addBoth( - function(self, data) { + var self = this; + this.rq.getData(RRD_ENDTIME, RRD_ENDTIME+1000).always( + function(data) { self.resume(function() { Y.Assert.areEqual(0, data.data.length); }); - }, this); + }); this.wait(); } - })); @@ -385,6 +396,7 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { * Test that a rendered chart has the correct dimensions, legend, * axis, labels etc **/ + var self = this; var $tpl = $( '
').appendTo($('body')); var c = new jarmon.Chart($tpl, jarmon.Chart.BASE_OPTIONS); @@ -395,12 +407,12 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { new jarmon.RrdQueryRemote('build/test.rrd', 'm/s'), true); var d = c.setTimeRange(RRD_STARTTIME, RRD_ENDTIME); - d.addCallback( - function(self) { + d.done( + function() { self.resume(function() { // TODO: write useful tests }); - }, this); + }); this.wait(); } })); @@ -433,8 +445,7 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { this.wait( function() { Y.Assert.areEqual(self.$tpl.find('.error').size(), 1); - }, 1000 - ); + }, 1000); }, test_drawUrlListDatasources: function () { -- cgit v1.2.3 From b07effde8a5c820629d5d48abb21d2ffd7777c75 Mon Sep 17 00:00:00 2001 From: Richard Wall Date: Sun, 7 Aug 2011 22:02:17 +0100 Subject: fix some tests in IE --- jarmon/jarmon.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'jarmon/jarmon.test.js') diff --git a/jarmon/jarmon.test.js b/jarmon/jarmon.test.js index 90eb28a..6370740 100644 --- a/jarmon/jarmon.test.js +++ b/jarmon/jarmon.test.js @@ -19,7 +19,7 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { function(ret) { self.resume(function() { Y.Assert.isInstanceOf(Error, ret); - Y.Assert.areEqual(404, ret.message); + Y.Assert.areEqual('error:404', ret.message); }); }); @@ -38,7 +38,7 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { self.resume(function() { Y.Assert.isInstanceOf(jarmon.BinaryFile, ret); Y.Assert.areEqual( - String.fromCharCode(0), ret.getRawData()); + String.fromCharCode(0), ret.getCharAt(0)); }); }); -- cgit v1.2.3