Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

UT fixes and the corresponding adjustments based on the failures

  • Loading branch information...
commit 012315df08da98a756387384c548c45f3c1bb21b 1 parent 37f7d67
Caridy Patino authored
2  lib/app/addons/ac/partial.common.js
@@ -54,7 +54,7 @@ YUI.add('mojito-partial-addon', function(Y, NAME) {
54 54
55 55 mojitView = instance.views[view];
56 56 data = data || {}; // default null data to empty view template
57   - renderer = Y.mojito.ViewRenderer(mojitView.engine,
  57 + renderer = new Y.mojito.ViewRenderer(mojitView.engine,
58 58 this.ac.staticAppConfig.viewEngine);
59 59
60 60 Y.log('Rendering "' + view + '" view for "' + (instance.id || '@' +
1  lib/app/addons/view-engines/hb.client.js
@@ -177,5 +177,6 @@ YUI.add('mojito-hb', function(Y, NAME) {
177 177
178 178 }, '0.1.0', {requires: [
179 179 'io-base',
  180 + 'parallel',
180 181 'handlebars'
181 182 ]});
2  lib/app/addons/view-engines/hb.server.js
@@ -193,4 +193,4 @@ YUI.add('mojito-hb', function (Y, NAME) {
193 193
194 194 Y.namespace('mojito.addons.viewEngines').hb = HandleBarsAdapter;
195 195
196   -}, '0.1.0', {requires: ['parallel']});
  196 +}, '0.1.0', {requires: ['mojito', 'parallel']});
7 lib/app/autoload/action-context.common.js
@@ -534,9 +534,10 @@ YUI.add('mojito-action-context', function(Y, NAME) {
534 534 // Y.log('Rendering "' + meta.view.name + '" view for "' +
535 535 // (instance.id || '@' + instance.type) + '"', 'info', NAME);
536 536
537   - // we use the view renderer factory
538   - // because it provides caching capabilities for better performance
539   - renderer = Y.mojito.ViewRenderer(mojitView.engine, this.staticAppConfig.viewEngine);
  537 + // TODO: we might want to use a view renderer factory
  538 + // that can provide caching capabilities for better performance
  539 + // instead of creating objects over and over again per mojit instance
  540 + renderer = new Y.mojito.ViewRenderer(mojitView.engine, this.staticAppConfig.viewEngine);
540 541 renderer.render(data, instance, mojitView, adapter, meta, more);
541 542
542 543 } else {
17 lib/app/autoload/view-renderer.client.js
@@ -11,21 +11,21 @@ YUI.add('mojito-view-renderer', function (Y) {
11 11
12 12 'use strict';
13 13
  14 + var cache = {};
  15 +
14 16 /*
15   - * Mojito's view renderer abstraction. Will craete a rendering
16   - * engine object depending on the 'type' specified.
  17 + * Mojito's view renderer abstraction. Will plugin in the specified view
  18 + * plugin to do the rendering, depending on the 'type' specified.
17 19 * @class ViewRenderer
18 20 * @namespace Y.mojito
19 21 * @constructor
20 22 * @param {String} type view engine addon type to use
21   - * @param {String} viewId
22   - * @param {Object} options
  23 + * @param {Object} options View engines configuration.
23 24 */
24   - function Renderer(type, viewId, options) {
  25 + function Renderer(type, options) {
25 26 this._type = type || 'hb';
26   - this._viewId = viewId;
27 27 this._options = options;
28   - this._renderer = null;
  28 + this._renderer = cache[type];
29 29 }
30 30
31 31
@@ -44,7 +44,7 @@ YUI.add('mojito-view-renderer', function (Y) {
44 44 var my = this,
45 45 viewEngines = Y.mojito.addons.viewEngines,
46 46 fn = function () {
47   - callback(null, new (viewEngines[my._type])(my._viewId, my._options));
  47 + callback(null, new (viewEngines[my._type])(my._options));
48 48 };
49 49
50 50 // some perf optimization to avoid calling Y.use when
@@ -92,6 +92,7 @@ YUI.add('mojito-view-renderer', function (Y) {
92 92 return;
93 93 }
94 94 my._renderer = engine;
  95 + cache[my._type] = engine; // caching renderer instance
95 96 my._renderer.render(data, mojitType, tmpl, adapter, meta, more);
96 97 });
97 98 } else {
22 lib/app/autoload/view-renderer.server.js
@@ -7,7 +7,7 @@
7 7 /*jslint anon:true, nomen:true*/
8 8 /*global YUI*/
9 9
10   -YUI.add('mojito-view-renderer', function(Y) {
  10 +YUI.add('mojito-view-renderer', function (Y) {
11 11
12 12 'use strict';
13 13
@@ -15,10 +15,7 @@ YUI.add('mojito-view-renderer', function(Y) {
15 15
16 16 /*
17 17 * Mojito's view renderer abstraction. Will plugin in the specified view
18   - * plugin to do the rendering, depending on the 'type' specified. This Class
19   - * can also be used as a factory to avoid creating renderer objects, and to
20   - * do so, you just need to call `Y.mojito.ViewRenderer('hb', {});` and it will
21   - * return the cached engine instead of creating a facade for it.
  18 + * plugin to do the rendering, depending on the 'type' specified.
22 19 * @class ViewRenderer
23 20 * @namespace Y.mojito
24 21 * @constructor
@@ -26,16 +23,15 @@ YUI.add('mojito-view-renderer', function(Y) {
26 23 * @param {Object} options View engines configuration.
27 24 */
28 25 function Renderer(type, options) {
29   - type = type || 'hb';
30   - if (!cache[type]) {
31   - this._renderer = cache[type] = new (Y.mojito.addons.viewEngines[type])(options);
32   - } else {
33   - this._renderer = cache[type];
  26 + this._type = type || 'hb';
  27 + this._options = options;
  28 + if (!cache[this._type]) {
  29 + // caching renderer instance
  30 + cache[this._type] = new (Y.mojito.addons.viewEngines[this._type])(options);
34 31 }
35   - return cache[type];
  32 + this._renderer = cache[type];
36 33 }
37 34
38   -
39 35 Renderer.prototype = {
40 36
41 37 /*
@@ -50,7 +46,7 @@ YUI.add('mojito-view-renderer', function(Y) {
50 46 * @param {boolean} more Whether there will be more data to render
51 47 * later. (streaming)
52 48 */
53   - render: function(data, mojitType, tmpl, adapter, meta, more) {
  49 + render: function (data, mojitType, tmpl, adapter, meta, more) {
54 50 this._renderer.render(data, mojitType, tmpl, adapter, meta, more);
55 51 }
56 52
30 tests/unit/lib/app/addons/ac/test-partial.common.js
@@ -8,15 +8,23 @@ YUI().use('mojito-partial-addon', 'test', function (Y) {
8 8 var suite = new Y.Test.Suite('mojito-partial-addon tests'),
9 9 Assert = Y.Assert,
10 10 ObjectAssert = Y.ObjectAssert,
11   - Mock = Y.Mock;
  11 + Mock = Y.Mock,
  12 + ac;
12 13
13 14 suite.add(new Y.Test.Case({
14 15
15 16 name: 'render() tests',
16 17
  18 + 'setUp': function () {
  19 + ac = {
  20 + staticAppConfig: {
  21 + viewEngine: {}
  22 + }
  23 + };
  24 + },
  25 +
17 26 'test callback called with error when view is not found': function() {
18   - var ac = {},
19   - command = {
  27 + var command = {
20 28 instance: {
21 29 views: {}
22 30 }
@@ -35,8 +43,7 @@ YUI().use('mojito-partial-addon', 'test', function (Y) {
35 43 },
36 44
37 45 'test correctly invokes named view engine': function() {
38   - var ac = {},
39   - data = { key: 'value' },
  46 + var data = { key: 'value' },
40 47 command = {
41 48 instance: {
42 49 type: 'myInstanceType',
@@ -60,7 +67,7 @@ YUI().use('mojito-partial-addon', 'test', function (Y) {
60 67 var mockYMojito = Mock();
61 68 Mock.expect(mockYMojito, {
62 69 method: 'ViewRenderer',
63   - args: ['myViewEngine'],
  70 + args: ['myViewEngine', ac.staticAppConfig.viewEngine],
64 71 returns: mockRenderer
65 72 });
66 73
@@ -76,8 +83,7 @@ YUI().use('mojito-partial-addon', 'test', function (Y) {
76 83 },
77 84
78 85 'test passes a valid adapter to the view engine': function() {
79   - var ac = {},
80   - command = {
  86 + var command = {
81 87 instance: {
82 88 views: {
83 89 myView: {}
@@ -138,11 +144,9 @@ YUI().use('mojito-partial-addon', 'test', function (Y) {
138 144 Mock.Value.Object
139 145 ]
140 146 });
141   - var ac = {
142   - command: command,
143   - context: 'myContext',
144   - _dispatch: mockDispatch.dispatch
145   - };
  147 + ac.command = command;
  148 + ac.context = 'myContext';
  149 + ac._dispatch = mockDispatch.dispatch;
146 150
147 151 var addon = new Y.mojito.addons.ac.partial(command, null, ac);
148 152 addon.invoke('myAction', options, null);
8 tests/unit/lib/app/autoload/test-action-context.common.js
@@ -467,12 +467,14 @@ YUI().use('mojito-action-context', 'test', function (Y) {
467 467 Y.mojito.ViewRenderer = function(engine) {
468 468 A.areSame('engine', engine, 'bad view engine');
469 469 return {
470   - render: function(d, type, v, a, m, more) {
  470 + render: function(d, mojitType, v, a, m, more) {
471 471 vrRendered = true;
472 472 A.areSame(data, d, 'bad data to view');
473   - A.areSame('t', type, 'bad mojitType to view');
  473 + A.isObject(mojitType, 'mojitType should be the expanded instance');
  474 + A.areSame('t', mojitType.type, 'bad mojitType to view');
474 475 A.areSame(meta, m, 'bad meta to view');
475   - A.areSame('path', v, 'bad view content path to view engine');
  476 + A.isObject(v, 'view object from store with the proper view info');
  477 + A.areSame('path', v['content-path'], 'bad view content path to view engine');
476 478 A.areSame(ac._adapter, a, 'bad adapter to view');
477 479 A.isFalse(more);
478 480 }
14 tests/unit/lib/app/autoload/test-view-renderer.client.js
@@ -30,7 +30,7 @@ YUI.add('mojito-view-renderer-client-tests', function(Y, NAME) {
30 30 'test instantiating a renderer engine': function () {
31 31 var vr;
32 32
33   - vr = new Y.mojito.ViewRenderer('foo', 'someviewid', {z:99});
  33 + vr = new Y.mojito.ViewRenderer('foo', {z:99});
34 34 A.isObject(vr);
35 35 // less restrictive initialization
36 36 vr = new Y.mojito.ViewRenderer('bar');
@@ -40,15 +40,14 @@ YUI.add('mojito-view-renderer-client-tests', function(Y, NAME) {
40 40 'test render method with valid engine': function () {
41 41 var args;
42 42 var ve = Y.namespace('mojito.addons.viewEngines');
43   - ve.foo = function(viewId, options) {
44   - A.areSame('someviewid', viewId);
  43 + ve.foo = function(options) {
45 44 A.areSame(99, options.z);
46 45 };
47 46 ve.foo.prototype.render = function(data, mojitType, tmpl, adapter, meta, more) {
48 47 args = arguments;
49 48 };
50 49
51   - var vr = new Y.mojito.ViewRenderer('foo', 'someviewid', {z:99});
  50 + var vr = new Y.mojito.ViewRenderer('foo', {z:99});
52 51 vr.render(1,2,3,4,5,6);
53 52 A.areSame(6, args.length);
54 53 A.areSame(1, args[0]);
@@ -64,8 +63,7 @@ YUI.add('mojito-view-renderer-client-tests', function(Y, NAME) {
64 63
65 64 YUI.add('mojito-fakebarengine', function (Y) {
66 65 var ve = Y.namespace('mojito.addons.viewEngines');
67   - ve.fakebarengine = function(viewId, options) {
68   - A.areSame('someviewid', viewId);
  66 + ve.fakebarengine = function(options) {
69 67 A.areSame(99, options.z);
70 68 };
71 69 ve.fakebarengine.prototype.render = function(data, mojitType, tmpl, adapter, meta, more) {
@@ -73,7 +71,7 @@ YUI.add('mojito-view-renderer-client-tests', function(Y, NAME) {
73 71 };
74 72 });
75 73
76   - var vr = new Y.mojito.ViewRenderer('fakebarengine', 'someviewid', {z:99});
  74 + var vr = new Y.mojito.ViewRenderer('fakebarengine', {z:99});
77 75 vr.render(1,2,3,4,5,6);
78 76 this.wait(function () {
79 77 A.areSame(6, args.length);
@@ -90,7 +88,7 @@ YUI.add('mojito-view-renderer-client-tests', function(Y, NAME) {
90 88 'test render method with invalid ondemand engine': function () {
91 89 var err;
92 90
93   - var vr = new Y.mojito.ViewRenderer('fakebazengine', 'someviewid', {z:99});
  91 + var vr = new Y.mojito.ViewRenderer('fakebazengine', {z:99});
94 92 vr.render(1,2,3, {
95 93 error: function () {
96 94 err = true;
7 tests/unit/lib/app/autoload/test-view-renderer.server.js
@@ -21,8 +21,7 @@ YUI.add('mojito-view-renderer-server-tests', function(Y, NAME) {
21 21 setUp: function() {
22 22 var ve = Y.namespace('mojito.addons.viewEngines');
23 23
24   - ve.foo = function(viewId, options) {
25   - A.areSame('someviewid', viewId);
  24 + ve.foo = function(options) {
26 25 A.areSame(99, options.z);
27 26 };
28 27
@@ -43,11 +42,11 @@ YUI.add('mojito-view-renderer-server-tests', function(Y, NAME) {
43 42
44 43 A.isObject(Y.mojito.addons);
45 44 A.isFunction(Y.mojito.ViewRenderer);
46   - var vr = new Y.mojito.ViewRenderer('foo', 'someviewid', {z:99});
  45 + var vr = new Y.mojito.ViewRenderer('foo', {z:99});
47 46 },
48 47
49 48 'test mock render method': function () {
50   - var vr = new Y.mojito.ViewRenderer('foo', 'someviewid', {z:99});
  49 + var vr = new Y.mojito.ViewRenderer('foo', {z:99});
51 50 vr.render(1,2,3,4,5,6);
52 51 }
53 52

0 comments on commit 012315d

Please sign in to comment.
Something went wrong with that request. Please try again.