Mercurial > bugzilla-dashboard
diff js/black-box.js @ 110:4567dc69cb3e
Added failure messages and more color feedback to black-box tests
author | Atul Varma <avarma@mozilla.com> |
---|---|
date | Fri, 30 Apr 2010 05:26:01 -0700 |
parents | 8335b1abc295 |
children | 00d6b3149165 |
line wrap: on
line diff
--- a/js/black-box.js Fri Apr 30 05:10:10 2010 -0700 +++ b/js/black-box.js Fri Apr 30 05:26:01 2010 -0700 @@ -1,6 +1,7 @@ -function Automator(window, jQuery, onDone) { +function Automator(window, jQuery, onDone, onFail) { this.jQuery = jQuery; this.onDone = onDone; + this.onFail = onFail; this.queue = []; this.window = window; } @@ -24,10 +25,10 @@ var query = this.jQuery(sel); if (query.length == 0) - throw new Error("selector yields no results: " + sel); + this.onFail("selector yields no results: " + sel); if (query.length > 1) - throw new Error("selector yields " + query.length + - " results instead of 1: " + sel); + this.onFail("selector yields " + query.length + + " results instead of 1: " + sel); return query; }, @@ -37,7 +38,7 @@ var query = this.jQuery(field + ":visible"); if (query.length == 0) - throw new Error("selector not visible: " + field); + this.onFail("selector not visible: " + field); }); }, type: function type(field, value) { @@ -48,6 +49,13 @@ } }; +function testLoginWithNoPassword(auto) { + auto.type("#login .username", "john@doe.com"); + auto.type("#login .password", ""); + auto.submit("#login form"); + auto.verifyVisible("#header .requires-login"); +} + function testLoginWithCorrectPassword(auto) { auto.type("#login .username", "john@doe.com"); auto.type("#login .password", "test"); @@ -56,13 +64,6 @@ auto.verifyVisible("#header .requires-auth-login"); } -function testLoginWithNoPassword(auto) { - auto.type("#login .username", "john@doe.com"); - auto.type("#login .password", ""); - auto.submit("#login form"); - auto.verifyVisible("#header .requires-login"); -} - function testLoginWithIncorrectPassword(auto) { auto.type("#login .username", "john@doe.com"); auto.type("#login .password", "u"); @@ -118,8 +119,19 @@ var auto; $(testButton).addClass("running"); + function onFail(reason) { + $(testButton).addClass("fail"); + var msg = ("Failure in " + $(testButton).text() + ": " + + reason); + var msgElem = $('<p class="fail"></p>').text(msg); + msgElem.hide(); + $("#messages").append(msgElem); + msgElem.slideDown(); + } function onDone() { $(testButton).removeClass("running"); + if (!$(testButton).hasClass("fail")) + $(testButton).addClass("success"); } resetDashboard( @@ -128,7 +140,8 @@ case "blackBox.onDashboardLoaded": var dashboard = args[0]; var options = args[1]; - auto = new Automator(window, options.jQuery, onDone); + auto = new Automator(window, options.jQuery, onDone, + onFail); testFunc(auto); break; case "blackBox.afterInit":