Icu 13880 create manage scopes route and view with keyword values (#2342)
* feat: 🎸 manage scopes route and page ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13880 * Update addons/core/translations/resources/en-us.yaml Co-authored-by: Zhihe Li <zhihe.li@hashicorp.com> * Update ui/admin/app/abilities/role.js Co-authored-by: Zhihe Li <zhihe.li@hashicorp.com> * Update ui/admin/app/components/form/role/manage-scopes/index.hbs Co-authored-by: Zhihe Li <zhihe.li@hashicorp.com> --------- Co-authored-by: Zhihe Li <zhihe.li@hashicorp.com>
This commit is contained in:
1 parent
85bce84356
commit
89e072401c
18 files changed
+536
-16
No files matched your search
@@ -22,6 +22,8 @@ module('Acceptance | roles | principals', function (hooks) {
|
||||
setupMirage(hooks);
|
||||
setupIndexedDb(hooks);
|
||||
|
||||
const ADD_PRINCIPALS_SELECTOR = '[data-test-manage-dropdown-principals]';
|
||||
|
||||
const instances = {
|
||||
scopes: {
|
||||
global: null,
|
||||
@@ -111,14 +113,14 @@ module('Acceptance | roles | principals', function (hooks) {
|
||||
);
|
||||
instances.role.update({ authorized_actions });
|
||||
await visit(urls.rolePrincipals);
|
||||
assert.notOk(find('.rose-layout-page-actions a'));
|
||||
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('.rose-layout-page-actions a');
|
||||
await click(ADD_PRINCIPALS_SELECTOR);
|
||||
assert.strictEqual(currentURL(), urls.addPrincipals);
|
||||
// Click three times to select, unselect, then reselect (for coverage)
|
||||
await click('tbody label');
|
||||
@@ -136,7 +138,7 @@ module('Acceptance | roles | principals', function (hooks) {
|
||||
await click('.hds-dropdown-toggle-icon');
|
||||
await click('tbody tr .hds-dropdown-list-item button');
|
||||
assert.strictEqual(findAll('tbody tr').length, principalsCount - 1);
|
||||
await click('.rose-layout-page-actions a');
|
||||
await click(ADD_PRINCIPALS_SELECTOR);
|
||||
assert.strictEqual(currentURL(), urls.addPrincipals);
|
||||
await click('tbody label');
|
||||
await click('form [type="button"]');
|
||||
|
||||
@@ -4,18 +4,27 @@
|
||||
*/
|
||||
|
||||
import { module, test } from 'qunit';
|
||||
import { visit, currentURL, click } from '@ember/test-helpers';
|
||||
import { visit, currentURL, click, findAll } from '@ember/test-helpers';
|
||||
import { setupApplicationTest } from 'ember-qunit';
|
||||
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 { authenticateSession } from 'ember-simple-auth/test-support';
|
||||
import { GRANT_SCOPE_THIS } from 'api/models/role';
|
||||
|
||||
module('Acceptance | roles | scopes', function (hooks) {
|
||||
setupApplicationTest(hooks);
|
||||
setupMirage(hooks);
|
||||
setupIndexedDb(hooks);
|
||||
|
||||
const SCOPE_TOGGLE_SELECTOR = (name) =>
|
||||
`.hds-form-toggle input[name="${name}"]`;
|
||||
const TABLE_ROW_SELECTOR = 'tbody tr';
|
||||
const SAVE_BTN_SELECTOR = 'form [type="submit"]';
|
||||
const CANCEL_BTN_SELECTOR = '.rose-form-actions [type="button"]';
|
||||
const MANAGE_SCOPES_SELECTOR = '[data-test-manage-dropdown-scopes]';
|
||||
const TOAST_SELECTOR = '[role="alert"]';
|
||||
|
||||
const instances = {
|
||||
scopes: {
|
||||
global: null,
|
||||
@@ -28,6 +37,7 @@ module('Acceptance | roles | scopes', function (hooks) {
|
||||
roles: null,
|
||||
role: null,
|
||||
roleScopes: null,
|
||||
manageScopes: null,
|
||||
};
|
||||
|
||||
hooks.beforeEach(function () {
|
||||
@@ -47,6 +57,7 @@ module('Acceptance | roles | scopes', function (hooks) {
|
||||
urls.roles = `/scopes/${instances.scopes.org.id}/roles`;
|
||||
urls.role = `${urls.roles}/${instances.role.id}`;
|
||||
urls.roleScopes = `${urls.role}/scopes`;
|
||||
urls.manageScopes = `${urls.role}/manage-scopes`;
|
||||
});
|
||||
|
||||
test('visiting role scopes', async function (assert) {
|
||||
@@ -54,7 +65,7 @@ module('Acceptance | roles | scopes', function (hooks) {
|
||||
await a11yAudit();
|
||||
assert.strictEqual(currentURL(), urls.roleScopes);
|
||||
assert
|
||||
.dom('tbody tr')
|
||||
.dom(TABLE_ROW_SELECTOR)
|
||||
.exists({ count: instances.role.grant_scope_ids.length });
|
||||
});
|
||||
|
||||
@@ -93,4 +104,71 @@ module('Acceptance | roles | scopes', function (hooks) {
|
||||
await visit(urls.roleScopes);
|
||||
assert.dom('.role-grant-scopes div div:nth-child(3) a').doesNotExist();
|
||||
});
|
||||
|
||||
test('toggle and save scope keywords to add', async function (assert) {
|
||||
instances.role.update({ grant_scope_ids: [] });
|
||||
await visit(urls.role);
|
||||
|
||||
await click(`[href="${urls.roleScopes}"]`);
|
||||
|
||||
assert.strictEqual(findAll(TABLE_ROW_SELECTOR).length, 0);
|
||||
|
||||
await click(MANAGE_SCOPES_SELECTOR);
|
||||
|
||||
assert.strictEqual(currentURL(), urls.manageScopes);
|
||||
|
||||
// Click three times to select, unselect, then reselect (for coverage)
|
||||
await click(SCOPE_TOGGLE_SELECTOR(GRANT_SCOPE_THIS));
|
||||
await click(SCOPE_TOGGLE_SELECTOR(GRANT_SCOPE_THIS));
|
||||
await click(SCOPE_TOGGLE_SELECTOR(GRANT_SCOPE_THIS));
|
||||
await click(SAVE_BTN_SELECTOR);
|
||||
|
||||
assert.strictEqual(currentURL(), urls.roleScopes);
|
||||
assert.strictEqual(findAll(TABLE_ROW_SELECTOR).length, 1);
|
||||
});
|
||||
|
||||
test('toggle and cancel scope keywords to add', async function (assert) {
|
||||
instances.role.update({ grant_scope_ids: [] });
|
||||
await visit(urls.role);
|
||||
|
||||
await click(`[href="${urls.roleScopes}"]`);
|
||||
|
||||
assert.strictEqual(findAll(TABLE_ROW_SELECTOR).length, 0);
|
||||
|
||||
await click(MANAGE_SCOPES_SELECTOR);
|
||||
|
||||
assert.strictEqual(currentURL(), urls.manageScopes);
|
||||
|
||||
// Click three times to select, unselect, then reselect (for coverage)
|
||||
await click(SCOPE_TOGGLE_SELECTOR(GRANT_SCOPE_THIS));
|
||||
await click(SCOPE_TOGGLE_SELECTOR(GRANT_SCOPE_THIS));
|
||||
await click(SCOPE_TOGGLE_SELECTOR(GRANT_SCOPE_THIS));
|
||||
await click(CANCEL_BTN_SELECTOR);
|
||||
|
||||
assert.strictEqual(currentURL(), urls.roleScopes);
|
||||
assert.strictEqual(findAll(TABLE_ROW_SELECTOR).length, 0);
|
||||
});
|
||||
|
||||
test('shows error message on scope save', 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({ grant_scope_ids: [] });
|
||||
await visit(urls.role);
|
||||
|
||||
await click(MANAGE_SCOPES_SELECTOR);
|
||||
await click(SCOPE_TOGGLE_SELECTOR(GRANT_SCOPE_THIS));
|
||||
await click(SAVE_BTN_SELECTOR);
|
||||
|
||||
assert.dom(TOAST_SELECTOR).isVisible();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,64 @@
|
||||
/**
|
||||
* Copyright (c) HashiCorp, Inc.
|
||||
* SPDX-License-Identifier: BUSL-1.1
|
||||
*/
|
||||
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
|
||||
module('Unit | Abilities | role', function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
let canService;
|
||||
let store;
|
||||
|
||||
hooks.beforeEach(function () {
|
||||
canService = this.owner.lookup('service:can');
|
||||
store = this.owner.lookup('service:store');
|
||||
});
|
||||
|
||||
test('can setGrantScopes on role when authorized and scope is global type', function (assert) {
|
||||
const globalScope = store.createRecord('scope', { id: 'global' });
|
||||
const role = store.createRecord('role', {
|
||||
authorized_actions: ['set-grant-scopes'],
|
||||
scope: globalScope,
|
||||
});
|
||||
assert.true(canService.can('setGrantScopes role', role));
|
||||
role.authorized_actions = [];
|
||||
assert.false(canService.can('setGrantScopes role', role));
|
||||
});
|
||||
|
||||
test('can setGrantScopes on role when authorized and scope is org type', function (assert) {
|
||||
const globalScope = store.createRecord('scope', { id: 'global' });
|
||||
const orgScope = store.createRecord('scope', {
|
||||
type: 'org',
|
||||
scope: globalScope,
|
||||
});
|
||||
const role = store.createRecord('role', {
|
||||
authorized_actions: ['set-grant-scopes'],
|
||||
scope: orgScope,
|
||||
});
|
||||
assert.true(canService.can('setGrantScopes role', role));
|
||||
role.authorized_actions = [];
|
||||
assert.false(canService.can('setGrantScopes role', role));
|
||||
});
|
||||
|
||||
test('cannot setGrantScopes on role when authorized and scope is project type', function (assert) {
|
||||
const globalScope = store.createRecord('scope', { id: 'global' });
|
||||
const orgScope = store.createRecord('scope', {
|
||||
type: 'org',
|
||||
scope: globalScope,
|
||||
});
|
||||
const projectScope = store.createRecord('scope', {
|
||||
type: 'project',
|
||||
scope: orgScope,
|
||||
});
|
||||
const role = store.createRecord('role', {
|
||||
authorized_actions: ['set-grant-scopes'],
|
||||
scope: projectScope,
|
||||
});
|
||||
assert.false(canService.can('setGrantScopes role', role));
|
||||
role.authorized_actions = [];
|
||||
assert.false(canService.can('setGrantScopes role', role));
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,70 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
import { visit, currentURL } from '@ember/test-helpers';
|
||||
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
|
||||
import { authenticateSession } from 'ember-simple-auth/test-support';
|
||||
|
||||
module(
|
||||
'Unit | Controller | scopes/scope/roles/role/manage-scopes',
|
||||
function (hooks) {
|
||||
setupTest(hooks);
|
||||
setupMirage(hooks);
|
||||
|
||||
let store;
|
||||
let controller;
|
||||
|
||||
const instances = {
|
||||
scopes: {
|
||||
global: null,
|
||||
},
|
||||
role: null,
|
||||
};
|
||||
|
||||
const urls = {
|
||||
globalScope: null,
|
||||
scopes: null,
|
||||
manageScopes: null,
|
||||
};
|
||||
|
||||
hooks.beforeEach(async function () {
|
||||
authenticateSession({});
|
||||
store = this.owner.lookup('service:store');
|
||||
controller = this.owner.lookup(
|
||||
'controller:scopes/scope/roles/role/manage-scopes',
|
||||
);
|
||||
|
||||
instances.scopes.global = this.server.create('scope', { id: 'global' });
|
||||
instances.role = this.server.create('role', {
|
||||
scopeId: 'global',
|
||||
grant_scope_ids: [],
|
||||
});
|
||||
|
||||
urls.globalScope = `/scopes/global`;
|
||||
urls.scopes = `${urls.globalScope}/roles/${instances.role.id}/scopes`;
|
||||
urls.manageScopes = `${urls.globalScope}/roles/${instances.role.id}/manage-scopes`;
|
||||
});
|
||||
|
||||
test('it exists', function (assert) {
|
||||
assert.ok(controller);
|
||||
});
|
||||
|
||||
test('setGrantScopes action adds scopes to specified model', async function (assert) {
|
||||
await visit(urls.manageScopes);
|
||||
const role = await store.findRecord('role', instances.role.id);
|
||||
|
||||
assert.deepEqual(role.grant_scope_ids, []);
|
||||
|
||||
await controller.setGrantScopes(role, ['this']);
|
||||
|
||||
assert.deepEqual(role.grant_scope_ids, ['this']);
|
||||
});
|
||||
|
||||
test('cancel action causes transition to expected route', async function (assert) {
|
||||
await visit(urls.manageScopes);
|
||||
|
||||
await controller.cancel();
|
||||
|
||||
assert.strictEqual(currentURL(), urls.scopes);
|
||||
});
|
||||
},
|
||||
);
|
||||
@@ -0,0 +1,16 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
|
||||
module(
|
||||
'Unit | Route | scopes/scope/roles/role/manage-scopes',
|
||||
function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
test('it exists', function (assert) {
|
||||
let route = this.owner.lookup(
|
||||
'route:scopes/scope/roles/role/manage-scopes',
|
||||
);
|
||||
assert.ok(route);
|
||||
});
|
||||
},
|
||||
);
|
||||
Reference in new issue
Block a user