test: 💍 Refactor IAM acceptance tests to use predefined ids

This commit is contained in:
Susmitha Girumala committed 2020-07-29 15:43:09 -04:00
1 parent bb30bb4b5f
commit c9fa433663
3 files changed
+123 -76

No files matched your search

+41 -25
View File
@@ -4,6 +4,12 @@ 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 | groups', function (hooks) {
setupApplicationTest(hooks);
@@ -11,6 +17,7 @@ module('Acceptance | groups', function (hooks) {
let orgScope;
let groupsURL;
let groupURL;
let newGroupURL;
hooks.beforeEach(function () {
@@ -22,8 +29,18 @@ module('Acceptance | groups', function (hooks) {
'withChildren'
);
const group = this.server.create('group', {
scope: {
id: orgScope.id,
type: orgScope.type
}
});
groupsURL = `/scopes/${orgScope.id}/groups`;
groupURL = `${groupsURL}/${group.id}`;
newGroupURL = `${groupsURL}/new`;
authenticateSession({});
});
test('visiting groups', async function (assert) {
@@ -33,25 +50,30 @@ module('Acceptance | groups', function (hooks) {
assert.equal(currentURL(), groupsURL);
});
test('visiting a group', async function(assert) {
assert.expect(1);
await visit(newGroupURL);
await a11yAudit();
assert.equal(currentURL(), newGroupURL);
});
test('can create new group', async function (assert) {
assert.expect(4);
assert.equal(this.server.db.groups.length, 0);
assert.expect(1);
const groupsCount = this.server.db.groups.length;
await visit(newGroupURL);
await fillIn('[name="name"]', 'group name');
await click('[type="submit"]');
assert.equal(currentURL(), `${groupsURL}/1`);
assert.equal(this.server.db.groups.length, 1);
assert.equal(this.server.db.groups[0].name, 'group name');
assert.equal(this.server.db.groups.length, groupsCount + 1);
});
test('can cancel new group creation', async function (assert) {
assert.expect(3);
assert.equal(this.server.db.groups.length, 0);
assert.expect(2);
const groupsCount = this.server.db.groups.length;
await visit(newGroupURL);
await fillIn('[name="name"]', 'group name');
await click('.rose-form-actions [type="button"]');
assert.equal(currentURL(), groupsURL);
assert.equal(this.server.db.groups.length, 0);
assert.equal(this.server.db.groups.length, groupsCount);
});
test('saving a new group with invalid fields displays error messages', async function (assert) {
@@ -92,35 +114,31 @@ module('Acceptance | groups', function (hooks) {
test('can save changes to an existing group', async function (assert) {
assert.expect(2);
this.server.createList('group', 1, { name: 'Admin group' });
await visit(`${groupsURL}/1`);
await visit(groupURL);
await fillIn('[name="name"]', 'Updated admin group');
await click('.rose-form-actions [type="submit"]');
assert.equal(currentURL(), `${groupsURL}/1`);
assert.equal(currentURL(), groupURL);
assert.equal(this.server.db.groups[0].name, 'Updated admin group');
});
test('can cancel changes to an existing group', async function (assert) {
assert.expect(1);
this.server.createList('group', 1, { name: 'Admin group' });
await visit(`${groupsURL}/1`);
await visit(groupURL);
await fillIn('[name="name"]', 'Updated admin group');
await click('.rose-form-actions [type="button"]');
assert.equal(find('[name="name"]').value, 'Admin group');
assert.notEqual(find('[name="name"]').value, 'Updated admin group');
});
test('can delete a group', async function (assert) {
assert.expect(2);
this.server.createList('group', 1);
assert.equal(this.server.db.groups.length, 1);
await visit(`${groupsURL}/1`);
assert.expect(1);
const groupsCount = this.server.db.groups.length;
await visit(groupURL);
await click('.rose-button-warning');
assert.equal(this.server.db.groups.length, 0);
assert.equal(this.server.db.groups.length, groupsCount - 1);
});
test('saving an existing group with invalid fields displays error messages', async function (assert) {
assert.expect(2);
this.server.createList('group', 1);
this.server.patch('/scopes/:scope_id/groups/:id', () => {
return new Response(
400,
@@ -140,7 +158,7 @@ module('Acceptance | groups', function (hooks) {
}
);
});
await visit(`${groupsURL}/1`);
await visit(groupURL);
await fillIn('[name="name"]', 'random string');
await click('[type="submit"]');
assert.ok(
@@ -157,7 +175,6 @@ module('Acceptance | groups', function (hooks) {
test('errors are displayed when save project fails', async function (assert) {
assert.expect(1);
this.server.createList('group', 1);
this.server.patch('/scopes/:scope_id/groups/:id', () => {
return new Response(
490,
@@ -169,7 +186,7 @@ module('Acceptance | groups', function (hooks) {
}
);
});
await visit(`${groupsURL}/1`);
await visit(groupURL);
await fillIn('[name="name"]', 'Role name');
await click('[type="submit"]');
assert.ok(
@@ -181,7 +198,6 @@ module('Acceptance | groups', function (hooks) {
test('errors are displayed when delete project fails', async function (assert) {
assert.expect(1);
this.server.createList('group', 1);
this.server.del('/scopes/:scope_id/groups/:id', () => {
return new Response(
490,
@@ -193,7 +209,7 @@ module('Acceptance | groups', function (hooks) {
}
);
});
await visit(`${groupsURL}/1`);
await visit(groupURL);
await click('.rose-button-warning');
assert.ok(
find('[role="alert"]').textContent.trim(),
+41 -25
View File
@@ -4,6 +4,12 @@ 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 | roles', function (hooks) {
setupApplicationTest(hooks);
@@ -11,6 +17,7 @@ module('Acceptance | roles', function (hooks) {
let orgScope;
let rolesURL;
let roleURL;
let newRoleURL;
hooks.beforeEach(function () {
@@ -22,8 +29,18 @@ module('Acceptance | roles', function (hooks) {
'withChildren'
);
const role = this.server.create('role', {
scope: {
id: orgScope.id,
type: orgScope.type
}
})
rolesURL = `/scopes/${orgScope.id}/roles`;
roleURL = `${rolesURL}/${role.id}`;
newRoleURL = `${rolesURL}/new`;
authenticateSession({});
});
test('visiting roles', async function (assert) {
@@ -33,25 +50,30 @@ module('Acceptance | roles', function (hooks) {
assert.equal(currentURL(), rolesURL);
});
test('visiting a role', async function(assert) {
assert.expect(1);
await visit(newRoleURL);
await a11yAudit();
assert.equal(currentURL(), newRoleURL);
});
test('can create new role', async function (assert) {
assert.expect(4);
assert.equal(this.server.db.roles.length, 0);
assert.expect(1);
const rolesCount = this.server.db.roles.length;
await visit(newRoleURL);
await fillIn('[name="name"]', 'role name');
await click('[type="submit"]');
assert.equal(currentURL(), `${rolesURL}/1`);
assert.equal(this.server.db.roles.length, 1);
assert.equal(this.server.db.roles[0].name, 'role name');
assert.equal(this.server.db.roles.length, rolesCount + 1);
});
test('can cancel new role creation', async function (assert) {
assert.expect(3);
assert.equal(this.server.db.roles.length, 0);
assert.expect(2);
const rolesCount = this.server.db.roles.length;
await visit(newRoleURL);
await fillIn('[name="name"]', 'role name');
await click('.rose-form-actions [type="button"]');
assert.equal(currentURL(), rolesURL);
assert.equal(this.server.db.roles.length, 0);
assert.equal(this.server.db.roles.length, rolesCount);
});
test('saving a new role with invalid fields displays error messages', async function (assert) {
@@ -92,35 +114,31 @@ module('Acceptance | roles', function (hooks) {
test('can save changes to an existing role', async function (assert) {
assert.expect(2);
this.server.createList('role', 1, { name: 'Admin role' });
await visit(`${rolesURL}/1`);
await visit(roleURL);
await fillIn('[name="name"]', 'Updated admin role');
await click('.rose-form-actions [type="submit"]');
assert.equal(currentURL(), `${rolesURL}/1`);
assert.equal(currentURL(), roleURL);
assert.equal(this.server.db.roles[0].name, 'Updated admin role');
});
test('can cancel changes to an existing role', async function (assert) {
assert.expect(1);
this.server.createList('role', 1, { name: 'Admin role' });
await visit(`${rolesURL}/1`);
await visit(roleURL);
await fillIn('[name="name"]', 'Updated admin role');
await click('.rose-form-actions [type="button"]');
assert.equal(find('[name="name"]').value, 'Admin role');
assert.notEqual(find('[name="name"]').value, 'Updated admin role');
});
test('can delete a role', async function (assert) {
assert.expect(2);
this.server.createList('role', 1);
assert.equal(this.server.db.roles.length, 1);
await visit(`${rolesURL}/1`);
assert.expect(1);
const rolesCount = this.server.db.roles.length;
await visit(roleURL);
await click('.rose-button-warning');
assert.equal(this.server.db.roles.length, 0);
assert.equal(this.server.db.roles.length, rolesCount - 1);
});
test('saving an existing role with invalid fields displays error messages', async function (assert) {
assert.expect(2);
this.server.createList('role', 1);
this.server.patch('/scopes/:scope_id/roles/:id', () => {
return new Response(
400,
@@ -140,7 +158,7 @@ module('Acceptance | roles', function (hooks) {
}
);
});
await visit(`${rolesURL}/1`);
await visit(roleURL);
await fillIn('[name="name"]', 'random string');
await click('[type="submit"]');
assert.ok(
@@ -157,7 +175,6 @@ module('Acceptance | roles', function (hooks) {
test('errors are displayed when save project fails', async function (assert) {
assert.expect(1);
this.server.createList('role', 1);
this.server.patch('/scopes/:scope_id/roles/:id', () => {
return new Response(
490,
@@ -169,7 +186,7 @@ module('Acceptance | roles', function (hooks) {
}
);
});
await visit(`${rolesURL}/1`);
await visit(roleURL);
await fillIn('[name="name"]', 'Role name');
await click('[type="submit"]');
assert.ok(
@@ -181,7 +198,6 @@ module('Acceptance | roles', function (hooks) {
test('errors are displayed when delete project fails', async function (assert) {
assert.expect(1);
this.server.createList('role', 1);
this.server.del('/scopes/:scope_id/roles/:id', () => {
return new Response(
490,
@@ -193,7 +209,7 @@ module('Acceptance | roles', function (hooks) {
}
);
});
await visit(`${rolesURL}/1`);
await visit(roleURL);
await click('.rose-button-warning');
assert.ok(
find('[role="alert"]').textContent.trim(),
+41 -26
View File
@@ -4,6 +4,12 @@ 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 | users', function (hooks) {
setupApplicationTest(hooks);
@@ -11,6 +17,7 @@ module('Acceptance | users', function (hooks) {
let orgScope;
let usersURL;
let userURL;
let newUserURL;
hooks.beforeEach(function () {
@@ -22,37 +29,51 @@ module('Acceptance | users', function (hooks) {
'withChildren'
);
const user = this.server.create('user', {
scope: {
id: orgScope.id,
type: orgScope.type
}
});
usersURL = `/scopes/${orgScope.id}/users`;
userURL = `${usersURL}/${user.id}`;
newUserURL = `${usersURL}/new`;
authenticateSession({});
});
test('visiting users', async function (assert) {
assert.expect(1);
this.server.createList('user', 1);
await visit(usersURL);
await a11yAudit();
assert.equal(currentURL(), usersURL);
});
test('visiting a user', async function(assert) {
assert.expect(1);
await visit(newUserURL);
await a11yAudit();
assert.equal(currentURL(), newUserURL);
});
test('can create new users', async function (assert) {
assert.expect(4);
assert.equal(this.server.db.users.length, 0);
assert.expect(1);
const usersCount = this.server.db.users.length;
await visit(newUserURL);
await fillIn('[name="name"]', 'User name');
await click('[type="submit"]');
assert.equal(currentURL(), `${usersURL}/1`);
assert.equal(this.server.db.users.length, 1);
assert.equal(this.server.db.users[0].name, 'User name');
assert.equal(this.server.db.users.length, usersCount + 1);
});
test('can cancel creation of a new user', async function (assert) {
assert.expect(3);
assert.equal(this.server.db.users.length, 0);
assert.expect(2);
const usersCount = this.server.db.users.length;
await visit(newUserURL);
await fillIn('[name="name"]', 'User name');
await click('.rose-form-actions [type="button"]');
assert.equal(currentURL(), usersURL);
assert.equal(this.server.db.users.length, 0);
assert.equal(this.server.db.users.length, usersCount);
});
test('saving a new user with invalid fields displays error messages', async function (assert) {
@@ -93,35 +114,31 @@ module('Acceptance | users', function (hooks) {
test('can save changes to an existing user', async function (assert) {
assert.expect(2);
this.server.createList('user', 1, { name: 'Test User' });
await visit(`${usersURL}/1`);
await visit(userURL);
await fillIn('[name="name"]', 'Updated user name');
await click('.rose-form-actions [type="submit"]');
assert.equal(currentURL(), `${usersURL}/1`);
assert.equal(currentURL(), userURL);
assert.equal(this.server.db.users[0].name, 'Updated user name');
});
test('can cancel changes to an existing user', async function (assert) {
assert.expect(1);
this.server.createList('user', 1, { name: 'Test User' });
await visit(`${usersURL}/1`);
await visit(userURL);
await fillIn('[name="name"]', 'Unsaved user name');
await click('.rose-form-actions [type="button"]');
assert.equal(find('[name="name"]').value, 'Test User');
assert.notEqual(find('[name="name"]').value, 'Unsaved user name');
});
test('can delete an user', async function (assert) {
assert.expect(2);
this.server.createList('user', 1);
assert.equal(this.server.db.users.length, 1);
await visit(`${usersURL}/1`);
assert.expect(1);
const usersCount = this.server.db.users.length;
await visit(userURL);
await click('.rose-button-warning');
assert.equal(this.server.db.users.length, 0);
assert.equal(this.server.db.users.length, usersCount - 1);
});
test('saving an existing user with invalid fields displays error messages', async function (assert) {
assert.expect(2);
this.server.createList('user', 1);
this.server.patch('/scopes/:scope_id/users/:id', () => {
return new Response(
400,
@@ -141,7 +158,7 @@ module('Acceptance | users', function (hooks) {
}
);
});
await visit(`${usersURL}/1`);
await visit(userURL);
await fillIn('[name="name"]', 'User name');
await click('[type="submit"]');
assert.ok(
@@ -158,7 +175,6 @@ module('Acceptance | users', function (hooks) {
test('errors are displayed when saving user fails', async function (assert) {
assert.expect(1);
this.server.createList('user', 1);
this.server.patch('/scopes/:scope_id/users/:id', () => {
return new Response(
490,
@@ -170,7 +186,7 @@ module('Acceptance | users', function (hooks) {
}
);
});
await visit(`${usersURL}/1`);
await visit(userURL);
await fillIn('[name="name"]', 'User name');
await click('[type="submit"]');
assert.ok(
@@ -182,7 +198,6 @@ module('Acceptance | users', function (hooks) {
test('errors are displayed when user deletion fails', async function (assert) {
assert.expect(1);
this.server.createList('user', 1);
this.server.del('/scopes/:scope_id/users/:id', () => {
return new Response(
490,
@@ -194,7 +209,7 @@ module('Acceptance | users', function (hooks) {
}
);
});
await visit(`${usersURL}/1`);
await visit(userURL);
await click('.rose-button-warning');
assert.ok(
find('[role="alert"]').textContent.trim(),