2023-03-01 09:39:41 -06:00
|
|
|
/**
|
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
2024-05-31 11:29:24 -07:00
|
|
|
* SPDX-License-Identifier: BUSL-1.1
|
2023-03-01 09:39:41 -06:00
|
|
|
*/
|
|
|
|
|
|
2020-09-23 13:27:50 -04:00
|
|
|
import { module, test } from 'qunit';
|
2025-03-13 09:51:37 -07:00
|
|
|
import { visit, currentURL, click } from '@ember/test-helpers';
|
2024-12-02 12:51:24 -06:00
|
|
|
import { setupApplicationTest } from 'admin/tests/helpers';
|
2025-08-20 10:38:33 -07:00
|
|
|
import { setupSqlite } from 'api/test-support/helpers/sqlite';
|
2020-09-23 13:27:50 -04:00
|
|
|
import { Response } from 'miragejs';
|
2025-02-13 15:54:40 -05:00
|
|
|
import * as commonSelectors from 'admin/tests/helpers/selectors';
|
2025-03-13 09:51:37 -07:00
|
|
|
import * as selectors from './selectors';
|
2025-08-11 11:04:07 -07:00
|
|
|
import { setRunOptions } from 'ember-a11y-testing/test-support';
|
2020-09-23 13:27:50 -04:00
|
|
|
|
|
|
|
|
module('Acceptance | groups | members', function (hooks) {
|
|
|
|
|
setupApplicationTest(hooks);
|
2025-08-20 10:38:33 -07:00
|
|
|
setupSqlite(hooks);
|
2020-09-23 13:27:50 -04:00
|
|
|
|
|
|
|
|
const instances = {
|
|
|
|
|
scopes: {
|
|
|
|
|
org: null,
|
|
|
|
|
},
|
|
|
|
|
group: null,
|
|
|
|
|
};
|
|
|
|
|
const urls = {
|
|
|
|
|
orgScope: null,
|
|
|
|
|
groups: null,
|
|
|
|
|
group: null,
|
|
|
|
|
members: null,
|
|
|
|
|
addMembers: null,
|
|
|
|
|
};
|
|
|
|
|
let membersCount;
|
|
|
|
|
|
2024-12-03 10:27:27 -08:00
|
|
|
hooks.beforeEach(async function () {
|
2020-09-23 13:27:50 -04:00
|
|
|
instances.scopes.org = this.server.create('scope', {
|
|
|
|
|
type: 'org',
|
|
|
|
|
scope: { id: 'global', type: 'global' },
|
|
|
|
|
});
|
2020-11-16 15:08:59 -05:00
|
|
|
instances.group = this.server.create(
|
|
|
|
|
'group',
|
|
|
|
|
{
|
|
|
|
|
scope: instances.scopes.org,
|
|
|
|
|
},
|
2023-11-22 14:07:41 -05:00
|
|
|
'withMembers',
|
2020-11-16 15:08:59 -05:00
|
|
|
);
|
2020-10-03 13:59:07 -04:00
|
|
|
membersCount = instances.group.memberIds.length;
|
2020-09-23 13:27:50 -04:00
|
|
|
urls.groups = `/scopes/${instances.scopes.org.id}/groups`;
|
|
|
|
|
urls.group = `${urls.groups}/${instances.group.id}`;
|
|
|
|
|
urls.members = `${urls.group}/members`;
|
|
|
|
|
urls.addMembers = `${urls.group}/add-members`;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('visiting group members', async function (assert) {
|
2025-08-11 11:04:07 -07:00
|
|
|
setRunOptions({
|
|
|
|
|
rules: {
|
|
|
|
|
'color-contrast': {
|
|
|
|
|
// [ember-a11y-ignore]: axe rule "color-contrast" automatically ignored on 2025-08-01
|
|
|
|
|
enabled: false,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
2020-09-23 13:27:50 -04:00
|
|
|
await visit(urls.members);
|
2025-03-13 09:51:37 -07:00
|
|
|
|
2022-07-07 11:18:51 -07:00
|
|
|
assert.strictEqual(currentURL(), urls.members);
|
2025-05-21 12:20:48 -07:00
|
|
|
assert.dom(commonSelectors.TABLE_ROWS).exists({ count: membersCount });
|
2020-09-23 13:27:50 -04:00
|
|
|
});
|
|
|
|
|
|
2020-09-24 11:53:19 -04:00
|
|
|
test('can remove a member', async function (assert) {
|
2025-08-11 11:04:07 -07:00
|
|
|
setRunOptions({
|
|
|
|
|
rules: {
|
|
|
|
|
'color-contrast': {
|
|
|
|
|
// [ember-a11y-ignore]: axe rule "color-contrast" automatically ignored on 2025-08-01
|
|
|
|
|
enabled: false,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
2020-09-23 13:27:50 -04:00
|
|
|
await visit(urls.members);
|
2025-03-13 09:51:37 -07:00
|
|
|
|
2025-05-21 12:20:48 -07:00
|
|
|
assert.dom(commonSelectors.TABLE_ROWS).exists({ count: membersCount });
|
2025-03-13 09:51:37 -07:00
|
|
|
|
|
|
|
|
await click(selectors.TABLE_MEMBER_ACTION_DROPDOWN);
|
|
|
|
|
await click(selectors.TABLE_MEMBER_ACTION_DROPDOWN_DELETE_MEMBER);
|
|
|
|
|
|
2025-05-21 12:20:48 -07:00
|
|
|
assert.dom(commonSelectors.TABLE_ROWS).exists({ count: membersCount - 1 });
|
2020-09-23 13:27:50 -04:00
|
|
|
});
|
|
|
|
|
|
2021-10-01 17:00:36 -04:00
|
|
|
test('cannot remove a member without proper authorization', async function (assert) {
|
2025-08-11 11:04:07 -07:00
|
|
|
setRunOptions({
|
|
|
|
|
rules: {
|
|
|
|
|
'color-contrast': {
|
|
|
|
|
// [ember-a11y-ignore]: axe rule "color-contrast" automatically ignored on 2025-08-01
|
|
|
|
|
enabled: false,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
2021-10-01 17:00:36 -04:00
|
|
|
const authorized_actions = instances.group.authorized_actions.filter(
|
2023-11-22 14:07:41 -05:00
|
|
|
(item) => item !== 'remove-members',
|
2021-10-01 17:00:36 -04:00
|
|
|
);
|
|
|
|
|
instances.group.update({ authorized_actions });
|
|
|
|
|
await visit(urls.members);
|
2025-03-13 09:51:37 -07:00
|
|
|
|
|
|
|
|
assert
|
|
|
|
|
.dom(selectors.TABLE_MEMBER_ACTION_DROPDOWN_DELETE_MEMBER)
|
|
|
|
|
.doesNotExist();
|
2021-10-01 17:00:36 -04:00
|
|
|
});
|
|
|
|
|
|
2020-09-23 13:27:50 -04:00
|
|
|
test('shows error message on member remove', async function (assert) {
|
2025-08-11 11:04:07 -07:00
|
|
|
setRunOptions({
|
|
|
|
|
rules: {
|
|
|
|
|
'color-contrast': {
|
|
|
|
|
// [ember-a11y-ignore]: axe rule "color-contrast" automatically ignored on 2025-08-01
|
|
|
|
|
enabled: false,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
2025-03-13 09:51:37 -07:00
|
|
|
const errorMsg = 'The request was invalid.';
|
2020-09-23 13:27:50 -04:00
|
|
|
this.server.post('/groups/:idMethod', () => {
|
|
|
|
|
return new Response(
|
|
|
|
|
400,
|
|
|
|
|
{},
|
|
|
|
|
{
|
|
|
|
|
status: 400,
|
|
|
|
|
code: 'invalid_argument',
|
2025-03-13 09:51:37 -07:00
|
|
|
message: errorMsg,
|
2020-09-23 13:27:50 -04:00
|
|
|
details: {},
|
2023-11-22 14:07:41 -05:00
|
|
|
},
|
2020-09-23 13:27:50 -04:00
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
await visit(urls.members);
|
2025-05-21 12:20:48 -07:00
|
|
|
assert.dom(commonSelectors.TABLE_ROWS).exists({ count: membersCount });
|
2025-03-13 09:51:37 -07:00
|
|
|
|
|
|
|
|
await click(selectors.TABLE_MEMBER_ACTION_DROPDOWN);
|
|
|
|
|
await click(selectors.TABLE_MEMBER_ACTION_DROPDOWN_DELETE_MEMBER);
|
|
|
|
|
|
|
|
|
|
assert.dom(commonSelectors.ALERT_TOAST_BODY).hasText(errorMsg);
|
2020-09-23 13:27:50 -04:00
|
|
|
});
|
|
|
|
|
|
2020-11-16 15:08:59 -05:00
|
|
|
test('visiting member selection', async function (assert) {
|
2025-08-11 11:04:07 -07:00
|
|
|
setRunOptions({
|
|
|
|
|
rules: {
|
|
|
|
|
'color-contrast': {
|
|
|
|
|
// [ember-a11y-ignore]: axe rule "color-contrast" automatically ignored on 2025-08-01
|
|
|
|
|
enabled: false,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
2020-09-23 13:27:50 -04:00
|
|
|
await visit(urls.addMembers);
|
2025-07-22 13:25:07 -05:00
|
|
|
|
2022-07-07 11:18:51 -07:00
|
|
|
assert.strictEqual(currentURL(), urls.addMembers);
|
2020-09-23 13:27:50 -04:00
|
|
|
});
|
|
|
|
|
|
2021-10-01 17:00:36 -04:00
|
|
|
test('can navigate to add members with proper authorization', async function (assert) {
|
2025-08-11 11:04:07 -07:00
|
|
|
setRunOptions({
|
|
|
|
|
rules: {
|
|
|
|
|
'color-contrast': {
|
|
|
|
|
// [ember-a11y-ignore]: axe rule "color-contrast" automatically ignored on 2025-08-01
|
|
|
|
|
enabled: false,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
2021-10-01 17:00:36 -04:00
|
|
|
await visit(urls.group);
|
2025-03-13 09:51:37 -07:00
|
|
|
await click(selectors.MANAGE_DROPDOWN);
|
|
|
|
|
assert.dom(selectors.MANAGE_DROPDOWN_ADD_MEMBER).isVisible();
|
2021-10-01 17:00:36 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('cannot navigate to add members without proper authorization', async function (assert) {
|
2025-08-11 11:04:07 -07:00
|
|
|
setRunOptions({
|
|
|
|
|
rules: {
|
|
|
|
|
'color-contrast': {
|
|
|
|
|
// [ember-a11y-ignore]: axe rule "color-contrast" automatically ignored on 2025-08-01
|
|
|
|
|
enabled: false,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
2021-10-01 17:00:36 -04:00
|
|
|
const authorized_actions = instances.group.authorized_actions.filter(
|
2023-11-22 14:07:41 -05:00
|
|
|
(item) => item !== 'add-members',
|
2021-10-01 17:00:36 -04:00
|
|
|
);
|
|
|
|
|
instances.group.update({ authorized_actions });
|
2025-03-13 09:51:37 -07:00
|
|
|
|
2021-10-01 17:00:36 -04:00
|
|
|
await visit(urls.group);
|
2025-07-15 14:03:27 -05:00
|
|
|
await click(selectors.MANAGE_DROPDOWN);
|
2025-03-13 09:51:37 -07:00
|
|
|
|
|
|
|
|
assert.dom(commonSelectors.HREF(urls.addMembers)).doesNotExist();
|
2021-10-01 17:00:36 -04:00
|
|
|
});
|
|
|
|
|
|
2020-09-23 13:27:50 -04:00
|
|
|
test('select and save members to add', async function (assert) {
|
2025-08-11 11:04:07 -07:00
|
|
|
setRunOptions({
|
|
|
|
|
rules: {
|
|
|
|
|
'color-contrast': {
|
|
|
|
|
// [ember-a11y-ignore]: axe rule "color-contrast" automatically ignored on 2025-08-01
|
|
|
|
|
enabled: false,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
2020-09-23 13:27:50 -04:00
|
|
|
instances.group.update({ memberIds: [] });
|
|
|
|
|
await visit(urls.members);
|
2025-03-13 09:51:37 -07:00
|
|
|
|
2025-05-21 12:20:48 -07:00
|
|
|
assert.dom(commonSelectors.TABLE_ROWS).exists({ count: 0 });
|
2025-03-13 09:51:37 -07:00
|
|
|
|
|
|
|
|
await click(selectors.MANAGE_DROPDOWN);
|
|
|
|
|
await click(selectors.MANAGE_DROPDOWN_ADD_MEMBER);
|
|
|
|
|
|
2022-07-07 11:18:51 -07:00
|
|
|
assert.strictEqual(currentURL(), urls.addMembers);
|
2020-10-03 13:59:07 -04:00
|
|
|
// Click three times to select, unselect, then reselect (for coverage)
|
2025-03-13 09:51:37 -07:00
|
|
|
await click(commonSelectors.TABLE_ROW_CHECKBOX);
|
|
|
|
|
await click(commonSelectors.SAVE_BTN);
|
|
|
|
|
|
2020-09-23 13:27:50 -04:00
|
|
|
await visit(urls.members);
|
2025-03-13 09:51:37 -07:00
|
|
|
|
2025-05-21 12:20:48 -07:00
|
|
|
assert.dom(commonSelectors.TABLE_ROWS).exists({ count: 1 });
|
2020-09-23 13:27:50 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('select and cancel members to add', async function (assert) {
|
2025-08-11 11:04:07 -07:00
|
|
|
setRunOptions({
|
|
|
|
|
rules: {
|
|
|
|
|
'color-contrast': {
|
|
|
|
|
// [ember-a11y-ignore]: axe rule "color-contrast" automatically ignored on 2025-08-01
|
|
|
|
|
enabled: false,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
2020-09-23 13:27:50 -04:00
|
|
|
await visit(urls.members);
|
2025-03-13 09:51:37 -07:00
|
|
|
|
2025-05-21 12:20:48 -07:00
|
|
|
assert.dom(commonSelectors.TABLE_ROWS).exists({ count: membersCount });
|
2025-03-13 09:51:37 -07:00
|
|
|
|
|
|
|
|
await click(selectors.TABLE_MEMBER_ACTION_DROPDOWN);
|
|
|
|
|
await click(selectors.TABLE_MEMBER_ACTION_DROPDOWN_DELETE_MEMBER);
|
|
|
|
|
|
2025-05-21 12:20:48 -07:00
|
|
|
assert.dom(commonSelectors.TABLE_ROWS).exists({ count: membersCount - 1 });
|
2025-03-13 09:51:37 -07:00
|
|
|
|
|
|
|
|
await click(selectors.MANAGE_DROPDOWN);
|
|
|
|
|
await click(selectors.MANAGE_DROPDOWN_ADD_MEMBER);
|
|
|
|
|
|
2022-07-07 11:18:51 -07:00
|
|
|
assert.strictEqual(currentURL(), urls.addMembers);
|
2025-03-13 09:51:37 -07:00
|
|
|
|
|
|
|
|
await click(commonSelectors.TABLE_ROW_CHECKBOX);
|
|
|
|
|
|
|
|
|
|
await click(commonSelectors.CANCEL_BTN);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(currentURL(), urls.members);
|
2025-05-21 12:20:48 -07:00
|
|
|
assert.dom(commonSelectors.TABLE_ROWS).exists({ count: membersCount - 1 });
|
2020-09-23 13:27:50 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('shows error message on member add', async function (assert) {
|
2025-08-11 11:04:07 -07:00
|
|
|
setRunOptions({
|
|
|
|
|
rules: {
|
|
|
|
|
'color-contrast': {
|
|
|
|
|
// [ember-a11y-ignore]: axe rule "color-contrast" automatically ignored on 2025-08-01
|
|
|
|
|
enabled: false,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
2025-03-13 09:51:37 -07:00
|
|
|
const errorMsg = 'The request was invalid.';
|
2020-09-23 13:27:50 -04:00
|
|
|
this.server.post('/groups/:idMethod', () => {
|
|
|
|
|
return new Response(
|
|
|
|
|
400,
|
|
|
|
|
{},
|
|
|
|
|
{
|
|
|
|
|
status: 400,
|
|
|
|
|
code: 'invalid_argument',
|
2025-03-13 09:51:37 -07:00
|
|
|
message: errorMsg,
|
2020-09-23 13:27:50 -04:00
|
|
|
details: {},
|
2023-11-22 14:07:41 -05:00
|
|
|
},
|
2020-09-23 13:27:50 -04:00
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
instances.group.update({ memberIds: [] });
|
|
|
|
|
await visit(urls.addMembers);
|
2025-03-13 09:51:37 -07:00
|
|
|
|
|
|
|
|
await click(commonSelectors.SAVE_BTN);
|
|
|
|
|
|
|
|
|
|
assert.dom(commonSelectors.ALERT_TOAST_BODY).hasText(errorMsg);
|
2020-09-23 13:27:50 -04:00
|
|
|
});
|
|
|
|
|
});
|