test: Add change password account acceptance test
This commit is contained in:
3 files changed
+225
-52
No files matched your search
@@ -6,9 +6,9 @@ import a11yAudit from 'ember-a11y-testing/test-support/audit';
|
||||
import { Response } from 'miragejs';
|
||||
import {
|
||||
authenticateSession,
|
||||
// // These are left here intentionally for future reference.
|
||||
// //currentSession,
|
||||
// //invalidateSession,
|
||||
// These are left here intentionally for future reference.
|
||||
//currentSession,
|
||||
//invalidateSession,
|
||||
} from 'ember-simple-auth/test-support';
|
||||
|
||||
module('Acceptance | accounts', function (hooks) {
|
||||
@@ -29,7 +29,6 @@ module('Acceptance | accounts', function (hooks) {
|
||||
accounts: null,
|
||||
newAccount: null,
|
||||
account: null,
|
||||
setAccountPassword: null,
|
||||
};
|
||||
|
||||
hooks.beforeEach(function () {
|
||||
@@ -46,7 +45,6 @@ module('Acceptance | accounts', function (hooks) {
|
||||
scope: instances.scopes.org,
|
||||
authMethod: instances.authMethod,
|
||||
});
|
||||
|
||||
// Generate route URLs for resources
|
||||
urls.orgScope = `/scopes/${instances.scopes.org.id}`;
|
||||
urls.authMethods = `${urls.orgScope}/auth-methods`;
|
||||
@@ -54,7 +52,6 @@ module('Acceptance | accounts', function (hooks) {
|
||||
urls.accounts = `${urls.authMethod}/accounts`;
|
||||
urls.newAccount = `${urls.accounts}/new`;
|
||||
urls.account = `${urls.accounts}/${instances.account.id}`;
|
||||
urls.setAccountPassword = `${urls.accounts}/${instances.account.id}/set-password`;
|
||||
});
|
||||
|
||||
hooks.afterEach(async function() {
|
||||
@@ -245,50 +242,4 @@ module('Acceptance | accounts', function (hooks) {
|
||||
'Displays field-level errors.'
|
||||
);
|
||||
});
|
||||
|
||||
module('password', function() {
|
||||
test('can set a new password for account', async function (assert) {
|
||||
assert.expect(1);
|
||||
this.server.post('/accounts/:id', (_, { requestBody }) => {
|
||||
const attrs = JSON.parse(requestBody);
|
||||
assert.equal(attrs.password, 'update password', 'new password is set');
|
||||
});
|
||||
await visit(urls.setAccountPassword);
|
||||
await fillIn('[name="password"]', 'update password');
|
||||
await click('form [type="submit"]:not(:disabled)');
|
||||
await a11yAudit();
|
||||
});
|
||||
|
||||
test('can cancel setting new password', async function (assert) {
|
||||
assert.expect(1);
|
||||
await visit(urls.setAccountPassword);
|
||||
await fillIn('[name="password"]', 'update password');
|
||||
await click('form button:not([type="submit"])');
|
||||
assert.notOk(find('[name="password"]').textContent.trim());
|
||||
});
|
||||
|
||||
test('errors are displayed when setting password fails', async function (assert) {
|
||||
assert.expect(1);
|
||||
this.server.post('/accounts/:id', () => {
|
||||
return new Response(
|
||||
490,
|
||||
{},
|
||||
{
|
||||
status: 490,
|
||||
code: 'error',
|
||||
message: 'Oops.',
|
||||
}
|
||||
);
|
||||
});
|
||||
await visit(urls.setAccountPassword);
|
||||
await fillIn('[name="password"]', 'update password');
|
||||
await click('form [type="submit"]');
|
||||
await a11yAudit();
|
||||
assert.ok(
|
||||
find('[role="alert"]').textContent.trim(),
|
||||
'Oops.',
|
||||
'Displays primary error message.'
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,117 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { visit, currentURL, click, find, fillIn } from '@ember/test-helpers';
|
||||
import { setupApplicationTest } from 'ember-qunit';
|
||||
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
|
||||
import a11yAudit from 'ember-a11y-testing/test-support/audit';
|
||||
import { Response } from 'miragejs';
|
||||
import {
|
||||
authenticateSession,
|
||||
// These are left here intentionally for future reference.
|
||||
// currentSession,
|
||||
invalidateSession,
|
||||
} from 'ember-simple-auth/test-support';
|
||||
|
||||
module('Acceptance | accounts | change password', function (hooks) {
|
||||
setupApplicationTest(hooks);
|
||||
setupMirage(hooks);
|
||||
|
||||
const instances = {
|
||||
scopes: {
|
||||
global: null,
|
||||
org: null,
|
||||
},
|
||||
account: null,
|
||||
};
|
||||
const urls = {
|
||||
orgScope: null,
|
||||
changePassword: null,
|
||||
};
|
||||
|
||||
hooks.beforeEach(function () {
|
||||
instances.scopes.global = this.server.create('scope', { id: 'global' });
|
||||
instances.scopes.org = this.server.create('scope', {
|
||||
type: 'org',
|
||||
scope: { id: 'global', type: 'global' },
|
||||
});
|
||||
instances.authMethod = this.server.create('auth-method', {
|
||||
scope: instances.scopes.org,
|
||||
});
|
||||
instances.account = this.server.create('account', {
|
||||
scope: instances.scopes.org
|
||||
});
|
||||
authenticateSession({
|
||||
account_id: instances.account.id
|
||||
});
|
||||
// Generate route URLs for resources
|
||||
urls.orgScope = `/scopes/${instances.scopes.org.id}`;
|
||||
urls.changePassword = `/account/change-password`;
|
||||
});
|
||||
|
||||
test('visiting account change password', async function (assert) {
|
||||
assert.expect(1);
|
||||
await visit(urls.changePassword);
|
||||
await a11yAudit();
|
||||
assert.equal(currentURL(), urls.changePassword);
|
||||
});
|
||||
|
||||
test('visiting account change password from header', async function (assert) {
|
||||
assert.expect(1);
|
||||
await visit(urls.orgScope);
|
||||
// Open header utilities dropdown
|
||||
await click('.rose-header-utilities .rose-dropdown summary');
|
||||
// Find first element in dropdown - should be change password link
|
||||
await click('.rose-header-utilities .rose-dropdown .rose-dropdown-content a');
|
||||
assert.equal(currentURL(), urls.changePassword);
|
||||
});
|
||||
|
||||
test('can change password for account', async function (assert) {
|
||||
assert.expect(2);
|
||||
this.server.post('/accounts/:id', (_, { requestBody }) => {
|
||||
const attrs = JSON.parse(requestBody);
|
||||
assert.equal(attrs.current_password, 'current password', 'current password is provided');
|
||||
assert.equal(attrs.new_password, 'new password', 'new password is provided');
|
||||
});
|
||||
await visit(urls.changePassword);
|
||||
await fillIn('[name="currentPassword"]', 'current password');
|
||||
await fillIn('[name="newPassword"]', 'new password');
|
||||
await click('form [type="submit"]:not(:disabled)');
|
||||
await a11yAudit();
|
||||
});
|
||||
|
||||
test('can cancel password change', async function (assert) {
|
||||
assert.expect(1);
|
||||
await visit(urls.changePassword);
|
||||
await fillIn('[name="currentPassword"]', 'current password');
|
||||
await fillIn('[name="newPassword"]', 'new password');
|
||||
await click('form button:not([type="submit"])');
|
||||
assert.notEqual(currentURL(), urls.changePassword);
|
||||
});
|
||||
|
||||
test('errors are displayed when changing password fails', async function (assert) {
|
||||
assert.expect(1);
|
||||
this.server.post('/accounts/:id', () => {
|
||||
return new Response(
|
||||
490,
|
||||
{},
|
||||
{
|
||||
status: 490,
|
||||
code: 'error',
|
||||
message: 'Oops.',
|
||||
}
|
||||
);
|
||||
});
|
||||
await visit(urls.changePassword);
|
||||
await fillIn('[name="currentPassword"]', 'current password');
|
||||
await fillIn('[name="newPassword"]', 'new password');
|
||||
await click('form [type="submit"]');
|
||||
await a11yAudit();
|
||||
assert.ok(find('[role="alert"]'));
|
||||
});
|
||||
|
||||
test('cannot change password when not authenticated', async function(assert) {
|
||||
assert.expect(1);
|
||||
invalidateSession();
|
||||
await visit(urls.changePassword);
|
||||
assert.notEqual(currentURL(), urls.changePassword);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,105 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { visit, currentURL, click, find, fillIn } from '@ember/test-helpers';
|
||||
import { setupApplicationTest } from 'ember-qunit';
|
||||
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
|
||||
import a11yAudit from 'ember-a11y-testing/test-support/audit';
|
||||
import { Response } from 'miragejs';
|
||||
import {
|
||||
authenticateSession,
|
||||
// These are left here intentionally for future reference.
|
||||
//currentSession,
|
||||
//invalidateSession,
|
||||
} from 'ember-simple-auth/test-support';
|
||||
|
||||
module('Acceptance | accounts | set password', function (hooks) {
|
||||
setupApplicationTest(hooks);
|
||||
setupMirage(hooks);
|
||||
|
||||
const instances = {
|
||||
scopes: {
|
||||
global: null,
|
||||
org: null,
|
||||
},
|
||||
authMethods: null,
|
||||
account: null,
|
||||
};
|
||||
const urls = {
|
||||
orgScope: null,
|
||||
authMethods: null,
|
||||
accounts: null,
|
||||
setPassword: null,
|
||||
};
|
||||
|
||||
hooks.beforeEach(function () {
|
||||
authenticateSession({});
|
||||
instances.scopes.global = this.server.create('scope', { id: 'global' });
|
||||
instances.scopes.org = this.server.create('scope', {
|
||||
type: 'org',
|
||||
scope: { id: 'global', type: 'global' },
|
||||
});
|
||||
instances.authMethod = this.server.create('auth-method', {
|
||||
scope: instances.scopes.org,
|
||||
});
|
||||
instances.account = this.server.create('account', {
|
||||
scope: instances.scopes.org,
|
||||
authMethod: instances.authMethod,
|
||||
});
|
||||
// Generate route URLs for resources
|
||||
urls.orgScope = `/scopes/${instances.scopes.org.id}`;
|
||||
urls.authMethods = `${urls.orgScope}/auth-methods`;
|
||||
urls.authMethod = `${urls.authMethods}/${instances.authMethod.id}`;
|
||||
urls.accounts = `${urls.authMethod}/accounts`;
|
||||
urls.setPassword = `${urls.accounts}/${instances.account.id}/set-password`;
|
||||
});
|
||||
|
||||
test('visiting account set password', async function (assert) {
|
||||
assert.expect(1);
|
||||
await visit(urls.setPassword);
|
||||
await a11yAudit();
|
||||
assert.equal(currentURL(), urls.setPassword);
|
||||
});
|
||||
|
||||
test('can set a new password for account', async function (assert) {
|
||||
assert.expect(1);
|
||||
this.server.post('/accounts/:id', (_, { requestBody }) => {
|
||||
const attrs = JSON.parse(requestBody);
|
||||
assert.equal(attrs.password, 'update password', 'new password is set');
|
||||
});
|
||||
await visit(urls.setPassword);
|
||||
await fillIn('[name="password"]', 'update password');
|
||||
await click('form [type="submit"]:not(:disabled)');
|
||||
await a11yAudit();
|
||||
});
|
||||
|
||||
test('can cancel setting new password', async function (assert) {
|
||||
assert.expect(1);
|
||||
await visit(urls.setPassword);
|
||||
await fillIn('[name="password"]', 'update password');
|
||||
await click('form button:not([type="submit"])');
|
||||
assert.notOk(find('[name="password"]').textContent.trim());
|
||||
});
|
||||
|
||||
test('errors are displayed when setting password fails', async function (assert) {
|
||||
assert.expect(1);
|
||||
this.server.post('/accounts/:id', () => {
|
||||
return new Response(
|
||||
490,
|
||||
{},
|
||||
{
|
||||
status: 490,
|
||||
code: 'error',
|
||||
message: 'Oops.',
|
||||
}
|
||||
);
|
||||
});
|
||||
await visit(urls.setPassword);
|
||||
await fillIn('[name="password"]', 'update password');
|
||||
await click('form [type="submit"]');
|
||||
await a11yAudit();
|
||||
assert.ok(
|
||||
find('[role="alert"]').textContent.trim(),
|
||||
'Oops.',
|
||||
'Displays primary error message.'
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user