2019-01-02 12:58:55 +03:00
|
|
|
import {click, fillIn, find, findAll, visit} from '@ember/test-helpers';
|
|
|
|
import {describe, it} from 'mocha';
|
2017-05-29 21:50:03 +03:00
|
|
|
import {expect} from 'chai';
|
2019-01-02 12:58:55 +03:00
|
|
|
import {invalidateSession} from 'ember-simple-auth/test-support';
|
|
|
|
import {setupApplicationTest} from 'ember-mocha';
|
2019-05-27 11:37:05 +03:00
|
|
|
import {setupMirage} from 'ember-cli-mirage/test-support';
|
2016-02-02 15:22:41 +03:00
|
|
|
|
2018-01-05 18:38:23 +03:00
|
|
|
describe('Acceptance: Password Reset', function () {
|
2019-01-02 12:58:55 +03:00
|
|
|
let hooks = setupApplicationTest();
|
|
|
|
setupMirage(hooks);
|
2016-02-02 15:22:41 +03:00
|
|
|
|
|
|
|
describe('request reset', function () {
|
2017-04-24 15:29:48 +03:00
|
|
|
it('is successful with valid data', async function () {
|
2019-01-02 12:58:55 +03:00
|
|
|
await invalidateSession();
|
2017-04-24 15:29:48 +03:00
|
|
|
await visit('/signin');
|
|
|
|
await fillIn('input[name="identification"]', 'test@example.com');
|
|
|
|
await click('.forgotten-link');
|
|
|
|
|
|
|
|
// an alert with instructions is displayed
|
2019-01-02 12:58:55 +03:00
|
|
|
expect(findAll('.gh-alert-blue').length, 'alert count')
|
2017-04-24 15:29:48 +03:00
|
|
|
.to.equal(1);
|
2016-02-02 15:22:41 +03:00
|
|
|
});
|
|
|
|
|
2017-04-24 15:29:48 +03:00
|
|
|
it('shows error messages with invalid data', async function () {
|
|
|
|
await visit('/signin');
|
2016-02-02 15:22:41 +03:00
|
|
|
|
|
|
|
// no email provided
|
2017-04-24 15:29:48 +03:00
|
|
|
await click('.forgotten-link');
|
|
|
|
|
|
|
|
// email field is invalid
|
|
|
|
expect(
|
2019-01-02 12:58:55 +03:00
|
|
|
find('input[name="identification"]').closest('.form-group'),
|
2017-04-24 15:29:48 +03:00
|
|
|
'email field has error class (no email)'
|
2019-01-02 12:58:55 +03:00
|
|
|
).to.match('.error');
|
2017-04-24 15:29:48 +03:00
|
|
|
|
|
|
|
// password field is valid
|
|
|
|
expect(
|
2019-01-02 12:58:55 +03:00
|
|
|
find('input[name="password"]').closest('.form-group'),
|
2017-04-24 15:29:48 +03:00
|
|
|
'password field has error class (no email)'
|
2019-01-02 12:58:55 +03:00
|
|
|
).to.not.match('.error');
|
2017-04-24 15:29:48 +03:00
|
|
|
|
|
|
|
// error message shown
|
2019-01-02 12:58:55 +03:00
|
|
|
expect(find('p.main-error').textContent.trim(), 'error message')
|
2017-04-24 15:29:48 +03:00
|
|
|
.to.equal('We need your email address to reset your password!');
|
2016-02-02 15:22:41 +03:00
|
|
|
|
|
|
|
// invalid email provided
|
2017-04-24 15:29:48 +03:00
|
|
|
await fillIn('input[name="identification"]', 'test');
|
|
|
|
await click('.forgotten-link');
|
|
|
|
|
|
|
|
// email field is invalid
|
|
|
|
expect(
|
2019-01-02 12:58:55 +03:00
|
|
|
find('input[name="identification"]').closest('.form-group'),
|
2017-04-24 15:29:48 +03:00
|
|
|
'email field has error class (invalid email)'
|
2019-01-02 12:58:55 +03:00
|
|
|
).to.match('.error');
|
2017-04-24 15:29:48 +03:00
|
|
|
|
|
|
|
// password field is valid
|
|
|
|
expect(
|
2019-01-02 12:58:55 +03:00
|
|
|
find('input[name="password"]').closest('.form-group'),
|
2017-04-24 15:29:48 +03:00
|
|
|
'password field has error class (invalid email)'
|
2019-01-02 12:58:55 +03:00
|
|
|
).to.not.match('.error');
|
2017-04-24 15:29:48 +03:00
|
|
|
|
|
|
|
// error message
|
2019-01-02 12:58:55 +03:00
|
|
|
expect(find('p.main-error').textContent.trim(), 'error message')
|
2017-04-24 15:29:48 +03:00
|
|
|
.to.equal('We need your email address to reset your password!');
|
2016-02-02 15:22:41 +03:00
|
|
|
|
|
|
|
// unknown email provided
|
2017-04-24 15:29:48 +03:00
|
|
|
await fillIn('input[name="identification"]', 'unknown@example.com');
|
|
|
|
await click('.forgotten-link');
|
|
|
|
|
|
|
|
// email field is invalid
|
|
|
|
expect(
|
2019-01-02 12:58:55 +03:00
|
|
|
find('input[name="identification"]').closest('.form-group'),
|
2017-04-24 15:29:48 +03:00
|
|
|
'email field has error class (unknown email)'
|
2019-01-02 12:58:55 +03:00
|
|
|
).to.match('.error');
|
2017-04-24 15:29:48 +03:00
|
|
|
|
|
|
|
// password field is valid
|
|
|
|
expect(
|
2019-01-02 12:58:55 +03:00
|
|
|
find('input[name="password"]').closest('.form-group'),
|
2017-04-24 15:29:48 +03:00
|
|
|
'password field has error class (unknown email)'
|
2019-01-02 12:58:55 +03:00
|
|
|
).to.not.match('.error');
|
2017-04-24 15:29:48 +03:00
|
|
|
|
|
|
|
// error message
|
2019-01-02 12:58:55 +03:00
|
|
|
expect(find('p.main-error').textContent.trim(), 'error message')
|
2017-04-24 15:29:48 +03:00
|
|
|
.to.equal('There is no user with that email address.');
|
2016-02-02 15:22:41 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// TODO: add tests for the change password screen
|
|
|
|
});
|