Skip to content

Commit

Permalink
Issue #711. Refactor tests to use setup + teardown methods.
Browse files Browse the repository at this point in the history
Plus some other junk. :hanky:
  • Loading branch information
Mike Taylor committed Oct 1, 2015
1 parent d2570ae commit f365001
Show file tree
Hide file tree
Showing 12 changed files with 260 additions and 113 deletions.
7 changes: 7 additions & 0 deletions tests/functional.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

/*
To run a single test suite, use the following from the project root.
node_modules/.bin/intern-runner config=tests/intern functionalSuites=tests/functional/foo.js user="username" pw="secret_lies"
*/

define([
'./functional/comments-auth.js',
'./functional/comments-non-auth.js',
Expand Down
37 changes: 28 additions & 9 deletions tests/functional/comments-auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ define([
], function (intern, registerSuite, assert, require) {
'use strict';

var url = function(num) {
return intern.config.siteRoot + '/issues/' + num;
var url = function(path) {
return intern.config.siteRoot + path;
};

registerSuite({
name: 'issues',

'Comments form visible when logged in': function() {
setup: function () {
return this.remote
.setFindTimeout(intern.config.wc.pageLoadTimeout)
.get(require.toUrl(url(100)))
.get(require.toUrl(url('/')))
.findByCssSelector('.js-login-link').click()
.end()
.findByCssSelector('#login_field').click()
Expand All @@ -32,8 +32,27 @@ define([
.findByCssSelector('input[type=submit]').submit()
.end()
.findByCssSelector('button').submit()
.end();
},

teardown: function () {
return this.remote
.setFindTimeout(intern.config.wc.pageLoadTimeout)
.get(require.toUrl(url('/')))
.findByCssSelector('.js-login-link').click()
.end()
.clearCookies()
.end()
.get(require.toUrl(url(100)))
.get(require.toUrl('https://github.com/logout'))
.findByCssSelector('.auth-form-body input.btn').click()
.end();
},

'Comments form visible when logged in': function() {
return this.remote
.setFindTimeout(intern.config.wc.pageLoadTimeout)
.get(require.toUrl(url('/issues/100')))
.sleep(2000)
.findByCssSelector('.wc-Comment--form').isDisplayed()
.then(function (isDisplayed) {
assert.equal(isDisplayed, true, 'Comment form visible for logged in users.');
Expand All @@ -45,7 +64,7 @@ define([
'Empty vs non-empty comment button text (open issue)': function() {
return this.remote
.setFindTimeout(intern.config.wc.pageLoadTimeout)
.get(require.toUrl(url(100)))
.get(require.toUrl(url('/issues/100')))
.sleep(500)
.findByCssSelector('.js-issue-state-button').getVisibleText()
.then(function(text){
Expand All @@ -67,7 +86,7 @@ define([
'Empty vs non-empty comment button text (closed issue)': function() {
return this.remote
.setFindTimeout(intern.config.wc.pageLoadTimeout)
.get(require.toUrl(url(101)))
.get(require.toUrl(url('/issues/101')))
.sleep(2000)
.findByCssSelector('.js-issue-state-button').getVisibleText()
.then(function(text){
Expand All @@ -90,7 +109,7 @@ define([
var originalCommentsLength, allCommentsLength;
return this.remote
.setFindTimeout(intern.config.wc.pageLoadTimeout)
.get(require.toUrl(url(100)))
.get(require.toUrl(url('/issues/100')))
.findAllByCssSelector('.js-issue-comment:not(.wc-Comment--form)')
.then(function(elms){
originalCommentsLength = elms.length;
Expand All @@ -115,7 +134,7 @@ define([
var originalCommentsLength, allCommentsLength;
return this.remote
.setFindTimeout(intern.config.wc.pageLoadTimeout)
.get(require.toUrl(url(100)))
.get(require.toUrl(url('/issues/100')))
.findAllByCssSelector('.js-issue-comment:not(.wc-Comment--form)')
.then(function(elms){
originalCommentsLength = elms.length;
Expand Down
10 changes: 3 additions & 7 deletions tests/functional/comments-non-auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ define([
], function (intern, registerSuite, assert, require) {
'use strict';

var url = function(num) {
return intern.config.siteRoot + '/issues/' + num;
var url = function(path) {
return intern.config.siteRoot + path;
};

registerSuite({
Expand All @@ -20,15 +20,11 @@ define([
'Comment form not visible for logged out users': function() {
return this.remote
.setFindTimeout(intern.config.wc.pageLoadTimeout)
.get(require.toUrl(url(200)))
.findByCssSelector('.js-login-link').click()
.end()
.get(require.toUrl(url('/issues/200')))
.findByCssSelector('.wc-Comment--form')
.then(assert.fail, function(err) {
assert.isTrue(/NoSuchElement/.test(String(err)));
})
.end()
.findByCssSelector('.js-login-link').click()
.end();
}

Expand Down
12 changes: 7 additions & 5 deletions tests/functional/contributors-non-auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ define([
], function (intern, registerSuite, assert, require) {
'use strict';

var url = intern.config.siteRoot + '/contributors';
var url = function (path) {
return intern.config.siteRoot + path;
};

registerSuite({
name: 'contributors',

'page loads': function () {
return this.remote
.get(require.toUrl(url))
.get(require.toUrl(url('/contributors')))
.findByCssSelector('.wc-Hero-title').getVisibleText()
.then(function (text) {
assert.include(text, 'Welcome aboard!');
Expand All @@ -28,7 +30,7 @@ define([
'clicking first section closes it': function() {
return this.remote
.setFindTimeout(intern.config.wc.pageLoadTimeout)
.get(require.toUrl(url))
.get(require.toUrl(url('/contributors')))
.findByCssSelector('.contributors__item__title').click()
.end()
.findByCssSelector('.contributors__item__content').getAttribute('class')
Expand All @@ -46,7 +48,7 @@ define([
'clicking section toggles it': function() {
return this.remote
.setFindTimeout(intern.config.wc.pageLoadTimeout)
.get(require.toUrl(url))
.get(require.toUrl(url('/contributors')))
.findByCssSelector('.contributors__item__content.is-open').isDisplayed()
.then(function (isDisplayed) {
assert.equal(isDisplayed, true);
Expand All @@ -73,7 +75,7 @@ define([
'toggling section toggles lightbulb': function() {
return this.remote
.setFindTimeout(intern.config.wc.pageLoadTimeout)
.get(require.toUrl(url))
.get(require.toUrl(url('/contributors')))
.findByCssSelector('.wc-Hero-img.is-active').isDisplayed()
.then(function (isDisplayed) {
assert.equal(isDisplayed, true);
Expand Down
6 changes: 4 additions & 2 deletions tests/functional/history-navigation-non-auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ define([
], function (intern, registerSuite, assert, require) {
'use strict';

var url = intern.config.siteRoot;
var url = function (path) {
return intern.config.siteRoot + path;
};

registerSuite({
name: 'history navigation',

'Back button works from issues page': function () {
return this.remote
.get(require.toUrl(url))
.get(require.toUrl(url('/')))
.findByCssSelector('.js-issues-link').click()
.end()
//find an issue so we know the page has loaded
Expand Down
12 changes: 7 additions & 5 deletions tests/functional/index-non-auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ define([
], function (intern, registerSuite, assert, require) {
'use strict';

var url = intern.config.siteRoot;
var url = function (path) {
return intern.config.siteRoot + path;
};

registerSuite({
name: 'index',

'front page loads': function () {
return this.remote
.get(require.toUrl(url))
.get(require.toUrl(url('/')))
.findByCssSelector('.wc-Hero-title').getVisibleText()
.then(function (text) {
assert.equal(text, 'Bug reporting\nfor the internet.');
Expand All @@ -27,7 +29,7 @@ define([

'reporter addon link is shown': function () {
return this.remote
.get(require.toUrl(url))
.get(require.toUrl(url('/')))
.findByCssSelector('.wc-Navbar-link').getVisibleText()
.then(function (text) {
assert.include(text, 'Download our Firefox');
Expand All @@ -38,7 +40,7 @@ define([
'form toggles open then closed': function () {
return this.remote
.setFindTimeout(intern.config.wc.pageLoadTimeout)
.get(require.toUrl(url))
.get(require.toUrl(url('/')))
.findByCssSelector('#report-bug.closed').click()
.end()
.findByCssSelector('.form-opened').isDisplayed()
Expand All @@ -56,7 +58,7 @@ define([

'browse issues (new)': function() {
return this.remote
.get(require.toUrl(url))
.get(require.toUrl(url('/')))
.findAllByCssSelector('#new .wc-IssueItem.wc-IssueItem--new')
.then(function (elms) {
assert.equal(elms.length, 10, '10 issues should be displayed');
Expand Down
59 changes: 39 additions & 20 deletions tests/functional/issue-list-auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,48 @@ define([
], function (intern, registerSuite, assert, require) {
'use strict';

var url = intern.config.siteRoot + '/issues';
var url = function(path) {
return intern.config.siteRoot + path;
};

registerSuite({
name: 'issue-list',

setup: function () {
return this.remote
.setFindTimeout(intern.config.wc.pageLoadTimeout)
.get(require.toUrl(url('/')))
.findByCssSelector('.js-login-link').click()
.end()
.findByCssSelector('#login_field').click()
.type(intern.config.wc.user)
.end()
.findByCssSelector('#password').click()
.type(intern.config.wc.pw)
.end()
.findByCssSelector('input[type=submit]').submit()
.end()
.findByCssSelector('button').submit()
.end();
},

teardown: function () {
return this.remote
.setFindTimeout(intern.config.wc.pageLoadTimeout)
.get(require.toUrl(url('/')))
.findByCssSelector('.js-login-link').click()
.end()
.clearCookies()
.end()
.get(require.toUrl('https://github.com/logout'))
.findByCssSelector('.auth-form-body input.btn').click()
.end();
},

'Search/filter interaction': function() {
return this.remote
.setFindTimeout(intern.config.wc.pageLoadTimeout)
.get(require.toUrl(url))
.get(require.toUrl(url('/issues')))
.findByCssSelector('.IssueList-search-form').click()
.type('taco')
.end()
Expand All @@ -37,27 +70,15 @@ define([
.findAllByCssSelector('button.wc-Filter--new').getAttribute('class')
.then(function (className) {
assert.notInclude(className, 'is-active', 'Searching should clear all filters');
});
})
.end();
},

'Results are loaded from the query params (logged in)': function() {
'Results are loaded from the query params': function() {
var params = '?q=vladvlad';
return this.remote
.setFindTimeout(intern.config.wc.pageLoadTimeout)
.get(require.toUrl(url + params))
.findByCssSelector('.wc-IssueItem:nth-of-type(1) a').getVisibleText()
.then(function(text){
assert.include(text, 'vladvlad', 'The search query results show up on the page.');
})
.end()
.getCurrentUrl()
.then(function(currUrl){
assert.include(currUrl, 'q=vladvlad', 'Our params didn\'t go anywhere.');
})
// log out
.findByCssSelector('.js-login-link').click()
.end()
.sleep(2000)
.get(require.toUrl(url('/issues') + params))
.findByCssSelector('.wc-IssueItem:nth-of-type(1) a').getVisibleText()
.then(function(text){
assert.include(text, 'vladvlad', 'The search query results show up on the page.');
Expand All @@ -67,8 +88,6 @@ define([
.then(function(currUrl){
assert.include(currUrl, 'q=vladvlad', 'Our params didn\'t go anywhere.');
})
// log back in
.findByCssSelector('.js-login-link').click()
.end();
}

Expand Down
Loading

0 comments on commit f365001

Please sign in to comment.