diff --git a/ui/admin/tests/acceptance/users/list-test.js b/ui/admin/tests/acceptance/users/list-test.js index ccf1bcf2e..d357fb947 100644 --- a/ui/admin/tests/acceptance/users/list-test.js +++ b/ui/admin/tests/acceptance/users/list-test.js @@ -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(); }); });