Permalink
Browse files

Merge pull request #1 from aerogear/master

Cleaned up some files and added unit tests
  • Loading branch information...
2 parents d39eb2c + 0753c20 commit 4ed39ab223bf26e0baf991ba9d723c560e20c751 @knrc knrc committed Aug 13, 2012
@@ -58,7 +58,7 @@ function( namespace, $, $m, Backbone, Main, Catalog, Cart, Orders, messageTempla
},
catalog: function() {
- namespace.transitioner( new Catalog.Views.Categories, $( "#main" ) );
+ namespace.transitioner( new Catalog.Views.Categories(), $( "#main" ) );
},
items: function( catID ) {
@@ -70,7 +70,7 @@ function( namespace, $, $m, Backbone, Main, Catalog, Cart, Orders, messageTempla
},
cart: function() {
- namespace.transitioner( new Cart.Views.CartPage, $( "#main" ) );
+ namespace.transitioner( new Cart.Views.CartPage(), $( "#main" ) );
},
orders: function( hash ) {
@@ -30,12 +30,12 @@ function( namespace, $, $m, Backbone, cartTemplate, messageTemplate ) {
// Shopping cart page view
Cart.Views.CartPage = Backbone.View.extend({
- cart: new Cart.CartModel,
+ cart: new Cart.CartModel(),
done: null,
events: {
"click a.remove-button": "removeItem",
- "click a.checkout-button": "checkout",
+ "click a.checkout-button": "checkout"
},
render: function( done ) {
@@ -71,8 +71,8 @@ function( namespace, $, $m, Backbone, cartTemplate, messageTemplate ) {
case "STORE_CLOSED":
namespace.showMessageDialog( "#main", "#buyer/catalog", messageTemplate, response.message, 2000, namespace.app.router );
break;
- case "INVALID_USER":
default:
+ // INVALID_USER errors are also captured here
namespace.showMessageDialog( "#main", "#logout", messageTemplate, response.message, 2000, namespace.app.router );
break;
}
@@ -103,14 +103,11 @@ function( namespace, $, $m, Backbone, cartTemplate, messageTemplate ) {
},
error: function( jqXHR, textStatus, errorThrown ) {
var response = $.parseJSON( jqXHR.responseText );
- switch ( response.type ) {
- case "STORE_CLOSED":
- namespace.showMessageDialog( "#main", "#buyer/catalog", messageTemplate, response.message, 2000, namespace.app.router );
- break;
- case "INVALID_USER":
- default:
- namespace.showMessageDialog( "#main", "#logout", messageTemplate, $.parseJSON( jqXHR.responseText ).message, 2000, namespace.app.router );
- break;
+ if ( response.type == "STORE_CLOSED" ) {
+ namespace.showMessageDialog( "#main", "#buyer/catalog", messageTemplate, response.message, 2000, namespace.app.router );
+ } else {
+ // INVALID_USER are also captured here
+ namespace.showMessageDialog( "#main", "#logout", messageTemplate, $.parseJSON( jqXHR.responseText ).message, 2000, namespace.app.router );
}
}
}).done( function() {
@@ -135,14 +132,11 @@ function( namespace, $, $m, Backbone, cartTemplate, messageTemplate ) {
},
error: function( model, response ) {
response = $.parseJSON( response.responseText );
- switch ( response.type ) {
- case "STORE_CLOSED":
- namespace.showMessageDialog( "#main", "#buyer/catalog", messageTemplate, response.message, 2000, namespace.app.router );
- break;
- case "INVALID_USER":
- default:
- namespace.showMessageDialog( "#main", "#logout", messageTemplate, response.message, 2000, namespace.app.router );
- break;
+ if ( response.type == "STORE_CLOSED" ) {
+ namespace.showMessageDialog( "#main", "#buyer/catalog", messageTemplate, response.message, 2000, namespace.app.router );
+ } else {
+ // INVALID_USER errors are captured here
+ namespace.showMessageDialog( "#main", "#logout", messageTemplate, response.message, 2000, namespace.app.router );
}
}
});
@@ -136,8 +136,8 @@ function( namespace, $, $m, Backbone, catalogTemplate, itemsTemplate, itemTempla
case "STORE_CLOSED":
namespace.showMessageDialog( "#main", "#buyer/catalog", messageTemplate, response.message, 2000, namespace.app.router );
break;
- case "INVALID_USER":
default:
+ // INVALID_USER errors are also captured here
namespace.showMessageDialog( "#main", "#logout", messageTemplate, response.message, 2000, namespace.app.router );
break;
}
@@ -147,7 +147,7 @@ function( namespace, $, $m, Backbone, catalogTemplate, itemsTemplate, itemTempla
$m.hidePageLoadingMsg();
}
});
- }
+ };
// Shared view renderer for all catalog views
Catalog.renderList = function( template, items, view, done ) {
@@ -157,7 +157,7 @@ function( namespace, $, $m, Backbone, catalogTemplate, itemsTemplate, itemTempla
if ( _.isFunction( done ) ) {
done( view.el );
}
- }
+ };
// Cache the catalog to prevent unnecessary REST calls and reload if it's more than one hour old
Catalog.buildCache = function() {
@@ -183,7 +183,7 @@ function( namespace, $, $m, Backbone, catalogTemplate, itemsTemplate, itemTempla
}
}
});
- }
+ };
// Required, return the module for AMD compliance
return Catalog;
@@ -26,23 +26,23 @@ function( namespace, $, $m, Backbone, mainTemplate, roleTemplate, messageTemplat
urlRoot: namespace.serviceURL + "/user",
sync: function( method, model, options ) {
- var options = options || {};
+ options = options || {};
options.Accept = "application/json";
return Backbone.sync( method, model, options );
},
validate: function( attributes ) {
if ( !this.isNew() ) {
return '{"message": "You may not change roles", "type": "INVALID_REGISTRATION"}';
- } else if ( attributes.name == "" ) {
+ } else if ( attributes.name === "" ) {
return '{"message": "Please enter your name", "type": "INVALID_REGISTRATION"}';
}
}
});
// Default view with registration form
Main.Views.Registration = Backbone.View.extend({
- model: new Main.User,
+ model: new Main.User(),
events: {
"submit #profileForm": "register"
@@ -95,7 +95,7 @@ function( namespace, $, $m, Backbone, mainTemplate, roleTemplate, messageTemplat
},
error: function( model, response ) {
var message = response.hasOwnProperty( "responseText" ) ?
- $.parseJSON( response.responseText ).message :
+ $.parseJSON( response.responseText ).message :
$.parseJSON( response ).message;
namespace.showMessageDialog( "#main", false, messageTemplate, message, 2000, namespace.app.router );
}
@@ -105,7 +105,7 @@ function( namespace, $, $m, Backbone, mainTemplate, roleTemplate, messageTemplat
// Registered user view with order summary
Main.Views.Role = Backbone.View.extend({
- model: new Main.User,
+ model: new Main.User(),
events: {
"click #approveButton": "approveOrder",
@@ -116,7 +116,7 @@ function( namespace, $, $m, Backbone, mainTemplate, roleTemplate, messageTemplat
var view = this,
localUser = $.parseJSON( localStorage.getItem( "user" ) );
localUser.order = null;
- this.done = done
+ this.done = done;
$.ajax({
url: namespace.serviceURL + "/user/" + localUser.id,
@@ -187,8 +187,8 @@ function( namespace, $, $m, Backbone, mainTemplate, roleTemplate, messageTemplat
case "ORDER_ASSIGNED_TO_OTHER":
namespace.showMessageDialog( "#main", "#" + user.role.toLowerCase() + "/orders", messageTemplate, response.message, 2000, namespace.app.router );
break;
- case "INVALID_USER":
default:
+ // INVALID_USER errors are also captured here
namespace.showMessageDialog( "#main", "#logout", messageTemplate, response.message, 2000, namespace.app.router );
break;
}
@@ -225,8 +225,8 @@ function( namespace, $, $m, Backbone, mainTemplate, roleTemplate, messageTemplat
case "ORDER_ASSIGNED_TO_OTHER":
namespace.showMessageDialog( "#main", "#" + user.role.toLowerCase() + "/orders", messageTemplate, response.message, 2000, namespace.app.router );
break;
- case "INVALID_USER":
default:
+ // INVALID_USER errors are also captured here
namespace.showMessageDialog( "#main", "#logout", messageTemplate, response.message, 2000, namespace.app.router );
break;
}
@@ -33,7 +33,7 @@ function( namespace, $, $m, Backbone, orderListTemplate, messageTemplate ) {
// View to display the list of orders in the collection
Orders.Views.OpenOrderView = Backbone.View.extend({
- orders: new Orders.OpenOrders,
+ orders: new Orders.OpenOrders(),
curLength: null,
events: {
@@ -117,17 +117,12 @@ function( namespace, $, $m, Backbone, orderListTemplate, messageTemplate ) {
},
error: function( jqXHR, textStatus, errorThrown ) {
var response = $.parseJSON( jqXHR.responseText );
- switch ( response.type ) {
- case "USER_ALREADY_ASSIGNEE":
- namespace.showMessageDialog( "#main", "#" + user.role.toLowerCase() + "/role", messageTemplate, response.message, 2000, namespace.app.router );
- break;
- case "INVALID_USER":
- case "INVALID_ROLE":
- default:
- namespace.showMessageDialog( "#main", "#logout", messageTemplate, response.message, 2000, namespace.app.router );
- break;
+ if ( response.type == "USER_ALREADY_ASSIGNEE" ) {
+ namespace.showMessageDialog( "#main", "#" + user.role.toLowerCase() + "/role", messageTemplate, response.message, 2000, namespace.app.router );
+ } else {
+ // INVALID_USER and INVALID_ROLE errors are captured here
+ namespace.showMessageDialog( "#main", "#logout", messageTemplate, response.message, 2000, namespace.app.router );
}
-
},
done: function() {
$m.hidePageLoadingMsg();
@@ -164,9 +159,8 @@ function( namespace, $, $m, Backbone, orderListTemplate, messageTemplate ) {
clearTimeout( orderTimer );
namespace.showMessageDialog( "#main", "#" + user.role.toLowerCase() + "/role", messageTemplate, response.message, 2000, namespace.app.router );
break;
- case "INVALID_USER":
- case "INVALID_ROLE":
default:
+ // INVALID_USER and INVALID_ROLE errors are also captured here
// Stop the order list loop
clearTimeout( orderTimer );
namespace.showMessageDialog( "#main", "#logout", messageTemplate, response.message, 2000, namespace.app.router );
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta charset="UTF-8" />
+ <title>JBoss Toy Store Client Side Test Suite</title>
+
+ <link rel="stylesheet" href="qunit.css" type="text/css" media="screen">
+ <link rel="stylesheet" href="../../main/webapp/assets/css/main.css" />
+ <script data-main="test-module" src="../../main/webapp/assets/js/libs/require.js"></script>
+</head>
+<body>
+ <h1 id="qunit-header">JBoss Toy Store Client Side Test Suite</h1>
+ <h2 id="qunit-banner"></h2>
+ <div id="qunit-testrunner-toolbar"></div>
+ <h2 id="qunit-userAgent"></h2>
+ <ol id="qunit-tests"></ol>
+ <div id="qunit-fixture"></div>
+</body>
+</html>
Oops, something went wrong.

0 comments on commit 4ed39ab

Please sign in to comment.