From 64aeaff1ad502b7b9c9956f74e547382a0b3840c Mon Sep 17 00:00:00 2001 From: Jonnie Spratley Date: Tue, 9 Dec 2014 10:49:57 -0800 Subject: [PATCH] updated specs --- gulpfile.js | 73 +++++++++++++++------- package.json | 4 +- test/protractor/j$.coffee | 14 ++--- test/protractor/pages/app-page.coffee | 9 +-- test/protractor/pages/login-page.coffee | 22 ++++--- test/protractor/pages/register-page.coffee | 32 +++++----- test/protractor/spec/app-spec.coffee | 16 ++--- test/protractor/spec/login-spec.coffee | 14 +++-- 8 files changed, 109 insertions(+), 75 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index e29d1eb..3a17851 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,28 +1,55 @@ -var coffee, gulp, uglify; +'use strict'; -gulp = require( 'gulp' ); -coffee = require( 'gulp-coffee' ); -uglify = require( 'gulp-uglify' ); +var del = require('del'); +var gulp = require('gulp'); +var coffee = require('gulp-coffee'); +var uglify = require('gulp-uglify'); +var protractor = require('gulp-protractor').protractor; -gulp.task( 'js', function () { + +gulp.task('clean', function(cb) { + del(['build'], cb); +}); + +/** + * CoffeeScript Source Files + */ +gulp.task('js', function () { gulp - .src( './app/scripts/**/*.coffee' ) - .pipe( coffee({ + .src('./app/scripts/**/*.coffee') + .pipe(coffee({ bare: true - }) ) - .pipe( uglify() ) - .pipe( gulp.dest( './.tmp/scripts' ) ); -} ); -gulp.task( 'js:test', function () { - gulp - .src( './test/**/*.coffee' ) - .pipe( coffee({ + })) + .pipe(uglify()) + .pipe(gulp.dest('./.tmp/scripts')); +}); + +/** + * CoffeeScript Test Files + */ +gulp.task('js:test', function () { + gulp.src('./test/**/*.coffee') + .pipe(coffee({ bare: true - }) ) - .pipe( gulp.dest( './.tmp' ) ); -} ); - -gulp.task( 'watch', function () { - gulp.watch( './app/scripts/**/*.coffee', ['js'] ); - gulp.watch( './test/**/*.coffee', ['js:test'] ) -} ); + })).pipe(gulp.dest('./.tmp')); +}); + +gulp.task('watch', function () { + gulp.watch('./app/scripts/**/*.coffee', ['js']); + gulp.watch('./test/**/*.coffee', ['js:test']) +}); + + + + +gulp.task('test', ['js:test'], function(){ + gulp.src(['./.tmp/protractor/**/*-spec.js']) + .pipe(protractor({ + configFile: 'protractor.conf.js' + })) + .on('error', function (e) { + throw e; + }); +}); + +gulp.task('default', ['js:test', 'test']); \ No newline at end of file diff --git a/package.json b/package.json index 2686c2b..b0ff62f 100755 --- a/package.json +++ b/package.json @@ -64,6 +64,7 @@ "devDependencies": { "chai": "^1.10.0", "connect-proxy": "~1.0.2", + "del": "^1.1.0", "grunt": "~0.4.4", "grunt-angular-templates": "~0.5.1", "grunt-autoprefixer": "~0.4.0", @@ -97,6 +98,7 @@ "grunt-svgmin": "~0.2.0", "grunt-usemin": "~2.0.2", "gulp-ngmin": "^0.3.0", + "gulp-protractor": "0.0.11", "gulp-uglify": "^1.0.2", "jasmine-core": "^2.1.2", "jasmine-node": "~1.11.0", @@ -111,7 +113,7 @@ "karma-phantomjs-launcher": "~0.1", "load-grunt-tasks": "~0.2.0", "mocha": "^2.0.1", - "protractor": "^1.0.0", + "protractor": "^1.5.0", "supertest": "^0.15.0", "time-grunt": "~0.2.1" }, diff --git a/test/protractor/j$.coffee b/test/protractor/j$.coffee index 8223b72..76aa0ef 100644 --- a/test/protractor/j$.coffee +++ b/test/protractor/j$.coffee @@ -1,11 +1,9 @@ ###* J$ Helpers - I am test helpers ### -j$ = - element: (selector, label) -> - console.warn('finding', label) if label - $(selector) - input: (name) -> - element(protractor.By.css("[name=#{name}]")).getWebElement() - -module.exports = j$ +module.exports = + element: (selector, label) -> + console.warn('finding', label) if label + $(selector) + input: (name) -> + element(protractor.By.css("[name=#{name}]")).getWebElement() \ No newline at end of file diff --git a/test/protractor/pages/app-page.coffee b/test/protractor/pages/app-page.coffee index 1201180..585342a 100644 --- a/test/protractor/pages/app-page.coffee +++ b/test/protractor/pages/app-page.coffee @@ -1,10 +1,11 @@ - ###* App Page - I handle general actions in the app. ### AppPage = - title: $('.navbar-brand') - get: -> - browser.get '/' + title: $('.navbar-brand') + get: -> + browser.get '/#' + refresh: -> + browser.refresh() module.exports = AppPage diff --git a/test/protractor/pages/login-page.coffee b/test/protractor/pages/login-page.coffee index 562e0a9..15d0700 100644 --- a/test/protractor/pages/login-page.coffee +++ b/test/protractor/pages/login-page.coffee @@ -2,13 +2,19 @@ Login Page - I handle actions on the login page. ### LoginPage = - username: $('#username') - password: $('#password') - get: -> - browser.get '/login' - login: (u, p) -> - @username.sendKeys(u) - @password.sendKeys(p) - element(protractor.By.css('button[type="submit"]')).click() + username: $('#username') + password: $('#password') + get: -> + browser.get '#/login' + logout: -> + $('.dropdown-toggle').getWebElement().then((el)-> + el.click().then(()-> + $('[href="#/login"]').click() + ) + ) + login: (u, p) -> + @username.sendKeys(u) + @password.sendKeys(p) + element(protractor.By.css('button[type="submit"]')).click() module.exports = LoginPage diff --git a/test/protractor/pages/register-page.coffee b/test/protractor/pages/register-page.coffee index d9415c3..321dba9 100644 --- a/test/protractor/pages/register-page.coffee +++ b/test/protractor/pages/register-page.coffee @@ -4,20 +4,22 @@ j$ = require('../j$') Register Page - I handle actions on the register page ### RegisterPage = - email = $('#email') - username: $('#username') - password: $('#password') - password2: $('#password2') - agree: $('#agree') - submit: element(protractor.By.css('button')) - get: -> - browser.get '/register' - register: (username, password) -> - @email.sendKeys(username) - @username.sendKeys(username) - @password.sendKeys(password) - @password2.sendKeys(password) - @agree.click() - @submit.click() + email: $('#email') + username: $('#username') + password: $('#password') + password2: $('#password2') + agree: $('#agree') + submit: element(protractor.By.buttonText('Sign up')) + get: -> + browser.get '#/register' + register: (username, password) -> + @email.sendKeys(username) + @username.sendKeys(username) + @password.sendKeys(password) + @password2.sendKeys(password) + @agree.click().then(()=> + @submit.click() + ) + module.exports = RegisterPage diff --git a/test/protractor/spec/app-spec.coffee b/test/protractor/spec/app-spec.coffee index a718865..9a8a9e6 100644 --- a/test/protractor/spec/app-spec.coffee +++ b/test/protractor/spec/app-spec.coffee @@ -1,14 +1,10 @@ -appPage = require('../pages/app-page') - - ###* Protractor e2e Tests ### -describe "Angular-CMS App", -> - beforeEach -> - appPage.refresh() - it 'should have the correct title', -> - appPage.title.getText().then((val)-> - expect(val).toContain('angular-cms') - ) +describe 'Angular-CMS App', -> + appPage = require('../pages/app-page') + it 'should have the correct title', -> + appPage.title.getText().then((val)-> + expect(val).toContain('angular-cms') + ) diff --git a/test/protractor/spec/login-spec.coffee b/test/protractor/spec/login-spec.coffee index c0f5ae7..1827900 100644 --- a/test/protractor/spec/login-spec.coffee +++ b/test/protractor/spec/login-spec.coffee @@ -4,9 +4,11 @@ loginPage = require('../pages/login-page') Login - The user login implementation ### describe 'Login:', -> - beforeEach -> - $('[href="#/login"]').click() - it 'should have Username and password inputs with a button to submit the form', -> - loginPage.login('test@email.com', 'test').then(()-> - expect(browser.getLocationAbsUrl()).toContain '/dashboard' - ) + beforeEach -> + loginPage.get() + afterEach -> + loginPage.logout() + it 'should have Username and password inputs with a button to submit the form', -> + loginPage.login('test@email.com', 'test').then(()-> + expect(browser.getLocationAbsUrl()).toContain '/dashboard' + )