Skip to content
This repository was archived by the owner on Oct 10, 2017. It is now read-only.

Commit

Permalink
re-working a lot of specs to clean them up, consolidating mail router…
Browse files Browse the repository at this point in the history
… specs in to one file
  • Loading branch information
Derick Bailey committed Sep 21, 2012
1 parent a24ef88 commit 7448513
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 93 deletions.
1 change: 1 addition & 0 deletions grunt.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ module.exports = function(grunt) {
'public/javascripts/vendor/json2.js',
'public/javascripts/vendor/underscore.js',
'public/javascripts/vendor/backbone.js',
'public/javascripts/vendor/backbone.routefilter.js',
'public/javascripts/vendor/backbone.marionette.js',
'public/javascripts/vendor/marionette.wreqr.js',
'public/javascripts/bbclonemail/bbclonemail.js',
Expand Down
3 changes: 2 additions & 1 deletion spec/javascripts/helpers/marionetteHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ function startHistory(){
// so Backbone.history will exist
var router = new (Backbone.Router.extend({
routes: { "empty-route": "emptyRoute"}
}));
}))();
}

if (!Backbone.History.started){
Expand All @@ -13,6 +13,7 @@ function startHistory(){
}

beforeEach(function(){
// clear the regions so they can be used again
BBCloneMail.main.reset();
BBCloneMail.nav.reset();
});
Expand Down
35 changes: 1 addition & 34 deletions spec/javascripts/inbox.spec.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
describe("inbox", function(){
"use strict";

var showMailItemHandler, showMailListHandler, getInboxHandler;
var showMailListHandler, getInboxHandler;

beforeEach(function(){
showMailItemHandler = jasmine.createSpy("show mail item");
showMailListHandler = jasmine.createSpy("show mail list");
getInboxHandler = jasmine.createSpy("get inbox");

BBCloneMail.registerCommand("show:mail:item", showMailItemHandler);
BBCloneMail.registerCommand("show:mail:list", showMailListHandler);
BBCloneMail.respondTo("mail:inbox", getInboxHandler);

Expand All @@ -18,7 +16,6 @@ describe("inbox", function(){
});

afterEach(function(){
BBCloneMail.removeCommand("show:mail:item");
BBCloneMail.removeCommand("show:mail:list");
BBCloneMail.removeRequestHandler("mail:inbox");
});
Expand All @@ -45,34 +42,4 @@ describe("inbox", function(){

});

describe("when routing to an individual email", function(){
var router, inbox, email;

beforeEach(function(){
affix("article#main; #email-view-template li");

BBCloneMail.main.reset();
BBCloneMail.main.ensureEl();

router = BBCloneMail.module("MailRouter");
router.start();

inbox = BBCloneMail.module("MailApp.Inbox");
inbox.start();

window.location.hash = "inbox/mail/1";
startHistory();
});

afterEach(function(){
inbox.stop();
router.stop();
});

it("should show the full email contents", function(){
expect(showMailItemHandler).toHaveBeenCalled();
});

});

});
40 changes: 5 additions & 35 deletions spec/javascripts/mailAppStart.spec.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,16 @@
describe("mail app start", function(){
"use strict";

describe("when starting the mail app with an empty route (#)", function(){
var router, inbox, handler, getInboxHandler;

beforeEach(function(){
getInboxHandler = jasmine.createSpy();
BBCloneMail.respondTo("mail:inbox", getInboxHandler);

handler = jasmine.createSpy();
BBCloneMail.registerCommand("show:mail:list", handler);

router = BBCloneMail.module("MailRouter");
router.start();

inbox = BBCloneMail.module("MailApp.Inbox");
inbox.start();

startHistory();
});

afterEach(function(){
inbox.stop();
router.stop();
BBCloneMail.removeCommand("show:mail:list");
BBCloneMail.removeRequestHandler("mail:inbox");
});

it("should show the inbox", function(){
expect(handler.wasCalled).toBe(true);
});

});

describe("when the mail app initializes", function(){
var categoryNav, getCategoriesHandler;
var categoryNav, getCategoriesHandler, notifyAppStart;

beforeEach(function(){
affix("#mail-categories-view-template ul.categories li; #navigation");
getCategoriesHandler = jasmine.createSpy();

var cat = new Backbone.Model({id: 1, name: "cat"});
var catCol = new Backbone.Collection([cat]);
getCategoriesHandler = jasmine.createSpy();
getCategoriesHandler.andReturn(catCol);

BBCloneMail.respondTo("mail:categories", getCategoriesHandler);

categoryNav = BBCloneMail.module("MailApp.CategoryNavigation");
Expand All @@ -60,5 +27,8 @@ describe("mail app start", function(){
expect(el.length).toBe(1);
});

it("should notify the mail app started", function(){
});

});
});
23 changes: 0 additions & 23 deletions spec/javascripts/mailCategoryNav.spec.js

This file was deleted.

88 changes: 88 additions & 0 deletions spec/javascripts/mailRouter.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
describe("mail router", function(){
"use strict";

var router, startMail, inbox;

beforeEach(function(){
startHistory();

startMail = spyOn(BBCloneMail, "startSubApp");

inbox = BBCloneMail.module("MailApp.Inbox");

router = BBCloneMail.module("MailRouter");
router.start();
});

afterEach(function(){
router.stop();
delete inbox.controller;
});

function mockControllerMethod(methodName){
var spy = jasmine.createSpy(methodName);

inbox.controller = {};
inbox.controller[methodName] = spy;

return spy;
}

describe("when navigating to the inbox (empty route)", function(){
var showInbox;

beforeEach(function(){
showInbox = mockControllerMethod("showInbox");

Backbone.history.loadUrl("");
});

it("should start the mail app", function(){
expect(startMail).toHaveBeenCalledWith("MailApp");
});

it("should show the inbox", function(){
expect(showInbox).wasCalled();
});

});

describe("when routing to an individual email", function(){
var showMailById;

beforeEach(function(){
showMailById = mockControllerMethod("showMailById");

Backbone.history.loadUrl("inbox/mail/1");
});

it("should start the mail app", function(){
expect(startMail).toHaveBeenCalledWith("MailApp");
});

it("should show the email by id", function(){
expect(showMailById).toHaveBeenCalled();
});

});

describe("when navigating to a mail category", function(){
var showMailByCategory;

beforeEach(function(){
showMailByCategory = mockControllerMethod("showMailByCategory");

Backbone.history.loadUrl("categories/foo");
});

it("should start the mail app", function(){
expect(startMail).toHaveBeenCalledWith("MailApp");
});

it("should show the email by category", function(){
expect(showMailByCategory).toHaveBeenCalled();
});

});

});

0 comments on commit 7448513

Please sign in to comment.