Created
March 28, 2014 00:22
-
-
Save a5sk4s/9822278 to your computer and use it in GitHub Desktop.
angularfire-seed e2e tests in protractor speak
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('my app', function() { | |
var ptor; | |
beforeEach(function() { | |
browser.driver.get('app/index.html'); | |
ptor = protractor.getInstance(); | |
}); | |
it('should automatically redirect to /home when location hash/fragment is empty', function() { | |
// expect(browser.location().url()).toBe("/home"); | |
expect(ptor.getCurrentUrl()).toMatch(/#\/home/); | |
}); | |
describe('home', function() { | |
beforeEach(function() { | |
// browser.navigateTo('#/home'); | |
browser.driver.get('app/index.html#/home'); | |
}); | |
it('should render home when user navigates to /home', function() { | |
// expect(element('[ng-view] h2:first').text()).toMatch(/Home/); | |
expect(element(by.css("div[ng-view]>h2:first-of-type")).getText()).toMatch(/Home/); | |
}); | |
}); | |
describe('chat', function() { | |
beforeEach(function() { | |
// browser.navigateTo('#/chat'); | |
browser.driver.get('app/index.html#/chat'); | |
}); | |
it('should render chat when user navigates to /chat', function() { | |
// expect(element('[ng-view] h2:first').text()).toMatch(/Chat/); | |
expect(element(by.css("div[ng-view]>h2:first-of-type")).getText()).toMatch(/Chat/); | |
}); | |
}); | |
describe('account', function() { | |
afterEach(function() { | |
// angularFireLogout(); | |
browser.driver.executeAsyncScript(function() { | |
// var fbRef = $document.injector().get('firebaseRef'); | |
// var $firebaseSimpleLogin = $document.injector().get('$firebaseSimpleLogin'); | |
// $firebaseSimpleLogin(fbRef()).$logout(); | |
// done(null, true); | |
var callback = arguments[arguments.length - 1]; | |
var firebaseRef = angular.injector(['ng', 'firebase', 'myApp.config', 'myApp.service.firebase']).get('firebaseRef'); | |
var $firebaseSimpleLogin = angular.injector(['ng', 'firebase']).get('$firebaseSimpleLogin'); | |
$firebaseSimpleLogin(firebaseRef()).$logout(); | |
callback(null, true); | |
}); | |
}); | |
describe('if not logged in', function() { | |
it('should redirect to /login', function() { | |
// browser.navigateTo('#/account'); | |
browser.driver.get('app/index.html#/account'); | |
// expect(browser.window().hash()).toBe('/login'); | |
expect(ptor.getCurrentUrl()).toMatch(/\/login/); | |
}); | |
}); | |
describe('if authenticated', function() { | |
beforeEach(function() { | |
browser.driver.executeAsyncScript(function() { | |
var callback = arguments[arguments.length - 1]; | |
var loginService = angular.injector(['ng', 'firebase', 'myApp.config', 'myApp.service.firebase', 'myApp.service.login']).get('loginService'); | |
loginService.init(); | |
loginService.login('[email protected]', 't3stm3', callback); | |
}); | |
}); | |
it('should stay on account screen if authenticated', function() { | |
// this.addFutureAction('authenticate', function($window, $document, done) { | |
// var loginService = angular.injector().get('loginService'); | |
// loginService.login('[email protected]', 't3stm3', done); | |
// }); | |
// browser.navigateTo('#/account'); | |
// ptor.waitForAngular(); | |
browser.driver.get('app/index.html#/account'); | |
// expect(browser.window().hash()).toBe('/account'); | |
expect(ptor.getCurrentUrl()).toMatch(/\/account/); | |
}); | |
}); | |
}); | |
describe('login', function() { | |
beforeEach(function() { | |
// browser.navigateTo('#/login'); | |
browser.driver.get('app/index.html#/login'); | |
}); | |
afterEach(function() { | |
// angularFireLogout(); | |
browser.driver.executeAsyncScript(function() { | |
// var fbRef = $document.injector().get('firebaseRef'); | |
// var $firebaseSimpleLogin = $document.injector().get('$firebaseSimpleLogin'); | |
// $firebaseSimpleLogin(fbRef()).$logout(); | |
// done(null, true); | |
var callback = arguments[arguments.length - 1]; | |
var firebaseRef = angular.injector(['ng', 'firebase', 'myApp.config', 'myApp.service.firebase']).get('firebaseRef'); | |
var $firebaseSimpleLogin = angular.injector(['ng', 'firebase']).get('$firebaseSimpleLogin'); | |
$firebaseSimpleLogin(firebaseRef()).$logout(); | |
callback(null, true); | |
}); | |
}); | |
it('should render login when user navigates to /login', function() { | |
// expect(element('[ng-view] h2:first').text()).toMatch('Login Page'); | |
expect(element(by.css("div[ng-view]>h2:first-of-type")).getText()).toMatch(/Login Page/); | |
}); | |
it('should show error if no email', function() { | |
expect(element(by.css("p.error")).getText()).toEqual(''); | |
// input('email').enter(''); | |
element(by.input('email')).sendKeys(''); | |
// input('pass').enter('t3stm3'); | |
element(by.input('pass')).sendKeys('t3stm3'); | |
element(by.css("button[ng-click='login()']")).click(); | |
expect(element(by.css("p.error")).getText()).not.toEqual(''); | |
}); | |
it('should show error if no password', function() { | |
expect(element(by.css("p.error")).getText()).toEqual(''); | |
// input('email').enter('[email protected]'); | |
element(by.input('email')).sendKeys('[email protected]'); | |
// input('pass').enter(''); | |
element(by.input('pass')).sendKeys(''); | |
element(by.css("button[ng-click='login()']")).click(); | |
expect(element(by.css("p.error")).getText()).not.toEqual('') | |
}); | |
it('should log in with valid fields', function() { | |
// input('email').enter('[email protected]'); | |
element(by.input('email')).sendKeys('[email protected]'); | |
// input('pass').enter('t3stm3'); | |
element(by.input('pass')).sendKeys('t3stm3'); | |
element(by.css("button[ng-click='login()']")).click(); | |
expect(element(by.css("p.error")).getText()).toEqual(''); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment