1 /*jshint node:true, indent:2, curly:false, eqeqeq:true, immed:true, latedef:true, newcap:true, noarg:true,
2 regexp:true, undef:true, strict:true, trailing:true, white:true */
3 /*global XT:true, XM:true, XV:true, XZ:true, enyo:true, XG:true */
11 XZ = {}; // xTuple Zombie. Used to help zombie within the context of these tests.
13 var assert = require('assert'),
14 zombie = require('zombie'),
16 _ = require('underscore');
20 Simplest possible usage:
22 var zombieTest = require('./zombie_auth');
23 zombieTest.testLoad();
28 var secondsToWait = 40;
31 Loads up the xTuple environment and makes the global variables globally available.
33 The first three options are optional, but if omitted then the login data should be
34 available in the /test/lib/loginData.js file.
36 There is one important limitation to this code at the moment: the client-side
37 app must be built. (Going in through debug.html won't work).
39 @param {Object} options
40 @param {String} options.username
41 @param {String} options.password
42 @param {String} options.host
43 @param {Boolean} options.verbose
44 @param {Function} options.callback. This function will be called with the zombie browser
45 as a parameter if the app loads up successfully.
47 Supported signatures are:
49 loadApp({username: "admin", password: "somenew", callback: callback});
50 loadApp({callback: callback, verbose: true});
52 var loadApp = exports.loadApp = function (options) {
53 options = options || {};
55 var username = options.username,
56 password = options.password,
57 database = options.database,
59 callback = options.callback,
60 verboseMode = options.verbose,
64 // Handle multiple signatures
66 if (typeof arguments[0] === 'function') {
67 // if the sole parameter is the callback, then we get the auth data from a file
68 callback = arguments[0];
71 if (!username || !password) {
73 loginData = require(options.loginDataPath || './login_data');
75 console.log("Make sure you put your login credentials in the /test/lib/login_data.js file");
79 username = loginData.data.username;
80 password = loginData.data.pwd;
81 database = loginData.data.org;
82 host = loginData.data.webaddress;
84 host = host || "https://localhost:443";
86 if (options.refreshLogin) {
94 // when we run all our tests we only want to have to log in for the first one
97 console.log("Using pre-existing zombie session");
103 var parse = URL.parse;
104 URL.parse = function (url) {
105 if (_.isObject(url) && _.isString(url.href)) {
106 return parse(url.href);
113 zombie.visit(host, {debug: verboseMode}, function (e, browser) {
115 //console.log("Zombie visit error: ", e);
118 // This is the login screen
121 .fill('id', username)
122 .fill('password', password)
123 .select('database', database)
124 .pressButton('submit', function () {
126 // Note: make sure the app is built
127 // XXX this limitation should be fixed, to allow testing off of debug.html
128 // it's possible that Zombie 2.0 will get this right.
131 // Plan to give up after a set time
133 var timeout = setTimeout(function () {
134 console.log("App did not fully load");
136 }, secondsToWait * 1000);
139 // Check frequently to see if the app is loaded, and move forward when it is
141 var interval = setInterval(function () {
143 if (browser.window.XT && browser.window.XT.app && browser.window.XT.app.state === 6) {
145 // add the global objects to our global namespace
146 enyo = browser.window.enyo;
147 XG = browser.window.XG;
148 XM = browser.window.XM;
149 XT = browser.window.XT;
150 XV = browser.window.XV;
151 XZ.browser = browser;
153 XZ.database = database;
155 XT.log = function (message, obj) {
156 if (message && message.toLowerCase().indexOf("error") === 0) {
157 // errors from the datasource should cause the test to fail
158 assert.fail(message + " " + JSON.stringify(obj));
160 // log if verbose mode or if the log is a warning
161 if (verboseMode || (message && message.code)) {
162 console.log(JSON.stringify(arguments));
167 var oldNotify = XT.app.$.postbooks.notify;
168 XT.app.$.postbooks.notify = function (notifySender, notifyObj) {
169 if (notifyObj && notifyObj.type === XM.Model.CRITICAL) {
170 assert.fail(JSON.stringify(notifyObj));
172 oldNotify(notifySender, notifyObj);
176 // WIP. Not yet working. Probably need to move it up to earlier app start status.
178 var oldLoc = XT.String.loc;
179 XT.String.loc = function (str) {
180 var localized = XT.localizeString(str);
181 if (localized === str) {
182 assert.fail(str + " has no translation");
189 // these are really annoying
190 browser.window.Backbone.Relational.showWarnings = false;
192 // clear out both is interval and the I'm-giving-up timeout
193 // we really want neither to be run again.
194 clearInterval(interval);
195 clearTimeout(timeout);
197 // give control back to whoever called us
200 }, 100); // 100 = check to see if the app is loaded every 0.1 seconds
206 More of a proof-of-concept than anything else.
208 var testLoad = exports.testLoad = function () {
209 console.log("Testing loadup of app.");
211 loadApp(function () {
212 console.log("App loaded successfully.");