Skip to content

Commit

Permalink
[#16] Migrating tests to new qunit API
Browse files Browse the repository at this point in the history
Closes #16
  • Loading branch information
0xadada committed Jan 29, 2018
1 parent 841ca6c commit 7f35173
Show file tree
Hide file tree
Showing 10 changed files with 237 additions and 233 deletions.
7 changes: 3 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ version: 2
jobs:
build:
docker:
- image: circleci/node:boron-browsers

- image: circleci/node:carbon-browsers
steps:
- checkout
- run:
Expand All @@ -18,7 +17,7 @@ jobs:
- run:
name: Install dependencies
command: |
yarn global add ember-cli@2.16
yarn global add ember-cli@3.0.0-beta.2
yarn
- save_cache:
key: dependency-cache-{{ checksum "yarn.lock" }}
Expand All @@ -27,7 +26,7 @@ jobs:
- run:
name: Run tests
command: |
npm rebuild node-sass
npm rebuild node-sass 2>&1 > /dev/null
./node_modules/ember-cli/bin/ember --version --verbose
yarn test
yarn coverage
4 changes: 4 additions & 0 deletions mirage/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,8 @@ export default function() {
}
return media;
});
this.del('/medias/:id', (schema, request) => {
let media = schema.medias.find(request.params.id);
media.destroy();
});
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,6 @@
"node-fetch"
],
"resolutions": {
"ember-simple-auth": "0xadada/ember-simple-auth#new-ember-qunit-release"
"ember-simple-auth": "0xadada/ember-simple-auth#b520d6bbd17ec2b99d792a75ae8a8b119af4d08a"
}
}
11 changes: 10 additions & 1 deletion testem.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,16 @@ module.exports = {
args: [
'--disable-gpu',
'--headless',
'--remote-debugging-port=9222',
'--remote-debugging-port=0',
'--window-size=1440,900'
]
},
Firefox: {
mode: 'all',
args: [
'--disable-gpu',
'--headless',
'--remote-debugging-port=0',
'--window-size=1440,900'
]
}
Expand Down
58 changes: 29 additions & 29 deletions tests/acceptance/index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,38 @@ import { module, test } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';
import { click, fillIn, currentURL, visit } from '@ember/test-helpers';

module('Acceptance | index', function(hooks) {
module('Application | index', function(hooks) {
setupApplicationTest(hooks);

test('visiting / unauthenticated should redirect to /welcome', async function(assert) {
await visit('/');

assert.equal(currentURL(), '/welcome');
module('unauthenticated user', function(/* hooks */) {
test('visiting / redirects to /welcome', async function(assert) {
await visit('/');
assert.equal(currentURL(), '/welcome');
});

test('visiting /styleguide redirects to /login', async function(assert) {
await visit('/styleguide');
assert.equal(currentURL(), '/login');
});

test('visiting /styleguide redirects to /login', async function(assert) {
await visit('/styleguide');
assert.equal(currentURL(), '/login');
});
});

test('visiting /styleguide unauthenticated should redirect to /login', async function(assert) {
await visit('/styleguide');

assert.equal(currentURL(), '/login');
});

test('visiting /styleguide unauthenticated should redirect to /login', async function(assert) {
await visit('/styleguide');

assert.equal(currentURL(), '/login');
});

test('visiting / authorized is allowed for new users', async function(assert) {
// create an OAuth token w/ ember-cli-mirage
server.create('token');
server.create('user');

await visit('/login');
await fillIn('[name=email]', `mike+${new Date().getTime()}@example.com`);
await fillIn('[name=password]', 'Password1234');
await fillIn('[name=password_confirmation]', 'Password1234');
await click('[data-test=signup]');

assert.equal(currentURL(), '/');
module('authenticated user', function(/* hooks */) {
test('can visiting / for new users', async function(assert) {
// create an OAuth token w/ ember-cli-mirage
server.create('token');
server.create('user');
await visit('/login');
// create account
await fillIn('[name=email]', `mike+${new Date().getTime()}@example.com`);
await fillIn('[name=password]', 'Password1234');
await fillIn('[name=password_confirmation]', 'Password1234');
await click('[data-test=signup]');
assert.equal(currentURL(), '/');
});
});
});
229 changes: 113 additions & 116 deletions tests/acceptance/login-test.js
Original file line number Diff line number Diff line change
@@ -1,126 +1,123 @@
import { module, test } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';
import {
click,
fillIn,
currentURL,
find,
keyEvent,
triggerKeyEvent,
focus,
blur,
visit
} from 'ember-native-dom-helpers';
import { test } from 'qunit';
import { authenticateSession } from 'mir/tests/helpers/ember-simple-auth';
import moduleForAcceptance from 'mir/tests/helpers/module-for-acceptance';

moduleForAcceptance('Acceptance | login');

test('unauthenticated users can visit /login', async function(assert) {
await visit('/login');

assert.equal(currentURL(), '/login');
});

test('unauthenticated users must supply a strong password', async function(assert) {
await visit('/login');
await fillIn('[name=email]', `mike+${new Date().getTime()}@example.com`);
await fillIn('[name=password]', 'Password');
await blur('[name=password]');

let msg = find('.ma-Login .help.is-danger').textContent;
assert.notEqual(msg.match(/Password must be between/), null);
});

test('unauthenticated users cannot create an account without confirming password', async function(assert) {
await visit('/login');
await fillIn('[name=email]', `mike+${new Date().getTime()}@example.com`);
await fillIn('[name=password]', 'Password1234');
await fillIn('[name=password_confirmation]', '');
await blur('[name=password_confirmation]');

let msg = find('.help.is-danger').textContent;
assert.notEqual(msg.match(/password/), null);
assert.dom('[data-test=signup][disabled]').exists({ count: 1 });
});

test('unauthenticated users must supply a valid password', async function(assert) {
await visit('/login');
let maLogin = await find('.ma-Login');
await fillIn('[name=email]', '[email protected]');
await fillIn('[name=password]', 'a');
await keyEvent(maLogin, 'keyup', 13);
await focus('.ma-Login [data-test=login]');
await keyEvent(maLogin, 'keyup', 13);

assert.dom('.ma-Login button[disabled]').exists({ count: 1 });
});

test('unauthenticated users can create an account with email & password', async function(assert) {
// create an OAuth token w/ ember-cli-mirage
server.create('token');
server.create('user');

// user visits login and fills in signup form
await visit('/login');
await fillIn('[name=email]', `mike+${new Date().getTime()}@example.com`);
await fillIn('[name=password]', 'Password1234');
await fillIn('[name=password_confirmation]', 'Password1234');
// user clicks signup button
await focus('.ma-Auth [data-test=signup]');
await click('.ma-Auth [data-test=signup]');

// user lands on index page
assert.equal(currentURL(), '/');
});

test('unauthenticated users cannot create an account with existing users email', async function(assert) {
// user visits login and fills in signup form
await visit('/login');
await fillIn('[name=email]', '[email protected]');
await fillIn('[name=password]', 'Password1234');
await fillIn('[name=password_confirmation]', 'Password1234');
// user clicks signup button
await click('.ma-Auth [data-test=signup]');

// user is still on Login page
assert.equal(currentURL(), '/login');
});

test('unauthenticated user can login to an account with email & password', async function(assert) {
// create an OAuth token
server.create('token');

// user visits login and fills in signup form
await visit('/login');
await fillIn('[name=email]', `mike+${new Date().getTime()}@example.com`);
await fillIn('[name=password]', 'Password1234');
let maLogin = await find('.ma-Login');
await keyEvent(maLogin, 'keyup', 13);
// user clicks login button
await focus('[name=email]');
await click('.ma-Login [data-test=login]');

// user lands on index page
assert.equal(currentURL(), '/');
});

test('authenticated users can visit /login and redirect to /', async function(assert) {
const app = this.application;

authenticateSession(app, {
userId: 1,
otherData: 'some-data'
} from '@ember/test-helpers';
import { authenticateSession } from 'ember-simple-auth/test-support';

module('Application | login', function(hooks) {
setupApplicationTest(hooks);

module('unauthenticated user', function(/* hooks */) {
test('can visit /login', async function(assert) {
await visit('/login');
assert.equal(currentURL(), '/login');
});

test('must supply a strong password', async function(assert) {
await visit('/login');
await fillIn('[name=email]', `mike+${new Date().getTime()}@example.com`);
await fillIn('[name=password]', 'Password');
await blur('[name=password]');
let msg = this.element.querySelector('.ma-Login .help.is-danger')
.textContent;
assert.notEqual(msg.match(/Password must be between/), null);
});

test('cannot create an account without confirming password', async function(assert) {
await visit('/login');
await fillIn('[name=email]', `mike+${new Date().getTime()}@example.com`);
await fillIn('[name=password]', 'Password1234');
await fillIn('[name=password_confirmation]', 'a');
await blur('[name=password_confirmation]');
let msg = this.element.querySelector('.help.is-danger').textContent;
assert.notEqual(msg.match(/password/), null);
assert.dom('[data-test=signup][disabled]').exists({ count: 1 });
});

test('must supply a valid password', async function(assert) {
await visit('/login');
let maLogin = this.element.querySelector('.ma-Login');
await fillIn('[name=email]', '[email protected]');
await fillIn('[name=password]', 'a');
await triggerKeyEvent(maLogin, 'keyup', 13);
await focus('.ma-Login [data-test=login]');
await triggerKeyEvent(maLogin, 'keyup', 13);
assert.dom('.ma-Login button[disabled]').exists({ count: 1 });
});

test('can create an account with email & password', async function(assert) {
// create an OAuth token w/ ember-cli-mirage
server.create('token');
server.create('user');
// user visits login and fills in signup form
await visit('/login');
await fillIn('[name=email]', `mike+${new Date().getTime()}@example.com`);
await fillIn('[name=password]', 'Password1234');
await fillIn('[name=password_confirmation]', 'Password1234');
// user clicks signup button
await focus('.ma-Auth [data-test=signup]');
await click('.ma-Auth [data-test=signup]');

// user lands on index page
assert.equal(currentURL(), '/');
});

test('cannot create an account with existing users email', async function(assert) {
// user visits login and fills in signup form
await visit('/login');
await fillIn('[name=email]', '[email protected]');
await fillIn('[name=password]', 'Password1234');
await fillIn('[name=password_confirmation]', 'Password1234');
// user clicks signup button
await click('.ma-Auth [data-test=signup]');
// user is still on Login page
assert.equal(currentURL(), '/login');
});

test('can login to an account with email & password', async function(assert) {
// create an OAuth token
server.create('token');
// user visits login and fills in signup form
await visit('/login');
await fillIn('[name=email]', `mike+${new Date().getTime()}@example.com`);
await fillIn('[name=password]', 'Password1234');
let maLogin = this.element.querySelector('.ma-Login');
await triggerKeyEvent(maLogin, 'keyup', 13);
// user clicks login button
await focus('[name=email]');
await click('.ma-Login [data-test=login]');
// user lands on index page
assert.equal(currentURL(), '/');
});

test('can click back link to Home', async function(assert) {
// user visits login and fills in signup form
await visit('/login');
// user clicks signup button
await click('.ma-Header .ma-Header-link--back');
// user lands on welcome page
assert.equal(currentURL(), '/welcome');
});
});
await visit('/login');

assert.equal(currentURL(), '/');
});

test('unauthenticated user can click back link to Home', async function(assert) {
// user visits login and fills in signup form
await visit('/login');
// user clicks signup button
await click('.ma-Header .ma-Header-link--back');

// user lands on welcome page
assert.equal(currentURL(), '/welcome');
module('authenticated user', function(hooks) {
hooks.beforeEach(function() {
authenticateSession({
userId: 1,
otherData: 'some-data'
});
});

test('can visit /login and redirect to /', async function(assert) {
await visit('/login');
assert.equal(currentURL(), '/');
});
});
});
Loading

0 comments on commit 7f35173

Please sign in to comment.