test: Add group members acceptance test
This commit is contained in:
2 files changed
+180
-51
No files matched your search
@@ -15,49 +15,53 @@ module('Acceptance | groups', function (hooks) {
|
||||
setupApplicationTest(hooks);
|
||||
setupMirage(hooks);
|
||||
|
||||
let orgScope;
|
||||
let groupsURL;
|
||||
let groupURL;
|
||||
let newGroupURL;
|
||||
const instances = {
|
||||
scopes: {
|
||||
global: null,
|
||||
org: null,
|
||||
},
|
||||
group: null,
|
||||
};
|
||||
const urls = {
|
||||
orgScope: null,
|
||||
groups: null,
|
||||
group: null,
|
||||
newGroup: null,
|
||||
};
|
||||
|
||||
hooks.beforeEach(function () {
|
||||
orgScope = this.server.create(
|
||||
'scope',
|
||||
{
|
||||
type: 'org',
|
||||
},
|
||||
'withChildren'
|
||||
);
|
||||
|
||||
const group = this.server.create('group', {
|
||||
scope: orgScope,
|
||||
});
|
||||
|
||||
groupsURL = `/scopes/${orgScope.id}/groups`;
|
||||
groupURL = `${groupsURL}/${group.id}`;
|
||||
newGroupURL = `${groupsURL}/new`;
|
||||
|
||||
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.group = this.server.create('group', {
|
||||
scope: instances.scopes.org,
|
||||
});
|
||||
urls.groups = `/scopes/${instances.scopes.org.id}/groups`;
|
||||
urls.group = `${urls.groups}/${instances.group.id}`;
|
||||
urls.newGroup = `${urls.groups}/new`;
|
||||
});
|
||||
|
||||
test('visiting groups', async function (assert) {
|
||||
assert.expect(1);
|
||||
await visit(groupsURL);
|
||||
await visit(urls.groups);
|
||||
await a11yAudit();
|
||||
assert.equal(currentURL(), groupsURL);
|
||||
assert.equal(currentURL(), urls.groups);
|
||||
});
|
||||
|
||||
test('visiting a group', async function (assert) {
|
||||
assert.expect(1);
|
||||
await visit(newGroupURL);
|
||||
await visit(urls.newGroup);
|
||||
await a11yAudit();
|
||||
assert.equal(currentURL(), newGroupURL);
|
||||
assert.equal(currentURL(), urls.newGroup);
|
||||
});
|
||||
|
||||
test('can create new group', async function (assert) {
|
||||
assert.expect(1);
|
||||
const groupsCount = this.server.db.groups.length;
|
||||
await visit(newGroupURL);
|
||||
await visit(urls.newGroup);
|
||||
await fillIn('[name="name"]', 'group name');
|
||||
await click('[type="submit"]');
|
||||
assert.equal(this.server.db.groups.length, groupsCount + 1);
|
||||
@@ -66,10 +70,10 @@ module('Acceptance | groups', function (hooks) {
|
||||
test('can cancel new group creation', async function (assert) {
|
||||
assert.expect(2);
|
||||
const groupsCount = this.server.db.groups.length;
|
||||
await visit(newGroupURL);
|
||||
await visit(urls.newGroup);
|
||||
await fillIn('[name="name"]', 'group name');
|
||||
await click('.rose-form-actions [type="button"]');
|
||||
assert.equal(currentURL(), groupsURL);
|
||||
assert.equal(currentURL(), urls.groups);
|
||||
assert.equal(this.server.db.groups.length, groupsCount);
|
||||
});
|
||||
|
||||
@@ -94,7 +98,7 @@ module('Acceptance | groups', function (hooks) {
|
||||
}
|
||||
);
|
||||
});
|
||||
await visit(newGroupURL);
|
||||
await visit(urls.newGroup);
|
||||
await fillIn('[name="name"]', 'group name');
|
||||
await click('[type="submit"]');
|
||||
assert.ok(
|
||||
@@ -111,16 +115,16 @@ module('Acceptance | groups', function (hooks) {
|
||||
|
||||
test('can save changes to an existing group', async function (assert) {
|
||||
assert.expect(2);
|
||||
await visit(groupURL);
|
||||
await visit(urls.group);
|
||||
await fillIn('[name="name"]', 'Updated admin group');
|
||||
await click('.rose-form-actions [type="submit"]');
|
||||
assert.equal(currentURL(), groupURL);
|
||||
assert.equal(currentURL(), urls.group);
|
||||
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);
|
||||
await visit(groupURL);
|
||||
await visit(urls.group);
|
||||
await fillIn('[name="name"]', 'Updated admin group');
|
||||
await click('.rose-form-actions [type="button"]');
|
||||
assert.notEqual(find('[name="name"]').value, 'Updated admin group');
|
||||
@@ -129,7 +133,7 @@ module('Acceptance | groups', function (hooks) {
|
||||
test('can delete a group', async function (assert) {
|
||||
assert.expect(1);
|
||||
const groupsCount = this.server.db.groups.length;
|
||||
await visit(groupURL);
|
||||
await visit(urls.group);
|
||||
await click('.rose-layout-page-actions .rose-dropdown-button-danger');
|
||||
assert.equal(this.server.db.groups.length, groupsCount - 1);
|
||||
});
|
||||
@@ -155,7 +159,7 @@ module('Acceptance | groups', function (hooks) {
|
||||
}
|
||||
);
|
||||
});
|
||||
await visit(groupURL);
|
||||
await visit(urls.group);
|
||||
await fillIn('[name="name"]', 'random string');
|
||||
await click('[type="submit"]');
|
||||
assert.ok(
|
||||
@@ -183,7 +187,7 @@ module('Acceptance | groups', function (hooks) {
|
||||
}
|
||||
);
|
||||
});
|
||||
await visit(groupURL);
|
||||
await visit(urls.group);
|
||||
await fillIn('[name="name"]', 'Role name');
|
||||
await click('[type="submit"]');
|
||||
assert.ok(
|
||||
@@ -206,7 +210,7 @@ module('Acceptance | groups', function (hooks) {
|
||||
}
|
||||
);
|
||||
});
|
||||
await visit(groupURL);
|
||||
await visit(urls.group);
|
||||
await click('.rose-layout-page-actions .rose-dropdown-button-danger');
|
||||
assert.ok(
|
||||
find('[role="alert"]').textContent.trim(),
|
||||
@@ -214,20 +218,4 @@ module('Acceptance | groups', function (hooks) {
|
||||
'Displays primary error message.'
|
||||
);
|
||||
});
|
||||
|
||||
test('can view group members', async function (assert) {
|
||||
assert.expect(0);
|
||||
});
|
||||
|
||||
test('can delete members', async function (assert) {
|
||||
assert.expect(0);
|
||||
});
|
||||
|
||||
test('select and save members to add', async function (assert) {
|
||||
assert.expect(0);
|
||||
});
|
||||
|
||||
test('select and cancel members to add', async function (assert) {
|
||||
assert.expect(0);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,141 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { visit, currentURL, click, find, findAll } 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 | groups | members', function (hooks) {
|
||||
setupApplicationTest(hooks);
|
||||
setupMirage(hooks);
|
||||
|
||||
const instances = {
|
||||
scopes: {
|
||||
global: null,
|
||||
org: null,
|
||||
},
|
||||
group: null,
|
||||
};
|
||||
const urls = {
|
||||
orgScope: null,
|
||||
groups: null,
|
||||
group: null,
|
||||
members: null,
|
||||
addMembers: null,
|
||||
};
|
||||
let membersCount;
|
||||
|
||||
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.group = this.server.create('group', {
|
||||
scope: instances.scopes.org,
|
||||
}, 'withMembers');
|
||||
membersCount = instances.group.memberIds.length;
|
||||
urls.groups = `/scopes/${instances.scopes.org.id}/groups`;
|
||||
urls.group = `${urls.groups}/${instances.group.id}`;
|
||||
urls.members = `${urls.group}/members`;
|
||||
urls.addMembers = `${urls.group}/add-members`;
|
||||
});
|
||||
|
||||
test('visiting group members', async function (assert) {
|
||||
assert.expect(2);
|
||||
await visit(urls.members);
|
||||
await a11yAudit();
|
||||
assert.equal(currentURL(), urls.members);
|
||||
assert.equal(findAll('tbody tr').length, membersCount);
|
||||
});
|
||||
|
||||
test('can delete a member', async function (assert) {
|
||||
assert.expect(2);
|
||||
await visit(urls.members);
|
||||
assert.equal(findAll('tbody tr').length, membersCount);
|
||||
await click('tbody tr .rose-dropdown-button-danger');
|
||||
assert.equal(findAll('tbody tr').length, membersCount - 1);
|
||||
});
|
||||
|
||||
test('shows error message on member remove', async function (assert) {
|
||||
assert.expect(2);
|
||||
this.server.post('/groups/:idMethod', () => {
|
||||
return new Response(
|
||||
400,
|
||||
{},
|
||||
{
|
||||
status: 400,
|
||||
code: 'invalid_argument',
|
||||
message: 'The request was invalid.',
|
||||
details: {},
|
||||
}
|
||||
);
|
||||
});
|
||||
await visit(urls.members);
|
||||
assert.equal(findAll('tbody tr').length, membersCount);
|
||||
await click('tbody tr .rose-dropdown-button-danger');
|
||||
assert.ok(find('[role="alert"]'));
|
||||
});
|
||||
|
||||
test('visiting member selection', async function(assert) {
|
||||
assert.expect(1);
|
||||
await visit(urls.addMembers);
|
||||
await a11yAudit();
|
||||
assert.equal(currentURL(), urls.addMembers);
|
||||
});
|
||||
|
||||
test('select and save members to add', async function (assert) {
|
||||
assert.expect(3);
|
||||
instances.group.update({ memberIds: [] });
|
||||
await visit(urls.members);
|
||||
assert.equal(findAll('tbody tr').length, 0);
|
||||
await click('.rose-layout-page-actions a')
|
||||
assert.equal(currentURL(), urls.addMembers);
|
||||
await click('tbody label');
|
||||
await click('form [type="submit"]');
|
||||
await visit(urls.members);
|
||||
assert.equal(findAll('tbody tr').length, 1);
|
||||
});
|
||||
|
||||
test('select and cancel members to add', async function (assert) {
|
||||
assert.expect(4);
|
||||
await visit(urls.members);
|
||||
assert.equal(findAll('tbody tr').length, membersCount);
|
||||
await click('tbody tr .rose-dropdown-button-danger');
|
||||
assert.equal(findAll('tbody tr').length, membersCount - 1);
|
||||
await click('.rose-layout-page-actions a')
|
||||
assert.equal(currentURL(), urls.addMembers);
|
||||
await click('tbody label');
|
||||
await click('form [type="button"]');
|
||||
await visit(urls.members);
|
||||
assert.equal(findAll('tbody tr').length, membersCount - 1);
|
||||
});
|
||||
|
||||
test('shows error message on member add', async function (assert) {
|
||||
assert.expect(1);
|
||||
this.server.post('/groups/:idMethod', () => {
|
||||
return new Response(
|
||||
400,
|
||||
{},
|
||||
{
|
||||
status: 400,
|
||||
code: 'invalid_argument',
|
||||
message: 'The request was invalid.',
|
||||
details: {},
|
||||
}
|
||||
);
|
||||
});
|
||||
instances.group.update({ memberIds: [] });
|
||||
await visit(urls.addMembers);
|
||||
await click('tbody label');
|
||||
await click('form [type="submit"]');
|
||||
assert.ok(find('[role="alert"]'));
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user