Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

moving tests around to accomodate routines changes as part of the par…

…tials support refactor
  • Loading branch information...
commit 228cbfbe0ae13a3596c7d8cc8167f5db64da416e 1 parent 6b33872
@caridy authored
View
161 tests/unit/lib/app/autoload/test-action-context.common.js
@@ -503,7 +503,7 @@ YUI().use('mojito-action-context', 'test', function (Y) {
acAddons: [],
views: {
viewName: {
- engine: 'engine',
+ 'engine': 'engine',
'content-path': 'path'
}
}
@@ -570,7 +570,7 @@ YUI().use('mojito-action-context', 'test', function (Y) {
};
// mock view renderer
var VR = Y.mojito.ViewRenderer;
- Y.mojito.ViewRenderer = function(engine) {
+ Y.mojito.ViewRenderer = function() {
return {
render: function(d, type, v, a, m, more) {
a.done('html', m);
@@ -895,163 +895,6 @@ YUI().use('mojito-action-context', 'test', function (Y) {
}
A.isNotUndefined(error);
A.areSame("Missing view template: 'index'", error.message.toString());
- },
-
- 'test server-side view caching': function() {
- var command = {
- action: 'index',
- context: {
- runtime: 'server'
- },
- instance: {
- id: 'id',
- type: 'TypeGeneral',
- acAddons: [],
- views: {
- index: {
- engine: 'mockViewEngine',
- 'content-path': 'path'
- }
- }
- }
- };
- var adapter = {
- done: function(data, meta) {},
- error: function(err) {}
- };
-
- var ac, error;
- var rendererCtorCalled = 0,
- rendererRenderCalled = 0;
-
- Y.mojito.addons.viewEngines.mockViewEngine = function() {
- rendererCtorCalled += 1;
- this.render = function(data, type, path, in_adapter, meta, more) {
- rendererRenderCalled += 1;
- A.areSame('done', data.status);
- A.areSame('TypeGeneral', type);
- A.areSame('path', path);
- A.areSame(adapter, in_adapter);
- A.areSame('index', meta.view.name);
- A.isFalse(!!more);
- };
- return this;
- };
- try {
- ac = new Y.mojito.ActionContext({
- dispatch: 'the dispatch',
- command: command,
- controller: {
- index: function(ac) {
- ac.done({status: 'done'});
- }
- },
- store: store,
- adapter: adapter
- });
- } catch(err) {
- error = err;
- }
- A.isUndefined(error);
- A.areSame(1, rendererCtorCalled);
- A.areSame(1, rendererRenderCalled);
-
- // second time, should use cache
- try {
- ac = new Y.mojito.ActionContext({
- dispatch: 'the dispatch',
- command: command,
- controller: {
- index: function(ac) {
- ac.done({status: 'done'});
- }
- },
- store: store,
- adapter: adapter
- });
- } catch(err) {
- error = err;
- }
- A.areEqual('', error, 'no error');
- A.isUndefined(error);
- A.areSame(1, rendererCtorCalled);
- A.areSame(2, rendererRenderCalled);
- },
-
- 'test pathToRoot for views': function() {
- var store = {
- getAppConfig: function() {
- return {
- pathToRoot: '/path/to/root/'
- };
- },
- getStaticContext: function() {
- return 'static context';
- },
- getRoutes: function(ctx) {
- return 'routes';
- }
- };
- var command = {
- action: 'index',
- context: {
- runtime: 'server'
- },
- instance: {
- id: 'id',
- type: 'TypeGeneral',
- acAddons: [],
- views: {
- index: {
- engine: 'engine-in-instance',
- 'content-path': 'path/in/instance'
- }
- }
- }
- };
- var adapter = {
- done: function(data, meta) {},
- error: function(err) {}
- };
- var renderCalled = false;
- Y.mojito.addons.viewEngines.mockViewEngine2 = function() {
- this.render = function(data, type, path, in_adapter, meta, more) {
- renderCalled = true;
- A.areSame('done', data.status);
- A.areSame('TypeGeneral', type);
- A.areSame('/path/to/root/path/in/meta', path);
- A.areSame(adapter, in_adapter);
- A.areSame('index', meta.view.name);
- A.isFalse(!!more);
- };
- return this;
- };
- var ac, error;
- try {
- ac = new Y.mojito.ActionContext({
- dispatch: 'the dispatch',
- command: command,
- controller: {
- index: function(ac) {
- ac.done({
- status: 'done'
- }, {
- view: {
- 'engine': 'mockViewEngine2',
- 'content-path': 'path/in/meta'
- }
- });
- }
- },
- store: store,
- adapter: adapter
- });
- } catch(err) {
- error = err;
- }
- A.areEqual('', error, 'no error');
- A.isUndefined(error, 'no error');
- A.isTrue(renderCalled, 'render called');
}
}));
View
67 tests/unit/lib/app/autoload/test-view-renderer.server.js
@@ -9,45 +9,74 @@
/*global YUI*/
YUI.add('mojito-view-renderer-server-tests', function(Y, NAME) {
+
+ 'use strict';
+
var suite = new Y.Test.Suite(NAME),
A = Y.Assert,
AA = Y.ArrayAssert,
- OA = Y.ObjectAssert;
+ OA = Y.ObjectAssert,
+ ve;
+
+ Y.namespace('mojito.addons');
suite.add(new Y.Test.Case({
name: 'mojito-view-renderer',
setUp: function() {
- var ve = Y.namespace('mojito.addons.viewEngines');
-
- ve.foo = function(options) {
- A.areSame(99, options.z);
- };
-
- ve.foo.prototype.render = function(data, mojitType, tmpl, adapter, meta, more) {
- A.areSame(6, arguments.length);
- A.areSame(1, arguments[0]);
- A.areSame(2, arguments[1]);
- A.areSame(3, arguments[2]);
- A.areSame(4, arguments[3]);
- A.areSame(5, arguments[4]);
- A.areSame(6, arguments[5]);
- };
+ // resetting the available engines
+ ve = Y.mojito.addons.viewEngines = {};
},
tearDown: function() {},
- 'test instantiating a mock renderer': function () {
-
+ 'test structures': function () {
A.isObject(Y.mojito.addons);
A.isFunction(Y.mojito.ViewRenderer);
+ },
+
+ 'test ctor': function () {
+ ve.foo = function(options) {
+ A.areSame(99, options.z);
+ };
+
var vr = new Y.mojito.ViewRenderer('foo', {z:99});
+
+ A.isObject(vr);
+ A.isFunction(vr.render);
},
'test mock render method': function () {
- var vr = new Y.mojito.ViewRenderer('foo', {z:99});
+ ve.bar = function() {};
+
+ ve.bar.prototype = {
+ render: function(data, mojitType, tmpl, adapter, meta, more) {
+ A.areSame(6, arguments.length);
+ A.areSame(1, arguments[0]);
+ A.areSame(2, arguments[1]);
+ A.areSame(3, arguments[2]);
+ A.areSame(4, arguments[3]);
+ A.areSame(5, arguments[4]);
+ A.areSame(6, arguments[5]);
+ }
+ };
+
+ var vr = new Y.mojito.ViewRenderer('bar', {z:99});
vr.render(1,2,3,4,5,6);
+ },
+
+ 'test view engine caching machanism': function() {
+ var rendererCtorCalled = 0;
+
+ ve.mockViewEngine = function() {
+ rendererCtorCalled += 1;
+ };
+
+ var obj1 = new Y.mojito.ViewRenderer('mockViewEngine', {z:99});
+ var obj2 = new Y.mojito.ViewRenderer('mockViewEngine', {z:99});
+
+ A.areSame(1, rendererCtorCalled, 'renderer constructor should be called once and then cached by engine name');
}
}));
Please sign in to comment.
Something went wrong with that request. Please try again.