Last active
August 29, 2015 14:14
-
-
Save courington/1c4ca6043a12432278aa to your computer and use it in GitHub Desktop.
Functional tests with The Intern: User login test
This file contains 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
define([ | |
'intern!object', | |
'intern/chai!assert', | |
'intern/chai!expect', | |
'intern/chai!should', | |
'require' | |
], function(registerSuite, assert, should, expect, require) { | |
var url = 'http://localhost:3000/'; | |
var dest_url = 'http://localhost:3000/users/sign_in'; | |
var countdown = 40000; | |
registerSuite({ | |
name: 'FLOW 1 - /users/sign_in => /overview', | |
'NAVIGATE': function() { | |
return this.remote | |
.get(require.toUrl(url)) | |
.setFindTimeout(countdown) | |
.findByCssSelector('#page-sign-in h5').getVisibleText().then(function(text) { | |
assert.strictEqual(text, 'Welcome to Mobile System 7', 'log in welcome message'); | |
}); | |
}, | |
'LOG IN ERROR': function() { | |
return this.remote | |
.get(require.toUrl(url)) | |
.setFindTimeout(countdown) | |
.findById('signin_button').click().end() | |
.findByCssSelector('div.alert').getVisibleText().then(function(text) { | |
assert.strictEqual(text, 'Invalid username or password.', 'Invalid username or password.'); | |
}); | |
}, | |
'LOG IN': function() { | |
return this.remote | |
.get(require.toUrl(dest_url)) | |
.setFindTimeout(countdown) | |
.findById('login-username').click().type('admin').end() | |
.findById('login-password').click().type('password').end() | |
.findById('signin_button').click().end() | |
.getCurrentUrl().then(function(current_url) { | |
assert.strictEqual(current_url, 'http://localhost:3000/overview', 'urls should match'); | |
}); | |
}, | |
'INSPECT MODAL': function() { | |
return this.remote | |
.get(require.toUrl(url)) | |
.setFindTimeout(countdown) | |
// launch the modal | |
.findByCssSelector('a#modal').click().end() | |
// inspect the modal header | |
.findByCssSelector('div.modal-header h3').getVisibleText().then(function(text) { | |
assert.strictEqual(text, 'You Launched a Modal!', 'Modal should launch with the correct header'); | |
}); | |
}, | |
'INSPECT QUICKVIEW': function() { | |
return this.remote | |
.get(require.toUrl(url)) | |
.setFindTimeout(countdown) | |
// launch the modal | |
.findByCssSelector('a#modal').click().end() | |
// trigger a quickview | |
.findByCssSelector('button[data-quick-view]').click().end() | |
// inspect the quickview | |
.findById('quickview-popup').getAttribute('class').then(function(text) { | |
assert.strictEqual(text, 'popup condensed-table', 'element class should match'); | |
}); | |
}, | |
'CLICK TAB': function() { | |
return this.remote | |
.get(require.toUrl(url)) | |
.setFindTimeout(countdown) | |
// find the tab | |
.findByCssSelector('ul.nav-pills').findByPartialLinkText('Analytics').click().end() | |
.getCurrentUrl().then(function(current_url) { | |
assert.strictEqual(current_url, 'http://localhost:3000/overview/analytics', 'urls should match'); | |
}); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment