Skip to content

Commit

Permalink
added view integration tests, updated other tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hunterloftis committed Aug 9, 2012
1 parent 2115138 commit 42dcca8
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 7 deletions.
17 changes: 14 additions & 3 deletions Makefile
@@ -1,11 +1,22 @@
setup:
rm -rf node_modules
npm cache clean
npm install

test:
npm install
scripts/test

test-quick:
scripts/test

start:
npm start

open:
(sleep 2 && open http://localhost:3000) &
npm start

test:
scripts/test

.PHONY: start open test

.PHONY: setup test test-quick start open
3 changes: 3 additions & 0 deletions lib/dashboard/dashboard.jade
@@ -1,5 +1,8 @@
extends ../shared/layout

block title
| Dashboard - Components test

block content
.dash-header
.half-drop
Expand Down
3 changes: 2 additions & 1 deletion lib/shared/layout.jade
Expand Up @@ -4,7 +4,8 @@ include ../flash/messages
html
head
meta(charset="utf-8")
title Components test
title: block title
| Components test
block styles
link(rel='stylesheet', type='text/css', href='/shared/global.css')

Expand Down
3 changes: 3 additions & 0 deletions lib/users/signin.jade
@@ -1,5 +1,8 @@
extends ../shared/layout

block title
| Sign in - Components test

block content
form.form-gateway(action='/signin', method='post')
.title-bar
Expand Down
2 changes: 1 addition & 1 deletion lib/users/test/controller.test.js
Expand Up @@ -49,7 +49,7 @@ describe('User controller', function() {
});
});
});
describe('/ landing page', function() {
describe('/', function() {
var agent = superagent.agent();

before(loginUser(agent));
Expand Down
2 changes: 1 addition & 1 deletion lib/users/test/model.test.js
Expand Up @@ -3,7 +3,7 @@ var should = require('should');
var UserModel = require('../userModel');

describe('User model', function() {
describe('authenticate', function() {
describe('authenticate()', function() {
it('should reject a request without an email', function(done) {
UserModel.authenticate({ password: 'bacon' }, onAuth);
function onAuth(err, user) {
Expand Down
2 changes: 1 addition & 1 deletion scripts/test
@@ -1,5 +1,5 @@
#!/bin/bash

TESTS=`find lib -name '*.test.js'`
TESTS=`find lib -name '*.test.js' && find test -name '*.test.js'`

node_modules/.bin/mocha -R list $TESTS
78 changes: 78 additions & 0 deletions test/integration.test.js
@@ -0,0 +1,78 @@
var should = require('should');
var Zombie = require('zombie');
var assert = require('assert');

var utils = require('../lib/shared/test.utils');

utils.startApp(3002);

describe('Browser', function() {
describe('of an unregistered user', function() {
var browser = new Zombie();
it('should be able to view the landing page', function(done) {
browser.visit('http://localhost:3002', function() {
assert.ok(browser.success);
browser.text('title').should.include('Sign in');
return done();
});
});
it('should not be able to view the dashboard', function(done) {
browser.visit('http://localhost:3002/dashboard', function() {
assert.ok(browser.success);
browser.text('title').should.include('Sign in');
browser.text('.flash-messages').should.include('Please log in first');
return done();
});
});
});
describe('of a registered user', function() {
var browser = new Zombie();
it('should be able to view the landing page', function(done) {
browser.visit('http://localhost:3002', function() {
assert.ok(browser.success);
browser.text('title').should.include('Sign in');
return done();
});
});
it('should get an error with bad credentials', function(done) {
browser
.fill('email', 'test@dummy.com')
.fill('password', 'wrong')
.pressButton('Sign in')
.then(function() {
assert.ok(browser.success);
browser.text('title').should.include('Sign in');
browser.text('.flash-messages').should.include('Sorry, that username or password was not found');
return done();
})
.fail(done);
});
it('should be able to sign in with good credentials', function(done) {
browser
.fill('email', 'test@dummy.com')
.fill('password', 'bacon')
.pressButton('Sign in')
.then(function() {
assert.ok(browser.success);
browser.text('title').should.include('Dashboard');
return done();
})
.fail(done);
});
it('should be able to reload the dashboard', function(done) {
browser.visit('http://localhost:3002/dashboard', function() {
assert.ok(browser.success);
browser.text('title').should.include('Dashboard');
return done();
});
});
it('should be able to sign out', function(done) {
browser.clickLink('Sign out', function() {
assert.ok(browser.success);
browser.text('title').should.include('Sign in');
browser.text('.flash-messages').should.include('You have been signed out');
return done();
});
});
});
});

0 comments on commit 42dcca8

Please sign in to comment.