HTMLFrameMojit enhancements #353

Closed
wants to merge 3 commits into from
View
5 source/lib/app/commands/test.js
@@ -711,7 +711,10 @@ runTests = function(opts) {
configureYUI(YUI, store);
if (testType === 'fw') {
- testConfigs = store.yui.getConfigShared('server', {}, true).modules;
+ testConfigs = merge(
+ store.yui.getConfigShared('server', {}, true).modules,
+ store.yui.getConfigAllMojits('server', {}).modules
+ );
} else if (testType === 'app') {
testConfigs = merge(
store.yui.getConfigShared('server', {}, true).modules,
View
5 source/lib/app/mojits/HTMLFrameMojit/controller.server.js
@@ -51,11 +51,14 @@ YUI.add('HTMLFrameMojit', function(Y, NAME) {
Y.namespace('mojito.controllers')[NAME] = {
+ init: function (config) {
+ this.config = config;
+ },
+
index: function(ac) {
this.__call(ac);
},
-
__call: function(ac) {
// Grab the "child" from the config an add it as the
View
107 source/lib/app/mojits/HTMLFrameMojit/tests/controller.server-tests.js
@@ -1,107 +0,0 @@
-/*
- * Copyright (c) 2011-2012, Yahoo! Inc. All rights reserved.
- * Copyrights licensed under the New BSD License.
- * See the accompanying LICENSE file for terms.
- */
-
-/*jslint anon:true, sloppy:true, nomen:true, node:true*/
-
-YUI.add('HTMLFrameMojit-tests', function(Y, NAME) {
-
- var pathlib = require('path'),
- mojitoPath = pathlib.join(__dirname, '../..'),
- targetMojitoPath = mojitoPath,
- fwTestsRoot = pathlib.join(targetMojitoPath, 'tests'),
- YUITest = require('yuitest').YUITest,
- suite = new YUITest.TestSuite(NAME),
- A = YUITest.Assert;
-
- suite.add(new YUITest.TestCase({
-
- name: 'HTMLFrameMojit user tests',
-
- 'test ctor()': function() {
- var controller = new Y.mojit.test.HTMLFrameMojit.controller(
- {
- assetManager: {x: 'y'}
- }
- );
- A.isNotNull(controller);
- A.isFunction(controller.index);
- Y.mojit.test.areEqualRecursive({ assetManager: {x: 'y'} },
- controller._cfg);
- A.isInstanceOf(Y.mojito.AssetManager, controller._assetMgr);
- Y.mojit.test.areEqualRecursive({x: 'y'}, controller._assetMgr._cfg);
-
- controller = new Y.mojit.test.HTMLFrameMojit.controller({
- assets: [
- 'a',
- {
- type: 'blob',
- location: 'top',
- content: 'b'
- },
- 'c'
- ]
- });
- A.areEqual("b\n", controller._assetMgr.getAssets('top'));
- A.areEqual("a\nc\n", controller._assetMgr.getAssets('bottom'));
- },
-
- 'test index()': function() {
-
- var controller = new Y.mojit.test.HTMLFrameMojit.controller({
- child: 'child-1'
- }),
- dispatchCalled,
- doneCalled,
- ac = {
- params: function() {
- return { count: 5, size: 'small' };
- },
- dispatch: function(child, action, params, cbs) {
- dispatchCalled = {
- child: child,
- action: action,
- params: params,
- cbs: Y.Object.keys(cbs)
- };
- // do what a child would:
- cbs.addAsset('blob', 'top', 'a');
- cbs.addAsset('blob', 'bottom', 'b');
- cbs.done('orange', 'red');
- },
- done: function(data, viewMeta) {
- doneCalled = {
- data: data,
- viewMeta: viewMeta
- };
- },
- addAsset: function(type, location, content) {
- A.fail("HTMLFrameMojit called it's ac.addAsset()");
- }
- };
-
- controller.index(ac);
- Y.mojit.test.areEqualRecursive({
- child: 'child-1',
- action: 'index',
- params: { count: 5, size: 'small' },
- cbs: [ 'flush', 'done', 'addAsset' ]
- }, dispatchCalled);
- Y.mojit.test.areEqualRecursive({
- data: {
- mojito_version: '0.1.0',
- assets_top: "a\n",
- assets_bottom: "b\n",
- child: 'orange'
- },
- viewMeta: undefined
- }, doneCalled);
- }
-
- }));
-
- YUITest.TestRunner.add(suite);
-
-}, '0.1.0', {requires: ['mojito-test', 'HTMLFrameMojit']});
View
153 source/lib/tests/autoload/mojits/HTMLFrameMojit/controller.server-tests.js
@@ -0,0 +1,153 @@
+/*
+ * Copyright (c) 2011-2012, Yahoo! Inc. All rights reserved.
+ * Copyrights licensed under the New BSD License.
+ * See the accompanying LICENSE file for terms.
+ */
+
+/*global YUI, YUITest*/
+/*jslint anon:true, sloppy:true, nomen:true, node:true*/
+
+YUI.add('HTMLFrameMojit-tests', function(Y, NAME) {
+
+ var suite = new YUITest.TestSuite(NAME),
+ A = YUITest.Assert,
+ AA = YUITest.ArrayAssert,
+ OA = YUITest.ObjectAssert,
+ controller;
+
+ suite.add(new YUITest.TestCase({
+
+ name: 'HTMLFrameMojit user tests',
+
+ // setUp for every testcase
+ setUp: function () {
+ controller = Y.clone(Y.mojito.controllers.HTMLFrameMojit);
+ },
+
+ // tearDown for every testcase
+ tearDown: function () {
+ controller = null;
+ },
+
+ 'test action on child mojit': function() {
+
+ var dispatchCalled,
+ executeCalled,
+ ac = {
+ action: 'index',
+ config: {
+ get: function (name) {
+ return controller.config[name];
+ }
+ },
+ composite: {
+ execute: function (cfg, callback) {
+ executeCalled = {
+ cfg: cfg
+ };
+ }
+ }
+ };
+
+ // default action
+ controller.init({
+ child: {
+ base: "child-1"
+ }
+ });
+ controller.index(ac);
+ A.isObject(executeCalled, 'ac.composite.execute was not executed');
+ A.areEqual('index', executeCalled.cfg.children.child.action, 'the default action index was not set');
+
+ // custom action
+ controller.init({
+ child: {
+ base: "child-1",
+ action: "custom"
+ }
+ });
+ controller.index(ac);
+ A.isObject(executeCalled, 'ac.composite.execute was not executed');
+ A.areEqual('custom', executeCalled.cfg.children.child.action, 'the custom action was not honored');
+
+ },
+
+ 'test index()': function() {
+
+ var dispatchCalled,
+ doneCalled,
+ executeCalled,
+ assetsAdded,
+ ac = {
+ config: {
+ get: function (name) {
+ return controller.config[name];
+ }
+ },
+ composite: {
+ execute: function (cfg, callback) {
+ executeCalled = {
+ cfg: cfg
+ };
+ callback({}, {
+ metaFromChildGoesHere: true,
+ assets: {
+ bottom: {}
+ }
+ });
+ }
+ },
+ done: function(data, viewMeta) {
+ doneCalled = {
+ data: data,
+ viewMeta: viewMeta
+ };
+ },
+ assets: {
+ getAssets: function() {
+ return [];
+ },
+ addAssets: function(assets) {
+ assetsAdded = assets;
+ }
+ }
+ };
+
+ controller.init({
+ child: {
+ base: "child-1"
+ },
+ deploy: false
+ });
+
+ controller.index(ac);
+ A.isObject(executeCalled, 'ac.composite.execute was not called');
+ A.areEqual('child-1', executeCalled.cfg.children.child.base, 'the child base config was not honored');
+
+ A.isObject(doneCalled, 'ac.done was not called');
+
+ A.isString(doneCalled.data.mojito_version, 'mojito_version is required');
+ A.isString(doneCalled.data.title, 'title is required');
+
+ A.isTrue(doneCalled.viewMeta.metaFromChildGoesHere, 'meta should be passed into done');
+ A.areEqual('index', doneCalled.viewMeta.view.name, 'the view name should always be index');
+
+ A.isObject(assetsAdded, 'ac.assets.addAssets was not called');
+ A.isObject(doneCalled.viewMeta.assets.bottom, 'assets coming from the child should be inserted in the correct position');
+ },
+
+ 'TODO: deploy flag': function() {
+ A.skip();
+ return;
+ },
+
+ 'TODO: global assets': function() {
+ A.skip();
+ return;
+ }
+
+ }));
+
+ YUITest.TestRunner.add(suite);
+
+}, '0.1.0', {requires: ['HTMLFrameMojit']});