Mercurial > bugzilla-dashboard
changeset 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 | e79a2dd66e25 |
files | black-box.html css/black-box.css js/black-box.js |
diffstat | 3 files changed, 153 insertions(+), 30 deletions(-) [+] |
line wrap: on
line diff
--- a/black-box.html Wed Apr 28 20:06:26 2010 -0700 +++ b/black-box.html Thu Apr 29 10:28:26 2010 -0700 @@ -1,14 +1,33 @@ <html> <head> <meta http-equiv="Content-type" content="text/html; charset=utf-8"/> - <title>Bugzilla Dashboard - Black Box</title> + <link rel="stylesheet" type="text/css" media="all" + href="css/black-box.css" /> + <title>Bugzilla Dashboard - Black Box</title> </head> -<body style="background: black; color: white;"> +<body> <h1 class="title">Bugzilla Dashboard - Black Box</h1> -<div style="text-align: center;"> -<iframe src="about:blank" id="dashboard" - style="width: 640px; height: 480px; border: none;"></iframe> +<p> + This page contains a Bugzilla Dashboard plugged-in to a + toy Bugzilla database. You can log into it with the + username "john@doe.com" and password "test". +</p> +<p> + You can also click on a test that automates some + common UI actions for you. +</p> +<div id="dashboard-container"> +<iframe src="about:blank" id="dashboard"></iframe> </div> +<span class="test-button" id="testLoginWithNoPassword"> + Login without Password +</span> +<span class="test-button" id="testLoginWithCorrectPassword"> + Login with Correct Password +</span> +<span class="test-button" id="testLoginWithIncorrectPassword"> + Login with Incorrect Password +</span> </body> <!-- Base Scripts --> <script src="js/jquery.js"></script>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/css/black-box.css Thu Apr 29 10:28:26 2010 -0700 @@ -0,0 +1,35 @@ +body { + background: black; + color: white; + font-family: Monaco, monospace; + font-size: 9pt; +} + +#dashboard-container { + float: left; +} + +#dashboard { + width: 640px; + height: 480px; + border: none; + margin-right: 1em; +} + +.test-button:before { + content: "Test "; +} + +.test-button { + display: block; + margin: 1em; + cursor: pointer; +} + +.running:after { + content: " (now running)"; +} + +span.test-button:hover { + background: #404040; +}
--- 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() {}); });