fix: 🐛 policy UI bug fix (#2098)

* fix: 🐛 policy UI bug fix
This commit is contained in:
Dharini Jeeva authored and GitHub committed 2024-01-19 14:06:51 -08:00
1 parent 3f2fc63b5b
commit 5a74220f38
15 files changed
+341 -58

No files matched your search

@@ -4,7 +4,7 @@
*/
import { module, test } from 'qunit';
import { visit, currentURL, click, fillIn } from '@ember/test-helpers';
import { visit, currentURL, click, fillIn, select } from '@ember/test-helpers';
import { setupApplicationTest } from 'admin/tests/helpers';
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
import a11yAudit from 'ember-a11y-testing/test-support/audit';
@@ -21,10 +21,15 @@ module('Acceptance | policies | create', function (hooks) {
const SAVE_BTN_SELECTOR = '[type="submit"]';
const CANCEL_BTN_SELECTOR = '.rose-form-actions [type="button"]';
const NAME_FIELD_SELECTOR = '[name="name"]';
const RETAIN_FOR_INPUT = 'input[data-input-type="retain_for"]';
const RETAIN_FOR_TEXT_INPUT = '[data-input="retain_for"]';
const ALERT_TEXT_SELECTOR = '[role="alert"] div';
const FIELD_ERROR_TEXT_SELECTOR = '.hds-form-error__message';
const NAME_FIELD_TEXT = 'random string';
const DELETE_AFTER_TEXT_INPUT = '[data-input="delete_after"]';
const RETAIN_OVERRIDE = '[data-toggle="retain_for"]';
const DELETE_OVERRIDE = '[data-toggle="delete_after"]';
const RETAIN_SELECT_LIST = '[data-select="retention_policy"]';
const DELETE_SELECT_LIST = '[data-select="deletion_policy"]';
const instances = {
scopes: {
@@ -63,7 +68,7 @@ module('Acceptance | policies | create', function (hooks) {
await click('.hds-form-select');
await fillIn('.hds-form-select', 1);
await fillIn(RETAIN_FOR_INPUT, 90);
await fillIn(RETAIN_FOR_TEXT_INPUT, 90);
await click(SAVE_BTN_SELECTOR);
const policy = this.server.schema.policies.findBy({
name: NAME_FIELD_TEXT,
@@ -75,6 +80,54 @@ module('Acceptance | policies | create', function (hooks) {
assert.strictEqual(getPolicyCount(), policyCount + 1);
});
test('delete policy is automatically disabled when forever retention policy is chosen', async function (assert) {
await visit(urls.policies);
await click(`[href="${urls.newPolicy}"]`);
await select(RETAIN_SELECT_LIST, '-1');
assert.dom(DELETE_SELECT_LIST).isDisabled();
});
test('user can enter custom value when custom retain option is selected', async function (assert) {
await visit(urls.policies);
await click(`[href="${urls.newPolicy}"]`);
await select(RETAIN_SELECT_LIST, '1');
assert.dom(RETAIN_FOR_TEXT_INPUT).isVisible();
});
test('user can enter custom value when custom delete option is selected', async function (assert) {
await visit(urls.policies);
await click(`[href="${urls.newPolicy}"]`);
await select(DELETE_SELECT_LIST, '1');
assert.dom(DELETE_AFTER_TEXT_INPUT).isVisible();
});
test('user can select SOC option and will not see custom input', async function (assert) {
await visit(urls.policies);
await click(`[href="${urls.newPolicy}"]`);
await select(RETAIN_SELECT_LIST, '2555');
assert.dom(RETAIN_FOR_TEXT_INPUT).isNotVisible();
});
test('user can select do_not_delete option and will not see custom input', async function (assert) {
await visit(urls.policies);
await click(`[href="${urls.newPolicy}"]`);
await select(DELETE_SELECT_LIST, '0');
assert.dom(DELETE_AFTER_TEXT_INPUT).isNotVisible();
});
test('org override is disabled when do_not_protect is selected', async function (assert) {
await visit(urls.policies);
await click(`[href="${urls.newPolicy}"]`);
await select(RETAIN_SELECT_LIST, '0');
assert.dom(RETAIN_OVERRIDE).isDisabled();
});
test('org override is disabled when do_not_delete is selected', async function (assert) {
await visit(urls.policies);
await click(`[href="${urls.newPolicy}"]`);
await select(DELETE_SELECT_LIST, '0');
assert.dom(DELETE_OVERRIDE).isDisabled();
});
test('user can cancel new policy creation', async function (assert) {
const policyCount = getPolicyCount();
await visit(urls.policies);
@@ -0,0 +1,89 @@
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
import { module, test } from 'qunit';
import { visit, click } from '@ember/test-helpers';
import { setupApplicationTest } from 'admin/tests/helpers';
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
import { authenticateSession } from 'ember-simple-auth/test-support';
module('Acceptance | policies | delete', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);
let featuresService;
let policyCount;
const DROPDOWN_BUTTON_SELECTOR = '.hds-dropdown-toggle-icon';
const DROPDOWN_ITEM_SELECTOR = '.hds-dropdown-list-item button';
const instances = {
scopes: {
global: null,
org: null,
},
policy: null,
};
const urls = {
globalScope: null,
policies: null,
policy: 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.policy = this.server.create('policy', {
scope: instances.scopes.global,
});
urls.globalScope = `/scopes/global`;
urls.policies = `${urls.globalScope}/policies`;
featuresService = this.owner.lookup('service:features');
policyCount = () => this.server.schema.policies.all().models.length;
});
test('users can delete a storage policy', async function (assert) {
const count = policyCount();
featuresService.enable('ssh-session-recording');
assert.true(instances.policy.authorized_actions.includes('delete'));
await visit(urls.globalScope);
urls.policy = `${urls.policies}/${instances.policy.id}`;
await click(`[href="${urls.policies}"]`);
await click(DROPDOWN_BUTTON_SELECTOR);
assert.dom(DROPDOWN_ITEM_SELECTOR).exists();
assert.dom(DROPDOWN_ITEM_SELECTOR).hasText('Delete Storage Policy');
await click(DROPDOWN_ITEM_SELECTOR);
assert.strictEqual(policyCount(), count - 1);
});
test('users cannot delete a storage policy without proper authorization', async function (assert) {
featuresService.enable('ssh-session-recording');
instances.policy.authorized_actions =
instances.policy.authorized_actions.filter((item) => item !== 'delete');
await visit(urls.globalScope);
urls.policy = `${urls.policies}/${instances.policy.id}`;
await click(`[href="${urls.policies}"]`);
await click(DROPDOWN_BUTTON_SELECTOR);
assert.dom(DROPDOWN_ITEM_SELECTOR).isNotVisible();
});
});
@@ -0,0 +1,150 @@
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
import { module, test } from 'qunit';
import { visit, click, fillIn, select } from '@ember/test-helpers';
import { setupApplicationTest } from 'admin/tests/helpers';
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
import { authenticateSession } from 'ember-simple-auth/test-support';
module('Acceptance | policies | update', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);
let features;
const SAVE_BTN_SELECTOR = '[type="submit"]';
const NAME_FIELD_SELECTOR = '[name="name"]';
const RETAIN_FOR_TEXT_INPUT = '[data-input="retain_for"]';
const NAME_FIELD_TEXT = 'random string';
const DELETE_AFTER_TEXT_INPUT = '[data-input="delete_after"]';
const DELETE_OVERRIDE = '[data-toggle="delete_after"]';
const RETAIN_SELECT_LIST = '[data-select="retention_policy"]';
const DELETE_SELECT_LIST = '[data-select="deletion_policy"]';
const BUTTON_SELECTOR = '.rose-form-actions [type="button"]';
const instances = {
scopes: {
global: null,
},
storageBucket: null,
};
const urls = {
globalScope: null,
policies: null,
newPolicy: null,
policy: null,
};
hooks.beforeEach(function () {
instances.scopes.global = this.server.create('scope', { id: 'global' });
instances.policy = this.server.create('policy', {
scope: instances.scopes.global,
});
urls.globalScope = `/scopes/global`;
urls.policies = `${urls.globalScope}/policies`;
urls.newPolicy = `${urls.policies}/new`;
urls.policy = `${urls.policies}/${instances.policy.id}`;
features = this.owner.lookup('service:features');
features.enable('ssh-session-recording');
authenticateSession({});
});
test('users can update forever select option to a custom input', async function (assert) {
await visit(urls.policies);
await click(`[href="${urls.policy}"]`);
await click(BUTTON_SELECTOR, 'Click edit mode');
await select(RETAIN_SELECT_LIST, '-1');
await click(SAVE_BTN_SELECTOR);
assert.strictEqual(
this.server.schema.policies.first().attributes.retain_for.days,
-1,
);
await click(BUTTON_SELECTOR, 'Click edit mode');
await select(RETAIN_SELECT_LIST, '1');
await fillIn(RETAIN_FOR_TEXT_INPUT, 100);
await click(SAVE_BTN_SELECTOR);
assert.strictEqual(
this.server.schema.policies.first().attributes.retain_for.days,
100,
);
assert.dom(RETAIN_FOR_TEXT_INPUT).isVisible();
});
test('users can update a custom input', async function (assert) {
await visit(urls.policies);
await click(`[href="${urls.policy}"]`);
await click(BUTTON_SELECTOR, 'Click edit mode');
await select(RETAIN_SELECT_LIST, '1');
await fillIn(RETAIN_FOR_TEXT_INPUT, 100);
await click(SAVE_BTN_SELECTOR);
assert.strictEqual(
this.server.schema.policies.first().attributes.retain_for.days,
100,
);
await click(BUTTON_SELECTOR, 'Click edit mode');
await select(RETAIN_SELECT_LIST, '1');
await fillIn(RETAIN_FOR_TEXT_INPUT, 10);
await click(SAVE_BTN_SELECTOR);
assert.strictEqual(
this.server.schema.policies.first().attributes.retain_for.days,
10,
);
assert.dom(RETAIN_FOR_TEXT_INPUT).isVisible();
});
test('users can update from do_not_delete to a custom input', async function (assert) {
await visit(urls.policies);
await click(`[href="${urls.policy}"]`);
await click(BUTTON_SELECTOR, 'Click edit mode');
await select(DELETE_SELECT_LIST, '0');
await click(SAVE_BTN_SELECTOR);
assert.strictEqual(
this.server.schema.policies.first().attributes.delete_after.days,
0,
);
await click(BUTTON_SELECTOR, 'Click edit mode');
await select(DELETE_SELECT_LIST, '1');
await fillIn(DELETE_AFTER_TEXT_INPUT, 100);
await click(SAVE_BTN_SELECTOR);
assert.strictEqual(
this.server.schema.policies.first().attributes.delete_after.days,
100,
);
assert.dom(DELETE_AFTER_TEXT_INPUT).isVisible();
});
test('users cannot update delete override when do_not_protect is selected', async function (assert) {
await visit(urls.policies);
await click(`[href="${urls.policy}"]`);
await click(BUTTON_SELECTOR, 'Click edit mode');
await select(DELETE_SELECT_LIST, '0');
assert.dom(DELETE_OVERRIDE).isDisabled();
});
test('can cancel changes to an existing storage policy', async function (assert) {
const name = instances.policy.name;
await visit(urls.policies);
await click(`[href="${urls.policy}"]`);
await click(BUTTON_SELECTOR, 'Click edit mode');
await fillIn(NAME_FIELD_SELECTOR, NAME_FIELD_TEXT);
await click(BUTTON_SELECTOR, 'Click cancel');
assert.dom(NAME_FIELD_SELECTOR).hasValue(`${name}`);
assert.strictEqual(instances.policy.name, name);
});
});