refactor: 💡 acceptance tests in list-test.js for users (#1466)

* refactor: 💡 acceptance tests in list-test.js for users

✅ Closes: ICU-6893

Co-authored-by: Randall Morey <randall@randallmorey.com>
This commit is contained in:
lisbet-alvarezandRandall Morey authored and GitHub committed 2022-11-16 11:39:45 -08:00
1 parent 42169b070c
commit 37ad4b6a32
1 file changed
+93 -35
+93 -35
View File
@@ -1,5 +1,5 @@
import { module, test } from 'qunit';
import { visit, find } from '@ember/test-helpers';
import { visit, click } from '@ember/test-helpers';
import { setupApplicationTest } from 'ember-qunit';
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
import {
@@ -12,63 +12,121 @@ import {
module('Acceptance | users | list', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);
let orgURL;
const instances = {
scopes: {
global: null,
org: null,
},
user: null,
};
const urls = {
scopes: {
org: null,
},
globalScope: null,
orgScope: null,
users: null,
user: null,
};
hooks.beforeEach(function () {
instances.scopes.global = this.server.create('scope', { id: 'global' });
instances.orgScope = this.server.create(
'scope',
{
type: 'org',
scope: { id: 'global', type: 'global' },
},
'withChildren'
);
instances.user = this.server.create('user', {
scope: instances.orgScope,
instances.scopes.org = this.server.create('scope', {
type: 'org',
scope: { id: 'global', type: 'global' },
});
orgURL = `/scopes/${instances.orgScope.id}`;
urls.users = `/scopes/${instances.orgScope.id}/users`;
instances.user = this.server.create('user', {
scope: instances.scopes.org,
});
urls.globalScope = `/scopes/global/scopes`;
urls.orgScope = `/scopes/${instances.scopes.org.id}`;
urls.users = `/scopes/${instances.scopes.org.id}/users`;
urls.user = `/scopes/${instances.scopes.org.id}/users/${instances.user.id}`;
authenticateSession({});
});
test('Users can navigate to users with proper authorization', async function (assert) {
assert.expect(2);
await visit(orgURL);
assert.ok(
instances.orgScope.authorized_collection_actions.users.includes('list')
test('users can navigate to users with proper authorization', async function (assert) {
assert.expect(3);
await visit(urls.globalScope);
await click(`[href="${urls.orgScope}"]`);
assert.true(
instances.scopes.org.authorized_collection_actions.users.includes('list')
);
assert.ok(find(`[href="${urls.users}"]`));
assert.true(
instances.scopes.org.authorized_collection_actions.users.includes(
'create'
)
);
assert.dom(`[href="${urls.users}"]`).exists();
});
test('User cannot navigate to index without either list or create actions', async function (assert) {
assert.expect(2);
instances.orgScope.authorized_collection_actions.users = [];
await visit(orgURL);
assert.notOk(
instances.orgScope.authorized_collection_actions.users.includes('list')
test('user cannot navigate to users tab without either list or create actions', async function (assert) {
assert.expect(3);
instances.scopes.org.authorized_collection_actions.users = [];
await visit(urls.globalScope);
await click(`[href="${urls.orgScope}"]`);
assert.false(
instances.scopes.org.authorized_collection_actions.users.includes(
'create'
)
);
assert.notOk(find(`[href="${urls.users}"]`));
assert.false(
instances.scopes.org.authorized_collection_actions.users.includes('list')
);
assert.dom(`nav [href="${urls.users}"]`).doesNotExist();
});
test('User can navigate to index with only create action', async function (assert) {
assert.expect(1);
instances.orgScope.authorized_collection_actions.users = ['create'];
await visit(orgURL);
assert.ok(find(`[href="${urls.users}"]`));
test('user can navigate to users tab with only create action', async function (assert) {
assert.expect(4);
instances.scopes.org.authorized_collection_actions.users =
instances.scopes.org.authorized_collection_actions.users.filter(
(item) => item !== 'list'
);
await visit(urls.globalScope);
await click(`[href="${urls.orgScope}"]`);
assert.false(
instances.scopes.org.authorized_collection_actions.users.includes('list')
);
assert.true(
instances.scopes.org.authorized_collection_actions.users.includes(
'create'
)
);
assert.dom(`[href="${urls.users}"]`).exists();
await click(`[href="${urls.users}"]`);
assert.dom(`.rose-table [href="${urls.user}"]`).doesNotExist();
});
test('user can navigate to users tab with only list action', async function (assert) {
assert.expect(4);
instances.scopes.org.authorized_collection_actions.users =
instances.scopes.org.authorized_collection_actions.users.filter(
(item) => item !== 'create'
);
await visit(urls.globalScope);
await click(`[href="${urls.orgScope}"]`);
assert.true(
instances.scopes.org.authorized_collection_actions.users.includes('list')
);
assert.false(
instances.scopes.org.authorized_collection_actions.users.includes(
'create'
)
);
assert.dom(`[href="${urls.users}"]`).exists();
await click(`[href="${urls.users}"]`);
assert.dom(`[href="${urls.user}"]`).exists();
});
});