Mercurial > bugzilla-dashboard
diff js/black-box.js @ 103:a994fc89f341
added semi-automated system tests to black box.
author | Atul Varma <avarma@mozilla.com> |
---|---|
date | Thu, 29 Apr 2010 10:28:26 -0700 |
parents | 00b02ba5236c |
children | aad1c0a17ba4 |
line wrap: on
line diff
--- a/js/black-box.js Wed Apr 28 20:06:26 2010 -0700 +++ b/js/black-box.js Thu Apr 29 10:28:26 2010 -0700 @@ -1,36 +1,105 @@ -function onDashboardLoaded(dashboard, options) { - var require = Require.build(Require.modules, {window: window}); +function testLoginWithCorrectPassword($) { + return [ + function() { $("#login .username").val("john@doe.com"); + $("#login .password").val("test"); }, + function() { $("#login form").submit(); } + ]; +} - // Needed for Firebug, which won't log iframe errors to the console. - $(dashboard).error( - function(event) { - console.warn("An error occurred in the dashboard iframe."); - }); +function testLoginWithNoPassword($) { + return [ + function() { $("#login .username").val("john@doe.com"); + $("#login .password").val(""); }, + function() { $("#login form").submit(); } + ]; +} - var moduleExports = {}; - var dbrequire = dashboard.Require.build(dashboard.Require.modules, - moduleExports); +function testLoginWithIncorrectPassword($) { + return [ + function() { $("#login .username").val("john@doe.com"); + $("#login .password").val("wrong"); }, + function() { $("#login form").submit(); } + ]; +} - function delegate(method, args) { - console.log(method, args); - } +function setDashboardLoaded(delegate, window) { + window.onDashboardLoaded = function onDashboardLoaded(dashboard, options) { + $(dashboard).error( + function(event) { + if (window.console) + window.console.warn("An error occurred in the dashboard iframe."); + }); - // Get rid of any form values cached by the browser. - options.jQuery("input[type=text], input[type=password]").val(""); + delegate("blackBox.onDashboardLoaded", [dashboard, options]); + + var require = Require.build(Require.modules, {window: window}); + + var moduleExports = {}; + var dbrequire = dashboard.Require.build(dashboard.Require.modules, + moduleExports); + + // Get rid of any form values cached by the browser. + options.jQuery("input[type=text], input[type=password]").val(""); - var ajaxImpl = require("mocks/bugzilla/trivial").makeAjaxImpl(); - options.cache = require("mocks/cache").create(delegate); - options.Bugzilla = require("mocks/bugzilla").create(options.Bugzilla, - ajaxImpl, - delegate); - dbrequire("date-utils").now = function() { - return new Date("Tue Apr 27 2010 09:00:00 GMT"); + var ajaxImpl = require("mocks/bugzilla/trivial").makeAjaxImpl(); + options.cache = require("mocks/cache").create(delegate); + options.Bugzilla = require("mocks/bugzilla").create(options.Bugzilla, + ajaxImpl, + delegate); + dbrequire("date-utils").now = function() { + return new Date("Tue Apr 27 2010 09:00:00 GMT"); + }; + + delegate("blackBox.beforeInit", []); + dbrequire("app/loader").init(moduleExports, options); + delegate("blackBox.afterInit", []); }; - dbrequire("app/loader").init(moduleExports, options); +} + +function resetDashboard(delegate) { + setDashboardLoaded(delegate, window); + var iframe = $("#dashboard").get(0); + iframe.src = "index.html?testing=1"; } $(window).ready( function() { - var iframe = $("#dashboard").get(0); - iframe.src = "index.html?testing=1"; + $(".test-button").click( + function() { + var testButton = this; + var testFunc = window[testButton.id]; + var cmds = []; + const COMMAND_DELAY = 500; + + function queueNextCommand() { + if (cmds.length) + window.setTimeout(nextCommand, COMMAND_DELAY); + else { + $(testButton).removeClass("running"); + } + } + + function nextCommand() { + var cmd = cmds.shift(); + cmd(); + queueNextCommand(); + } + + $(testButton).addClass("running"); + + resetDashboard( + function(method, args) { + switch (method) { + case "blackBox.onDashboardLoaded": + var dashboard = args[0]; + var options = args[1]; + cmds = testFunc(options.jQuery); + break; + case "blackBox.afterInit": + queueNextCommand(); + break; + } + }); + }); + resetDashboard(function() {}); });