* feat: 🎸 scope picker component (#2646) * feat: 🎸 scope picker component --------- Co-authored-by: lisbet-alvarez <lisbet-alvarez@users.noreply.github.com> Co-authored-by: Zhihe Li <zhihe.li@hashicorp.com> * refactor: 💡 use hds side nav w/ hds frame instead of rose (#2688) * refactor: 💡 use hds side nav w/ hds frame instead of rose * test: 💍 clean up selectors * fix: 🐛 specificity of style override * refactor: 💡 use hds side nav list instead of target and portal * refactor: 💡 revert to using portal component & update scss * docs: ✏️ update comment * refactor: 💡 use custom class names for containers * refactor: 💡 pr feedback (use @hasSidebar arg) * refactor: 💡 fix onboarding page & fix settings title * refactor: 💡 remove unneeded template file (pr feedback) * test: 💍 fix tests due to merge conflicts * test: 💍 add missing test selector due to merge conflict * test: 💍 fix more broken tests due to merge conflicts * chore: 🤖 update yarn.lock & update hds version to 4.18.1 * chore: 🤖 fix e2e test cases due to side nav refactor (#2751) * chore: 🤖 fix e2e test cases due to side nav refactor * test: 💍 fix e2e test for desktop --------- Co-authored-by: lisbet-alvarez <lisbet-alvarez@users.noreply.github.com> Co-authored-by: Zhihe Li <zhihe.li@hashicorp.com>
170 lines
6.0 KiB
JavaScript
170 lines
6.0 KiB
JavaScript
/**
|
|
* Copyright (c) HashiCorp, Inc.
|
|
* SPDX-License-Identifier: BUSL-1.1
|
|
*/
|
|
|
|
import { module, test } from 'qunit';
|
|
import { visit, currentURL, click, find, findAll } from '@ember/test-helpers';
|
|
import { setupApplicationTest } from 'admin/tests/helpers';
|
|
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
|
|
import { setupIndexedDb } from 'api/test-support/helpers/indexed-db';
|
|
import a11yAudit from 'ember-a11y-testing/test-support/audit';
|
|
import { Response } from 'miragejs';
|
|
import { authenticateSession } from 'ember-simple-auth/test-support';
|
|
import * as commonSelectors from 'admin/tests/helpers/selectors';
|
|
|
|
module('Acceptance | roles | principals', function (hooks) {
|
|
setupApplicationTest(hooks);
|
|
setupMirage(hooks);
|
|
setupIndexedDb(hooks);
|
|
|
|
const MANAGE_DROPDOWN_SELECTOR = '[data-test-manage-roles-dropdown] button';
|
|
const ADD_PRINCIPALS_SELECTOR = '[data-test-manage-role-principals]';
|
|
|
|
const instances = {
|
|
scopes: {
|
|
global: null,
|
|
org: null,
|
|
},
|
|
role: null,
|
|
};
|
|
const urls = {
|
|
orgScope: null,
|
|
roles: null,
|
|
role: null,
|
|
newRole: null,
|
|
};
|
|
let principalsCount;
|
|
|
|
hooks.beforeEach(async function () {
|
|
await authenticateSession({ username: 'admin' });
|
|
instances.scopes.global = this.server.create('scope', { id: 'global' });
|
|
instances.scopes.org = this.server.create('scope', {
|
|
type: 'org',
|
|
scope: { id: 'global', type: 'global' },
|
|
});
|
|
instances.role = this.server.create(
|
|
'role',
|
|
{
|
|
scope: instances.scopes.org,
|
|
},
|
|
'withPrincipals',
|
|
);
|
|
principalsCount =
|
|
this.server.db.roles[0].userIds.length +
|
|
this.server.db.roles[0].groupIds.length +
|
|
this.server.db.roles[0].managedGroupIds.length;
|
|
urls.roles = `/scopes/${instances.scopes.org.id}/roles`;
|
|
urls.role = `${urls.roles}/${instances.role.id}`;
|
|
urls.rolePrincipals = `${urls.role}/principals`;
|
|
urls.addPrincipals = `${urls.role}/add-principals`;
|
|
});
|
|
|
|
test('visiting role principals', async function (assert) {
|
|
await visit(urls.rolePrincipals);
|
|
await a11yAudit();
|
|
assert.strictEqual(currentURL(), urls.rolePrincipals);
|
|
assert.strictEqual(findAll('tbody tr').length, principalsCount);
|
|
});
|
|
|
|
test('principal can be removed from a role', async function (assert) {
|
|
await visit(urls.rolePrincipals);
|
|
assert.strictEqual(findAll('tbody tr').length, principalsCount);
|
|
await click('tbody tr td:last-child .hds-dropdown-toggle-icon');
|
|
await click('tbody tr .hds-dropdown-list-item button');
|
|
assert.strictEqual(findAll('tbody tr').length, principalsCount - 1);
|
|
});
|
|
|
|
test('principal cannot be removed from a role without proper authorization', async function (assert) {
|
|
const authorized_actions = instances.role.authorized_actions.filter(
|
|
(item) => item !== 'remove-principals',
|
|
);
|
|
instances.role.update({ authorized_actions });
|
|
await visit(urls.rolePrincipals);
|
|
assert.notOk(find('tbody tr .hds-dropdown-list-item button'));
|
|
});
|
|
|
|
test('shows error message on principal remove', async function (assert) {
|
|
this.server.post('/roles/:idMethod', () => {
|
|
return new Response(
|
|
400,
|
|
{},
|
|
{
|
|
status: 400,
|
|
code: 'invalid_argument',
|
|
message: 'The request was invalid.',
|
|
details: {},
|
|
},
|
|
);
|
|
});
|
|
await visit(urls.rolePrincipals);
|
|
assert.strictEqual(findAll('tbody tr').length, principalsCount);
|
|
await click('tbody tr td:last-child .hds-dropdown-toggle-icon');
|
|
await click('tbody tr .hds-dropdown-list-item button');
|
|
assert
|
|
.dom(commonSelectors.ALERT_TOAST_BODY)
|
|
.hasText('The request was invalid.');
|
|
});
|
|
|
|
test('cannot navigate to add principals without proper authorization', async function (assert) {
|
|
const authorized_actions = instances.role.authorized_actions.filter(
|
|
(item) => item !== 'add-principals',
|
|
);
|
|
instances.role.update({ authorized_actions });
|
|
await visit(urls.rolePrincipals);
|
|
assert.dom(ADD_PRINCIPALS_SELECTOR).doesNotExist();
|
|
});
|
|
|
|
test('select and save principals to add', async function (assert) {
|
|
instances.role.update({ userIds: [], groupIds: [], managedGroupIds: [] });
|
|
await visit(urls.rolePrincipals);
|
|
assert.strictEqual(findAll('tbody tr').length, 0);
|
|
await click(MANAGE_DROPDOWN_SELECTOR);
|
|
await click(ADD_PRINCIPALS_SELECTOR);
|
|
assert.strictEqual(currentURL(), urls.addPrincipals);
|
|
// Click three times to select, unselect, then reselect (for coverage)
|
|
await click('tbody label');
|
|
await click('tbody label');
|
|
await click('tbody label');
|
|
await click('form [type="submit"]');
|
|
await visit(urls.rolePrincipals);
|
|
assert.strictEqual(findAll('tbody tr').length, 1);
|
|
});
|
|
|
|
test('select and cancel principals to add', async function (assert) {
|
|
await visit(urls.rolePrincipals);
|
|
assert.strictEqual(findAll('tbody tr').length, principalsCount);
|
|
// Remove a principal to populate association view
|
|
await click('tbody tr td:last-child .hds-dropdown-toggle-icon');
|
|
await click('tbody tr .hds-dropdown-list-item button');
|
|
assert.strictEqual(findAll('tbody tr').length, principalsCount - 1);
|
|
await click(MANAGE_DROPDOWN_SELECTOR);
|
|
await click(ADD_PRINCIPALS_SELECTOR);
|
|
assert.strictEqual(currentURL(), urls.addPrincipals);
|
|
await click('tbody label');
|
|
await click('form [type="button"]');
|
|
await visit(urls.rolePrincipals);
|
|
assert.strictEqual(findAll('tbody tr').length, principalsCount - 1);
|
|
});
|
|
|
|
test('shows error message on principal add', async function (assert) {
|
|
this.server.post('/roles/:idMethod', () => {
|
|
return new Response(
|
|
400,
|
|
{},
|
|
{
|
|
status: 400,
|
|
code: 'invalid_argument',
|
|
message: 'The request was invalid.',
|
|
details: {},
|
|
},
|
|
);
|
|
});
|
|
instances.role.update({ userIds: [], groupIds: [], managedGroupIds: [] });
|
|
await visit(urls.addPrincipals);
|
|
await click('tbody label');
|
|
await click('form [type="submit"]');
|
|
assert.ok(find(commonSelectors.ALERT_TOAST_BODY));
|
|
});
|
|
});
|