Index: test/test_utils.js |
=== modified file 'test/test_utils.js' |
--- test/test_utils.js 2012-10-12 23:52:48 +0000 |
+++ test/test_utils.js 2013-01-10 22:00:53 +0000 |
@@ -3,6 +3,7 @@ |
(function() { |
describe('juju-views-utils', function() { |
var views, Y; |
+ |
before(function(done) { |
Y = YUI(GlobalConfig).use( |
'juju-view-utils', 'node-event-simulate', |
@@ -339,3 +340,106 @@ |
}); |
})(); |
+ |
+(function() { |
+ describe('utils.negate', function() { |
+ |
+ var utils, Y; |
+ |
+ before(function(done) { |
+ Y = YUI(GlobalConfig).use('juju-views', function(Y) { |
+ utils = Y.namespace('juju.views.utils'); |
+ done(); |
+ }); |
+ }); |
+ |
+ it('should return false if the function returns true', function() { |
+ var f = function() { return true; }; |
+ var n = utils.negate(f); |
+ assert.isFalse(n()); |
+ }); |
+ |
+ it('should return true if the function returns false', function() { |
+ var f = function() { return false; }; |
+ var n = utils.negate(f); |
+ assert.isTrue(n()); |
+ }); |
+ |
+ it('should forward all arguments to the underlying function', function() { |
+ var passed_arguments; |
+ var f = function() { |
+ passed_arguments = arguments; |
+ }; |
+ var n = utils.negate(f); |
+ n(1, 2, 3); |
+ assert.deepEqual(passed_arguments, {'0': 1, '1': 2, '2': 3}); |
+ }); |
+ |
+ }); |
+})(); |
+ |
+(function() { |
+ describe('utils.isGuiService', function() { |
+ |
+ var utils, Y; |
+ |
+ before(function(done) { |
+ Y = YUI(GlobalConfig).use('juju-views', function(Y) { |
+ utils = Y.namespace('juju.views.utils'); |
+ done(); |
+ }); |
+ }); |
+ |
+ it('should extract values from "charm" attribute', function() { |
+ var candidate = {charm: 'cs:precise/juju-gui-7'}; |
+ assert.isTrue(utils.isGuiService(candidate)); |
+ }); |
+ |
+ it('should extract values from .get("charm")', function() { |
+ var candidate = { |
+ get: function(name) { |
+ if (name === 'charm') { |
+ return 'cs:precise/juju-gui-7'; |
+ } |
+ } |
+ }; |
+ assert.isTrue(utils.isGuiService(candidate)); |
+ }); |
+ |
+ }); |
+})(); |
+ |
+(function() { |
+ describe('utils.isGuiCharmUrl', function() { |
+ |
+ var utils, Y; |
+ |
+ before(function(done) { |
+ Y = YUI(GlobalConfig).use('juju-views', function(Y) { |
+ utils = Y.namespace('juju.views.utils'); |
+ done(); |
+ }); |
+ }); |
+ |
+ it('should recognize charm store URLs', function() { |
+ assert.isTrue(utils.isGuiCharmUrl('cs:precise/juju-gui-7')); |
+ }); |
+ |
+ it('should recognize unofficial charm store URLs', function() { |
+ assert.isTrue(utils.isGuiCharmUrl('cs:~foobar/precise/juju-gui-7')); |
+ }); |
+ |
+ it('should ignore owners of unofficial charm store URLs', function() { |
+ assert.isFalse(utils.isGuiCharmUrl('cs:~juju-gui/precise/foobar-7')); |
+ }); |
+ |
+ it('should recognize local charm URLs', function() { |
+ assert.isTrue(utils.isGuiCharmUrl('local:juju-gui-3')); |
+ }); |
+ |
+ it('should not allow junk on the end of the URL', function() { |
+ assert.isFalse(utils.isGuiCharmUrl('local:juju-gui-3 ROFLCOPTR!')); |
+ }); |
+ |
+ }); |
+})(); |