Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(637)

Unified Diff: test/test_utils.js

Issue 7195047: Environment relation tests and refactor
Patch Set: Environment relation tests and refactor Created 12 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/test_topology_relation.js ('k') | undocumented » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/test_utils.js
=== modified file 'test/test_utils.js'
--- test/test_utils.js 2013-01-17 20:28:28 +0000
+++ test/test_utils.js 2013-01-24 16:46:38 +0000
@@ -406,3 +406,128 @@
});
})();
+
+(function() {
+ describe('DecoratedRelation', function() {
+
+ var utils, views, Y, inputRelation, source, target;
+
+ before(function(done) {
+ Y = YUI(GlobalConfig).use('juju-views', function(Y) {
+ utils = Y.namespace('juju.views.utils');
+ views = Y.namespace('juju.views');
+ done();
+ });
+ });
+
+ beforeEach(function() {
+ source = {
+ modelId: function() {
+ return 'source-id';
+ }
+ };
+ target = {
+ modelId: function() {
+ return 'target-id';
+ }
+ };
+ inputRelation = {
+ getAttrs: function() {
+ return {};
+ }
+ };
+
+ });
+
+ it('mirrors the relation\'s properties', function() {
+ var relation = {
+ getAttrs: function() {
+ return {foo: 'bar'};
+ }
+ };
+ relation = views.DecoratedRelation(relation, source, target);
+ assert.deepProperty(relation, 'foo');
+ assert.equal(relation.foo, 'bar');
+ });
+
+ it('exposes the source and target as attributes', function() {
+ var relation = views.DecoratedRelation(inputRelation, source, target);
+ assert.equal(relation.source, source);
+ assert.equal(relation.target, target);
+ });
+
+ it('generates an ID that includes source and target IDs', function() {
+ var relation = views.DecoratedRelation(inputRelation, source, target);
+ assert.match(relation.compositeId, new RegExp(source.modelId()));
+ assert.match(relation.compositeId, new RegExp(target.modelId()));
+ });
+
+ it('includes endpoint names in its ID, if they exist', function() {
+ var source = {
+ modelId: function() {
+ return 'source-id';
+ }
+ };
+ var target = {
+ modelId: function() {
+ return 'target-id';
+ }
+ };
+ var firstEndpointName = 'endpoint-1';
+ var secondEndpointName = 'endpoint-2';
+ inputRelation.endpoints = [
+ [null, {name: firstEndpointName}],
+ [null, {name: secondEndpointName}]
+ ];
+ var relation = views.DecoratedRelation(inputRelation, source, target);
+ assert.match(relation.compositeId, new RegExp(firstEndpointName));
+ assert.match(relation.compositeId, new RegExp(secondEndpointName));
+ });
+
+ it('exposes the fact that a relation is a subordinate', function() {
+ var inputRelation = {
+ getAttrs: function() {
+ return {scope: 'container'};
+ }
+ };
+ var relation = views.DecoratedRelation(inputRelation, source, target);
+ assert.isTrue(relation.isSubordinate);
+ });
+
+ it('exposes the fact that a relation is not a subordinate', function() {
+ var inputRelation = {
+ getAttrs: function() {
+ return {scope: 'not-container'};
+ }
+ };
+ var relation = views.DecoratedRelation(inputRelation, source, target);
+ assert.isFalse(relation.isSubordinate);
+ });
+
+ });
+})();
+
+(function() {
+ describe('utils.isSubordinateRelation', function() {
+
+ var utils, Y;
+
+ before(function(done) {
+ Y = YUI(GlobalConfig).use('juju-views', function(Y) {
+ utils = Y.namespace('juju.views.utils');
+ done();
+ });
+ });
+
+ it('can tell if a relation is a subordinate', function() {
+ var relation = {scope: 'container'};
+ assert.isTrue(utils.isSubordinateRelation(relation));
+ });
+
+ it('can tell if a relation is not a subordinate', function() {
+ var relation = {scope: 'not-a-container'};
+ assert.isFalse(utils.isSubordinateRelation(relation));
+ });
+
+ });
+})();
« no previous file with comments | « test/test_topology_relation.js ('k') | undocumented » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b