feat: 🎸 create manage projects in org route and view (#2365)

* feat: 🎸 create manage projects in org route and view

✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13882

---------

Co-authored-by: Cameron Perera <cameron.perera@hashicorp.com>
Co-authored-by: Zhihe Li <zhihe.li@hashicorp.com>
This commit is contained in:
authored and Lisbet Alvarez committed 2024-07-15 17:23:00 -07:00
1 parent e83bb425af
commit 3064e51bc1
20 files changed
+1541 -381

No files matched your search

@@ -0,0 +1,533 @@
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import { module, test } from 'qunit';
import {
visit,
currentURL,
click,
findAll,
fillIn,
waitUntil,
} 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,
GRANT_SCOPE_CHILDREN,
GRANT_SCOPE_DESCENDANTS,
} from 'api/models/role';
module('Acceptance | roles | global-scope', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);
setupIndexedDb(hooks);
const SCOPE_TOGGLE_SELECTOR = (name) =>
`.hds-form-toggle input[name="${name}"]`;
const SCOPE_CHECKBOX_SELECTOR = (type, id) =>
`tbody [data-test-${type}-scopes-table-row="${id}"] input`;
const TABLE_ROW_SELECTOR = 'tbody tr';
const TABLE_SCOPE_SELECTOR = 'tbody tr:nth-child(2) a';
const TABLE_PARENT_SCOPE_SELECTOR = 'tbody tr:nth-child(2) td:nth-child(3) a';
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 SEARCH_INPUT_SELECTOR = '.search-filtering [type="search"]';
const NO_RESULTS_MSG_SELECTOR = '[data-test-no-grant-scope-results]';
const NO_SCOPES_MSG_SELECTOR = '.role-grant-scopes div';
const NO_SCOPES_MSG_LINK_SELECTOR =
'.role-grant-scopes div div:nth-child(3) a';
const instances = {
scopes: {
global: null,
org: null,
project: null,
},
role: null,
};
const urls = {
orgScope: null,
roles: null,
role: null,
roleScopes: null,
manageScopes: null,
manageCustomScopes: null,
};
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.scopes.project = this.server.create('scope', {
type: 'project',
scope: { id: instances.scopes.org.id, type: 'org' },
});
instances.role = this.server.create(
'role',
{
scope: instances.scopes.global,
},
'withScopes',
);
urls.roles = `/scopes/global/roles`;
urls.role = `${urls.roles}/${instances.role.id}`;
urls.roleScopes = `${urls.role}/scopes`;
urls.manageScopes = `${urls.role}/manage-scopes`;
urls.manageCustomScopes = `${urls.manageScopes}/manage-custom-scopes`;
});
test('visiting role scopes', async function (assert) {
await visit(urls.role);
await click(`[href="${urls.roleScopes}"]`);
await a11yAudit();
assert.strictEqual(currentURL(), urls.roleScopes);
assert
.dom(TABLE_ROW_SELECTOR)
.exists({ count: instances.role.grant_scope_ids.length });
});
test('user can naviage to scope from role grant scopes', async function (assert) {
await visit(urls.role);
await click(`[href="${urls.roleScopes}"]`);
await click(TABLE_SCOPE_SELECTOR);
assert.strictEqual(
currentURL(),
`/scopes/${instances.scopes.global.id}/scopes`,
);
});
test('user can naviage to parent scope from role grant scopes', async function (assert) {
instances.role.update({
grant_scope_ids: ['this', instances.scopes.org.id],
});
await visit(urls.role);
await click(`[href="${urls.roleScopes}"]`);
await click(TABLE_PARENT_SCOPE_SELECTOR);
assert.strictEqual(
currentURL(),
`/scopes/${instances.scopes.global.id}/scopes`,
);
});
test('user sees no scopes message and action when role has no grant scopes', async function (assert) {
instances.role.update({ grant_scope_ids: [] });
await visit(urls.role);
await click(`[href="${urls.roleScopes}"]`);
assert.dom(NO_SCOPES_MSG_SELECTOR).includesText('No scopes added');
assert.dom(NO_SCOPES_MSG_LINK_SELECTOR).isVisible();
});
test('user does not see action to add scopes when role has no grant scopes without proper permissions', async function (assert) {
instances.role.update({
grant_scope_ids: [],
authorized_actions: instances.role.authorized_actions.filter(
(action) => action !== 'set-grant-scopes',
),
});
await visit(urls.role);
await click(`[href="${urls.roleScopes}"]`);
assert.dom(NO_SCOPES_MSG_LINK_SELECTOR).doesNotExist();
});
test('correct toggles are visible for global level role on manage scopes page', async function (assert) {
await visit(urls.role);
await click(MANAGE_SCOPES_SELECTOR);
assert.strictEqual(currentURL(), urls.manageScopes);
assert.dom(SCOPE_TOGGLE_SELECTOR(GRANT_SCOPE_THIS)).isVisible();
assert.dom(SCOPE_TOGGLE_SELECTOR(GRANT_SCOPE_CHILDREN)).isVisible();
assert.dom(SCOPE_TOGGLE_SELECTOR(GRANT_SCOPE_DESCENDANTS)).isVisible();
});
test('user can save scope keywords to add on manage scopes page', 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);
await a11yAudit();
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('user can cancel scope keywords to add on manage scopes page', 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 on manage scopes page', 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();
});
test('user can save custom scopes to add on manage custom scopes page', 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);
await click(`[href="${urls.manageCustomScopes}"]`);
await a11yAudit();
assert.strictEqual(currentURL(), urls.manageCustomScopes);
// Click three times to select, unselect, then reselect (for coverage)
await click(SCOPE_CHECKBOX_SELECTOR('org', instances.scopes.org.id));
await click(SCOPE_CHECKBOX_SELECTOR('org', instances.scopes.org.id));
await click(SCOPE_CHECKBOX_SELECTOR('org', instances.scopes.org.id));
await click(SAVE_BTN_SELECTOR);
assert.strictEqual(currentURL(), urls.manageScopes);
await click(SAVE_BTN_SELECTOR);
assert.strictEqual(currentURL(), urls.roleScopes);
assert.strictEqual(findAll(TABLE_ROW_SELECTOR).length, 1);
});
test('user can cancel custom scopes to add on manage custom scopes page', 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);
await click(`[href="${urls.manageCustomScopes}"]`);
// Click three times to select, unselect, then reselect (for coverage)
await click(SCOPE_CHECKBOX_SELECTOR('org', instances.scopes.org.id));
await click(SCOPE_CHECKBOX_SELECTOR('org', instances.scopes.org.id));
await click(SCOPE_CHECKBOX_SELECTOR('org', instances.scopes.org.id));
await click(CANCEL_BTN_SELECTOR);
assert.strictEqual(currentURL(), urls.manageScopes);
await click(CANCEL_BTN_SELECTOR);
assert.strictEqual(currentURL(), urls.roleScopes);
assert.strictEqual(findAll(TABLE_ROW_SELECTOR).length, 0);
});
test('shows error message on custom scope save on manage custom scopes page', 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(`[href="${urls.manageCustomScopes}"]`);
await click(SCOPE_CHECKBOX_SELECTOR('org', instances.scopes.org.id));
await click(SAVE_BTN_SELECTOR);
assert.dom(TOAST_SELECTOR).isVisible();
});
test('user can search for a specifc org scope by id on manage custom scopes page', async function (assert) {
const anotherOrg = this.server.create('scope', {
type: 'org',
scope: { id: 'global', type: 'global' },
});
await visit(urls.manageScopes);
await click(`[href="${urls.manageCustomScopes}"]`);
assert
.dom(SCOPE_CHECKBOX_SELECTOR('org', instances.scopes.org.id))
.exists();
assert.dom(SCOPE_CHECKBOX_SELECTOR('org', anotherOrg.id)).exists();
await fillIn(SEARCH_INPUT_SELECTOR, instances.scopes.org.id);
await waitUntil(
() => findAll(SCOPE_CHECKBOX_SELECTOR('org', anotherOrg.id)).length === 0,
);
assert
.dom(SCOPE_CHECKBOX_SELECTOR('org', instances.scopes.org.id))
.exists();
assert.dom(SCOPE_CHECKBOX_SELECTOR('org', anotherOrg.id)).doesNotExist();
});
test('user can search for org scopes and get no results on manage custom scopes page', async function (assert) {
const anotherOrg = this.server.create('scope', {
type: 'org',
scope: { id: 'global', type: 'global' },
});
await visit(urls.manageScopes);
await click(`[href="${urls.manageCustomScopes}"]`);
assert
.dom(SCOPE_CHECKBOX_SELECTOR('org', instances.scopes.org.id))
.exists();
assert.dom(SCOPE_CHECKBOX_SELECTOR('org', anotherOrg.id)).exists();
await fillIn(SEARCH_INPUT_SELECTOR, 'fake scope that does not exist');
await waitUntil(() => findAll(NO_RESULTS_MSG_SELECTOR).length === 1);
assert
.dom(SCOPE_CHECKBOX_SELECTOR('org', instances.scopes.org.id))
.doesNotExist();
assert.dom(SCOPE_CHECKBOX_SELECTOR('org', anotherOrg.id)).doesNotExist();
assert.dom(NO_RESULTS_MSG_SELECTOR).includesText('No results found');
});
test('user can save custom scopes to add on manage org projects page', 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);
await click(`[href="${urls.manageCustomScopes}"]`);
await click(
`tbody [href="${urls.manageScopes}/${instances.scopes.org.id}"]`,
);
await a11yAudit();
// Click three times to select, unselect, then reselect (for coverage)
await click(
SCOPE_CHECKBOX_SELECTOR('project', instances.scopes.project.id),
);
await click(
SCOPE_CHECKBOX_SELECTOR('project', instances.scopes.project.id),
);
await click(
SCOPE_CHECKBOX_SELECTOR('project', instances.scopes.project.id),
);
await click(SAVE_BTN_SELECTOR);
assert.strictEqual(currentURL(), urls.manageCustomScopes);
await click(SAVE_BTN_SELECTOR);
assert.strictEqual(currentURL(), urls.manageScopes);
await click(SAVE_BTN_SELECTOR);
assert.strictEqual(currentURL(), urls.roleScopes);
assert.strictEqual(findAll(TABLE_ROW_SELECTOR).length, 1);
});
test('user can cancel custom scopes to add on manage org projects page', 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);
await click(`[href="${urls.manageCustomScopes}"]`);
await click(
`tbody [href="${urls.manageScopes}/${instances.scopes.org.id}"]`,
);
// Click three times to select, unselect, then reselect (for coverage)
await click(
SCOPE_CHECKBOX_SELECTOR('project', instances.scopes.project.id),
);
await click(
SCOPE_CHECKBOX_SELECTOR('project', instances.scopes.project.id),
);
await click(
SCOPE_CHECKBOX_SELECTOR('project', instances.scopes.project.id),
);
await click(CANCEL_BTN_SELECTOR);
assert.strictEqual(currentURL(), urls.manageCustomScopes);
await click(CANCEL_BTN_SELECTOR);
assert.strictEqual(currentURL(), urls.manageScopes);
await click(CANCEL_BTN_SELECTOR);
assert.strictEqual(currentURL(), urls.roleScopes);
assert.strictEqual(findAll(TABLE_ROW_SELECTOR).length, 0);
});
test('shows error message on custom scope save on manage org projects page', 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(`[href="${urls.manageCustomScopes}"]`);
await click(
`tbody [href="${urls.manageScopes}/${instances.scopes.org.id}"]`,
);
await click(
SCOPE_CHECKBOX_SELECTOR('project', instances.scopes.project.id),
);
await click(SAVE_BTN_SELECTOR);
assert.dom(TOAST_SELECTOR).isVisible();
});
test('user can search for a specifc project scope by id on manage org projects page', async function (assert) {
const anotherProject = this.server.create('scope', {
type: 'project',
scope: { id: instances.scopes.org.id, type: 'org' },
});
await visit(urls.role);
await click(MANAGE_SCOPES_SELECTOR);
await click(`[href="${urls.manageCustomScopes}"]`);
await click(
`tbody [href="${urls.manageScopes}/${instances.scopes.org.id}"]`,
);
assert
.dom(SCOPE_CHECKBOX_SELECTOR('project', instances.scopes.project.id))
.exists();
assert.dom(SCOPE_CHECKBOX_SELECTOR('project', anotherProject.id)).exists();
await fillIn(SEARCH_INPUT_SELECTOR, instances.scopes.project.id);
await waitUntil(
() =>
findAll(SCOPE_CHECKBOX_SELECTOR('project', anotherProject.id))
.length === 0,
);
assert
.dom(SCOPE_CHECKBOX_SELECTOR('project', instances.scopes.project.id))
.exists();
assert
.dom(SCOPE_CHECKBOX_SELECTOR('project', anotherProject.id))
.doesNotExist();
});
test('user can search for project scopes and get no results on manage org projects page', async function (assert) {
const anotherProject = this.server.create('scope', {
type: 'project',
scope: { id: instances.scopes.org.id, type: 'org' },
});
await visit(urls.role);
await click(MANAGE_SCOPES_SELECTOR);
await click(`[href="${urls.manageCustomScopes}"]`);
await click(
`tbody [href="${urls.manageScopes}/${instances.scopes.org.id}"]`,
);
assert
.dom(SCOPE_CHECKBOX_SELECTOR('project', instances.scopes.project.id))
.exists();
assert.dom(SCOPE_CHECKBOX_SELECTOR('project', anotherProject.id)).exists();
await fillIn(SEARCH_INPUT_SELECTOR, 'fake scope that does not exist');
await waitUntil(() => findAll(NO_RESULTS_MSG_SELECTOR).length === 1);
assert
.dom(SCOPE_CHECKBOX_SELECTOR('project', instances.scopes.project.id))
.doesNotExist();
assert
.dom(SCOPE_CHECKBOX_SELECTOR('project', anotherProject.id))
.doesNotExist();
assert.dom(NO_RESULTS_MSG_SELECTOR).includesText('No results found');
});
});
@@ -0,0 +1,376 @@
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import { module, test } from 'qunit';
import {
visit,
currentURL,
click,
findAll,
fillIn,
waitUntil,
} 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,
GRANT_SCOPE_CHILDREN,
GRANT_SCOPE_DESCENDANTS,
} from 'api/models/role';
module('Acceptance | roles | org-scope', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);
setupIndexedDb(hooks);
const SCOPE_TOGGLE_SELECTOR = (name) =>
`.hds-form-toggle input[name="${name}"]`;
const SCOPE_CHECKBOX_SELECTOR = (type, id) =>
`tbody [data-test-${type}-scopes-table-row="${id}"] input`;
const TABLE_ROW_SELECTOR = 'tbody tr';
const TABLE_SCOPE_SELECTOR = 'tbody tr:nth-child(2) a';
const TABLE_PARENT_SCOPE_SELECTOR = 'tbody tr:nth-child(2) td:nth-child(3) a';
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 SEARCH_INPUT_SELECTOR = '.search-filtering [type="search"]';
const NO_RESULTS_MSG_SELECTOR = '[data-test-no-grant-scope-results]';
const NO_SCOPES_MSG_SELECTOR = '.role-grant-scopes div';
const NO_SCOPES_MSG_LINK_SELECTOR =
'.role-grant-scopes div div:nth-child(3) a';
const instances = {
scopes: {
global: null,
org: null,
project: null,
},
role: null,
};
const urls = {
orgScope: null,
roles: null,
role: null,
roleScopes: null,
manageScopes: null,
manageOrgProjects: null,
};
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.scopes.project = this.server.create('scope', {
type: 'project',
scope: { id: instances.scopes.org.id, type: 'org' },
});
instances.role = this.server.create(
'role',
{
scope: instances.scopes.org,
},
'withScopes',
);
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`;
urls.manageOrgProjects = `${urls.role}/manage-scopes/${instances.scopes.org.id}`;
});
test('visiting role scopes', async function (assert) {
await visit(urls.role);
await click(`[href="${urls.roleScopes}"]`);
await a11yAudit();
assert.strictEqual(currentURL(), urls.roleScopes);
assert
.dom(TABLE_ROW_SELECTOR)
.exists({ count: instances.role.grant_scope_ids.length });
});
test('user can naviage to scope from role grant scopes', async function (assert) {
await visit(urls.role);
await click(`[href="${urls.roleScopes}"]`);
await click(TABLE_SCOPE_SELECTOR);
assert.strictEqual(
currentURL(),
`/scopes/${instances.scopes.org.id}/scopes`,
);
});
test('user can naviage to parent scope from role grant scopes', async function (assert) {
await visit(urls.role);
await click(`[href="${urls.roleScopes}"]`);
await click(TABLE_PARENT_SCOPE_SELECTOR);
assert.strictEqual(
currentURL(),
`/scopes/${instances.scopes.global.id}/scopes`,
);
});
test('user sees no scopes message and action when role has no grant scopes', async function (assert) {
instances.role.update({ grant_scope_ids: [] });
await visit(urls.role);
await click(`[href="${urls.roleScopes}"]`);
assert.dom(NO_SCOPES_MSG_SELECTOR).includesText('No scopes added');
assert.dom(NO_SCOPES_MSG_LINK_SELECTOR).isVisible();
});
test('user does not see action to add scopes when role has no grant scopes without proper permissions', async function (assert) {
instances.role.update({
grant_scope_ids: [],
authorized_actions: instances.role.authorized_actions.filter(
(action) => action !== 'set-grant-scopes',
),
});
await visit(urls.role);
await click(`[href="${urls.roleScopes}"]`);
assert.dom(NO_SCOPES_MSG_LINK_SELECTOR).doesNotExist();
});
test('correct toggles are visible for org level role on manage scopes page', async function (assert) {
await visit(urls.role);
await click(MANAGE_SCOPES_SELECTOR);
assert.strictEqual(currentURL(), urls.manageScopes);
assert.dom(SCOPE_TOGGLE_SELECTOR(GRANT_SCOPE_THIS)).isVisible();
assert.dom(SCOPE_TOGGLE_SELECTOR(GRANT_SCOPE_CHILDREN)).isVisible();
assert.dom(SCOPE_TOGGLE_SELECTOR(GRANT_SCOPE_DESCENDANTS)).doesNotExist();
});
test('user can save scope keywords to add on manage scopes page', 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);
await a11yAudit();
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('user can cancel scope keywords to add on manage scopes page', 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 on manage scopes page', 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();
});
test('user can save custom scopes to add on manage org projects page', 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);
await click(`[href="${urls.manageOrgProjects}"]`);
await a11yAudit();
// Click three times to select, unselect, then reselect (for coverage)
await click(
SCOPE_CHECKBOX_SELECTOR('project', instances.scopes.project.id),
);
await click(
SCOPE_CHECKBOX_SELECTOR('project', instances.scopes.project.id),
);
await click(
SCOPE_CHECKBOX_SELECTOR('project', instances.scopes.project.id),
);
await click(SAVE_BTN_SELECTOR);
assert.strictEqual(currentURL(), urls.manageScopes);
await click(SAVE_BTN_SELECTOR);
assert.strictEqual(currentURL(), urls.roleScopes);
assert.strictEqual(findAll(TABLE_ROW_SELECTOR).length, 1);
});
test('user can cancel custom scopes to add on manage org projects page', 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);
await click(`[href="${urls.manageOrgProjects}"]`);
await a11yAudit();
// Click three times to select, unselect, then reselect (for coverage)
await click(
SCOPE_CHECKBOX_SELECTOR('project', instances.scopes.project.id),
);
await click(
SCOPE_CHECKBOX_SELECTOR('project', instances.scopes.project.id),
);
await click(
SCOPE_CHECKBOX_SELECTOR('project', instances.scopes.project.id),
);
await click(CANCEL_BTN_SELECTOR);
assert.strictEqual(currentURL(), urls.manageScopes);
await click(CANCEL_BTN_SELECTOR);
assert.strictEqual(currentURL(), urls.roleScopes);
assert.strictEqual(findAll(TABLE_ROW_SELECTOR).length, 0);
});
test('shows error message on custom scope save on manage org projects page', 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(`[href="${urls.manageOrgProjects}"]`);
await click(
SCOPE_CHECKBOX_SELECTOR('project', instances.scopes.project.id),
);
await click(SAVE_BTN_SELECTOR);
assert.dom(TOAST_SELECTOR).isVisible();
});
test('user can search for a specifc project scope by id on manage org projects page', async function (assert) {
const anotherProject = this.server.create('scope', {
type: 'project',
scope: { id: instances.scopes.org.id, type: 'org' },
});
await visit(urls.role);
await click(MANAGE_SCOPES_SELECTOR);
await click(`[href="${urls.manageOrgProjects}"]`);
assert
.dom(SCOPE_CHECKBOX_SELECTOR('project', instances.scopes.project.id))
.exists();
assert.dom(SCOPE_CHECKBOX_SELECTOR('project', anotherProject.id)).exists();
await fillIn(SEARCH_INPUT_SELECTOR, instances.scopes.project.id);
await waitUntil(
() =>
findAll(SCOPE_CHECKBOX_SELECTOR('project', anotherProject.id))
.length === 0,
);
assert
.dom(SCOPE_CHECKBOX_SELECTOR('project', instances.scopes.project.id))
.exists();
assert
.dom(SCOPE_CHECKBOX_SELECTOR('project', anotherProject.id))
.doesNotExist();
});
test('user can search for project scopes and get no results on manage org projects page', async function (assert) {
const anotherProject = this.server.create('scope', {
type: 'project',
scope: { id: instances.scopes.org.id, type: 'org' },
});
await visit(urls.role);
await click(MANAGE_SCOPES_SELECTOR);
await click(`[href="${urls.manageOrgProjects}"]`);
assert
.dom(SCOPE_CHECKBOX_SELECTOR('project', instances.scopes.project.id))
.exists();
assert.dom(SCOPE_CHECKBOX_SELECTOR('project', anotherProject.id)).exists();
await fillIn(SEARCH_INPUT_SELECTOR, 'fake scope that does not exist');
await waitUntil(() => findAll(NO_RESULTS_MSG_SELECTOR).length === 1);
assert
.dom(SCOPE_CHECKBOX_SELECTOR('project', instances.scopes.project.id))
.doesNotExist();
assert
.dom(SCOPE_CHECKBOX_SELECTOR('project', anotherProject.id))
.doesNotExist();
assert.dom(NO_RESULTS_MSG_SELECTOR).includesText('No results found');
});
});
@@ -1,351 +0,0 @@
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import { module, test } from 'qunit';
import {
visit,
currentURL,
click,
findAll,
fillIn,
waitUntil,
} 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,
GRANT_SCOPE_CHILDREN,
GRANT_SCOPE_DESCENDANTS,
} 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 SCOPE_CHECKBOX_SELECTOR = (id) =>
`tbody [data-test-org-scopes-table-row="${id}"] input`;
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 SEARCH_INPUT_SELECTOR = '.search-filtering [type="search"]';
const NO_RESULTS_MSG_SELECTOR = '[data-test-no-scope-results]';
const instances = {
scopes: {
global: null,
org: null,
},
globalRole: null,
orgRole: null,
};
const urls = {
orgScope: null,
globalRoles: null,
globalRole: null,
globalRoleScopes: null,
globalManageScopes: null,
orgRoles: null,
orgRole: null,
orgRoleScopes: null,
orgManageScopes: null,
manageCustomScopes: null,
};
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.globalRole = this.server.create(
'role',
{
scope: instances.scopes.global,
},
'withScopes',
);
instances.orgRole = this.server.create(
'role',
{
scope: instances.scopes.org,
},
'withScopes',
);
urls.globalRoles = `/scopes/global/roles`;
urls.globalRole = `${urls.globalRoles}/${instances.globalRole.id}`;
urls.globalRoleScopes = `${urls.globalRole}/scopes`;
urls.globalManageScopes = `${urls.globalRole}/manage-scopes`;
urls.manageCustomScopes = `${urls.globalManageScopes}/manage-custom-scopes`;
urls.orgRoles = `/scopes/${instances.scopes.org.id}/roles`;
urls.orgRole = `${urls.orgRoles}/${instances.orgRole.id}`;
urls.orgRoleScopes = `${urls.orgRole}/scopes`;
urls.orgManageScopes = `${urls.orgRole}/manage-scopes`;
});
test('visiting role scopes', async function (assert) {
await visit(urls.orgRoleScopes);
await a11yAudit();
assert.strictEqual(currentURL(), urls.orgRoleScopes);
assert
.dom(TABLE_ROW_SELECTOR)
.exists({ count: instances.orgRole.grant_scope_ids.length });
});
test('user can naviage to scope from role grant scopes', async function (assert) {
await visit(urls.orgRoleScopes);
await click('tbody tr:nth-child(2) a');
assert.strictEqual(
currentURL(),
`/scopes/${instances.scopes.org.id}/scopes`,
);
});
test('user can naviage to parent scope from role grant scopes', async function (assert) {
await visit(urls.orgRoleScopes);
await click('tbody tr:nth-child(2) td:nth-child(3) a');
assert.strictEqual(
currentURL(),
`/scopes/${instances.scopes.global.id}/scopes`,
);
});
test('user sees no scopes message and action when role has no grant scopes', async function (assert) {
instances.orgRole.update({ grant_scope_ids: [] });
await visit(urls.orgRoleScopes);
assert.dom('.role-grant-scopes div').includesText('No scopes added');
assert.dom('.role-grant-scopes div div:nth-child(3) a').isVisible();
});
test('user does not see action to add scopes when role has no grant scopes without proper permissions', async function (assert) {
instances.orgRole.update({
grant_scope_ids: [],
authorized_actions: instances.orgRole.authorized_actions.filter(
(action) => action !== 'set-grant-scopes',
),
});
await visit(urls.orgRoleScopes);
assert.dom('.role-grant-scopes div div:nth-child(3) a').doesNotExist();
});
test('user can toggle and save scope keywords to add on manage scopes page', async function (assert) {
instances.orgRole.update({ grant_scope_ids: [] });
await visit(urls.orgRole);
await click(`[href="${urls.orgRoleScopes}"]`);
assert.strictEqual(findAll(TABLE_ROW_SELECTOR).length, 0);
await click(MANAGE_SCOPES_SELECTOR);
assert.strictEqual(currentURL(), urls.orgManageScopes);
// 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.orgRoleScopes);
assert.strictEqual(findAll(TABLE_ROW_SELECTOR).length, 1);
});
test('correct toggles are visible for global level role on manage scopes page', async function (assert) {
await visit(urls.globalRole);
await click(MANAGE_SCOPES_SELECTOR);
assert.strictEqual(currentURL(), urls.globalManageScopes);
assert.dom(SCOPE_TOGGLE_SELECTOR(GRANT_SCOPE_THIS)).isVisible();
assert.dom(SCOPE_TOGGLE_SELECTOR(GRANT_SCOPE_CHILDREN)).isVisible();
assert.dom(SCOPE_TOGGLE_SELECTOR(GRANT_SCOPE_DESCENDANTS)).isVisible();
});
test('correct toggles are visible for org level role on manage scopes page', async function (assert) {
await visit(urls.orgRole);
await click(MANAGE_SCOPES_SELECTOR);
assert.strictEqual(currentURL(), urls.orgManageScopes);
assert.dom(SCOPE_TOGGLE_SELECTOR(GRANT_SCOPE_THIS)).isVisible();
assert.dom(SCOPE_TOGGLE_SELECTOR(GRANT_SCOPE_CHILDREN)).isVisible();
assert.dom(SCOPE_TOGGLE_SELECTOR(GRANT_SCOPE_DESCENDANTS)).doesNotExist();
});
test('user can toggle and cancel scope keywords to add on manage scopes page', async function (assert) {
instances.orgRole.update({ grant_scope_ids: [] });
await visit(urls.orgRole);
await click(`[href="${urls.orgRoleScopes}"]`);
assert.strictEqual(findAll(TABLE_ROW_SELECTOR).length, 0);
await click(MANAGE_SCOPES_SELECTOR);
assert.strictEqual(currentURL(), urls.orgManageScopes);
// 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.orgRoleScopes);
assert.strictEqual(findAll(TABLE_ROW_SELECTOR).length, 0);
});
test('shows error message on scope save on manage scopes page', async function (assert) {
this.server.post('/roles/:idMethod', () => {
return new Response(
400,
{},
{
status: 400,
code: 'invalid_argument',
message: 'The request was invalid.',
details: {},
},
);
});
instances.orgRole.update({ grant_scope_ids: [] });
await visit(urls.orgRole);
await click(MANAGE_SCOPES_SELECTOR);
await click(SCOPE_TOGGLE_SELECTOR(GRANT_SCOPE_THIS));
await click(SAVE_BTN_SELECTOR);
assert.dom(TOAST_SELECTOR).isVisible();
});
test('user can select and save custom scopes to add on manage custom scopes page', async function (assert) {
instances.globalRole.update({ grant_scope_ids: [] });
await visit(urls.globalRole);
await click(`[href="${urls.globalRoleScopes}"]`);
assert.strictEqual(findAll(TABLE_ROW_SELECTOR).length, 0);
await click(MANAGE_SCOPES_SELECTOR);
assert.strictEqual(currentURL(), urls.globalManageScopes);
await click(`[href="${urls.manageCustomScopes}"]`);
// Click three times to select, unselect, then reselect (for coverage)
await click(SCOPE_CHECKBOX_SELECTOR(instances.scopes.org.id));
await click(SCOPE_CHECKBOX_SELECTOR(instances.scopes.org.id));
await click(SCOPE_CHECKBOX_SELECTOR(instances.scopes.org.id));
await click(SAVE_BTN_SELECTOR);
assert.strictEqual(currentURL(), urls.globalManageScopes);
await click(SAVE_BTN_SELECTOR);
assert.strictEqual(currentURL(), urls.globalRoleScopes);
assert.strictEqual(findAll(TABLE_ROW_SELECTOR).length, 1);
});
test('user can select and cancel custom scopes to add on manage custom scopes page', async function (assert) {
instances.globalRole.update({ grant_scope_ids: [] });
await visit(urls.globalRole);
await click(`[href="${urls.globalRoleScopes}"]`);
assert.strictEqual(findAll(TABLE_ROW_SELECTOR).length, 0);
await click(MANAGE_SCOPES_SELECTOR);
assert.strictEqual(currentURL(), urls.globalManageScopes);
await click(`[href="${urls.manageCustomScopes}"]`);
// Click three times to select, unselect, then reselect (for coverage)
await click(SCOPE_CHECKBOX_SELECTOR(instances.scopes.org.id));
await click(SCOPE_CHECKBOX_SELECTOR(instances.scopes.org.id));
await click(SCOPE_CHECKBOX_SELECTOR(instances.scopes.org.id));
await click(CANCEL_BTN_SELECTOR);
assert.strictEqual(currentURL(), urls.globalManageScopes);
await click(CANCEL_BTN_SELECTOR);
assert.strictEqual(currentURL(), urls.globalRoleScopes);
assert.strictEqual(findAll(TABLE_ROW_SELECTOR).length, 0);
});
test('shows error message on custom scope save on manage custom scopes page', async function (assert) {
this.server.post('/roles/:idMethod', () => {
return new Response(
400,
{},
{
status: 400,
code: 'invalid_argument',
message: 'The request was invalid.',
details: {},
},
);
});
instances.globalRole.update({ grant_scope_ids: [] });
await visit(urls.globalRole);
await click(MANAGE_SCOPES_SELECTOR);
await click(`[href="${urls.manageCustomScopes}"]`);
await click(SCOPE_CHECKBOX_SELECTOR(instances.scopes.org.id));
await click(SAVE_BTN_SELECTOR);
assert.dom(TOAST_SELECTOR).isVisible();
});
test('user can search for a specifc org scope by id on manage custom scopes page', async function (assert) {
const anotherOrg = this.server.create('scope', {
type: 'org',
scope: { id: 'global', type: 'global' },
});
await visit(urls.globalManageScopes);
await click(`[href="${urls.manageCustomScopes}"]`);
assert.dom(SCOPE_CHECKBOX_SELECTOR(instances.scopes.org.id)).exists();
assert.dom(SCOPE_CHECKBOX_SELECTOR(anotherOrg.id)).exists();
await fillIn(SEARCH_INPUT_SELECTOR, instances.scopes.org.id);
await waitUntil(
() => findAll(SCOPE_CHECKBOX_SELECTOR(anotherOrg.id)).length === 0,
);
assert.dom(SCOPE_CHECKBOX_SELECTOR(instances.scopes.org.id)).exists();
assert.dom(SCOPE_CHECKBOX_SELECTOR(anotherOrg.id)).doesNotExist();
});
test('user can search for org scopes and get no results on manage custom scopes page', async function (assert) {
const anotherOrg = this.server.create('scope', {
type: 'org',
scope: { id: 'global', type: 'global' },
});
await visit(urls.globalManageScopes);
await click(`[href="${urls.manageCustomScopes}"]`);
assert.dom(SCOPE_CHECKBOX_SELECTOR(instances.scopes.org.id)).exists();
assert.dom(SCOPE_CHECKBOX_SELECTOR(anotherOrg.id)).exists();
await fillIn(SEARCH_INPUT_SELECTOR, 'fake scope that does not exist');
await waitUntil(() => findAll(NO_RESULTS_MSG_SELECTOR).length === 1);
assert.dom(`[href="${urls.role1}"]`).doesNotExist();
assert.dom(`[href="${urls.role2}"]`).doesNotExist();
assert.dom(NO_RESULTS_MSG_SELECTOR).includesText('No results found');
});
});
@@ -0,0 +1,105 @@
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
import { currentURL, visit, waitUntil } from '@ember/test-helpers';
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
import { setupIndexedDb } from 'api/test-support/helpers/indexed-db';
import { authenticateSession } from 'ember-simple-auth/test-support';
module(
'Unit | Controller | scopes/scope/roles/role/manage-scopes/manage-org-projects',
function (hooks) {
setupTest(hooks);
setupMirage(hooks);
setupIndexedDb(hooks);
let store;
let controller;
const instances = {
scopes: {
global: null,
org: null,
project: null,
},
role: null,
};
const urls = {
globalScope: null,
manageOrgProjects: null,
manageCustomScopes: null,
};
hooks.beforeEach(async function () {
authenticateSession({});
store = this.owner.lookup('service:store');
controller = this.owner.lookup(
'controller:scopes/scope/roles/role/manage-scopes/manage-org-projects',
);
instances.scopes.global = this.server.create('scope', {
id: 'global',
type: 'global',
});
instances.scopes.org = this.server.create('scope', {
type: 'org',
scope: { id: 'global', type: 'global' },
});
instances.scopes.project = this.server.create('scope', {
type: 'project',
scope: { id: instances.scopes.org.id, type: 'org' },
});
instances.role = this.server.create('role', {
scope: instances.scopes.global,
grant_scope_ids: [],
});
urls.globalScope = `/scopes/global`;
urls.manageOrgProjects = `${urls.globalScope}/roles/${instances.role.id}/manage-scopes/${instances.scopes.org.id}`;
urls.manageCustomScopes = `${urls.globalScope}/roles/${instances.role.id}/manage-scopes/manage-custom-scopes`;
});
test('it exists', function (assert) {
assert.ok(controller);
});
test('handleSearchInput action sets expected values correctly', async function (assert) {
const searchValue = 'test';
controller.handleSearchInput({ target: { value: searchValue } });
await waitUntil(() => controller.search === searchValue);
assert.strictEqual(controller.page, 1);
assert.strictEqual(controller.search, searchValue);
});
test('setGrantScopes action adds scopes to specified model', async function (assert) {
await visit(urls.manageOrgProjects);
const role = await store.findRecord('role', instances.role.id);
assert.deepEqual(role.grant_scope_ids, []);
await controller.setGrantScopes(role, [instances.scopes.project.id]);
assert.deepEqual(role.grant_scope_ids, [instances.scopes.project.id]);
await waitUntil(() => currentURL() === urls.manageCustomScopes);
assert.strictEqual(currentURL(), urls.manageCustomScopes);
});
test('cancel action causes transition to expected route', async function (assert) {
await visit(urls.manageOrgProjects);
const role = await store.findRecord('role', instances.role.id);
await controller.cancel(role);
await waitUntil(() => currentURL() === urls.manageCustomScopes);
assert.strictEqual(currentURL(), urls.manageCustomScopes);
});
},
);
@@ -0,0 +1,21 @@
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module(
'Unit | Route | scopes/scope/roles/role/manage-scopes/manage-org-projects',
function (hooks) {
setupTest(hooks);
test('it exists', function (assert) {
let route = this.owner.lookup(
'route:scopes/scope/roles/role/manage-scopes/manage-org-projects',
);
assert.ok(route);
});
},
);