refactor: 💡 use test selector in host-catalog read, delete and update (#2734)
This commit is contained in:
1 parent
e69c6456d1
commit
3260bf1b2a
4 files changed
+105
-87
No files matched your search
@@ -15,6 +15,7 @@ import {
|
||||
TYPE_HOST_CATALOG_DYNAMIC,
|
||||
TYPE_HOST_CATALOG_PLUGIN_GCP,
|
||||
} from 'api/models/host-catalog';
|
||||
import * as selectors from './selectors';
|
||||
|
||||
module('Acceptance | host-catalogs | delete', function (hooks) {
|
||||
setupApplicationTest(hooks);
|
||||
@@ -22,10 +23,6 @@ module('Acceptance | host-catalogs | delete', function (hooks) {
|
||||
setupIndexedDb(hooks);
|
||||
|
||||
let getHostCatalogCount;
|
||||
const MANAGE_DROPDOWN_SELECTOR =
|
||||
'[data-test-manage-host-catalogs-dropdown] button:first-child';
|
||||
const DELETE_ACTION_SELECTOR =
|
||||
'[data-test-manage-host-catalogs-dropdown] ul li button';
|
||||
|
||||
const instances = {
|
||||
scopes: {
|
||||
@@ -81,11 +78,11 @@ module('Acceptance | host-catalogs | delete', function (hooks) {
|
||||
|
||||
test('can delete host catalog', async function (assert) {
|
||||
const hostCatalogCount = getHostCatalogCount();
|
||||
|
||||
await visit(urls.hostCatalogs);
|
||||
await click(`[href="${urls.hostCatalog}"]`);
|
||||
await click(MANAGE_DROPDOWN_SELECTOR);
|
||||
await click(DELETE_ACTION_SELECTOR);
|
||||
|
||||
await click(commonSelectors.HREF(urls.hostCatalog));
|
||||
await click(selectors.MANAGE_DROPDOWN_HOST_CATALOG);
|
||||
await click(selectors.MANAGE_DROPDOWN_HOST_CATALOG_DELETE);
|
||||
|
||||
assert.strictEqual(getHostCatalogCount(), hostCatalogCount - 1);
|
||||
});
|
||||
@@ -94,10 +91,10 @@ module('Acceptance | host-catalogs | delete', function (hooks) {
|
||||
const hostCatalogCount = getHostCatalogCount();
|
||||
|
||||
await visit(urls.hostCatalogs);
|
||||
await click(`[href="${urls.gcpDynamicHostCatalog}"]`);
|
||||
await click(commonSelectors.HREF(urls.gcpDynamicHostCatalog));
|
||||
|
||||
await click(MANAGE_DROPDOWN_SELECTOR);
|
||||
await click(DELETE_ACTION_SELECTOR);
|
||||
await click(selectors.MANAGE_DROPDOWN_HOST_CATALOG);
|
||||
await click(selectors.MANAGE_DROPDOWN_HOST_CATALOG_DELETE);
|
||||
|
||||
assert.strictEqual(getHostCatalogCount(), hostCatalogCount - 1);
|
||||
});
|
||||
@@ -109,10 +106,10 @@ module('Acceptance | host-catalogs | delete', function (hooks) {
|
||||
(item) => item !== 'delete',
|
||||
);
|
||||
|
||||
await click(`[href="${urls.hostCatalog}"]`);
|
||||
await click(MANAGE_DROPDOWN_SELECTOR);
|
||||
await click(commonSelectors.HREF(urls.hostCatalog));
|
||||
await click(selectors.MANAGE_DROPDOWN_HOST_CATALOG);
|
||||
|
||||
assert.dom(DELETE_ACTION_SELECTOR).doesNotExist();
|
||||
assert.dom(selectors.MANAGE_DROPDOWN_HOST_CATALOG_DELETE).doesNotExist();
|
||||
});
|
||||
|
||||
test('can accept delete host catalog via dialog', async function (assert) {
|
||||
@@ -121,9 +118,9 @@ module('Acceptance | host-catalogs | delete', function (hooks) {
|
||||
const hostCatalogCount = getHostCatalogCount();
|
||||
await visit(urls.hostCatalogs);
|
||||
|
||||
await click(`[href="${urls.hostCatalog}"]`);
|
||||
await click(MANAGE_DROPDOWN_SELECTOR);
|
||||
await click(DELETE_ACTION_SELECTOR);
|
||||
await click(commonSelectors.HREF(urls.hostCatalog));
|
||||
await click(selectors.MANAGE_DROPDOWN_HOST_CATALOG);
|
||||
await click(selectors.MANAGE_DROPDOWN_HOST_CATALOG_DELETE);
|
||||
await click(commonSelectors.MODAL_WARNING_CONFIRM_BTN);
|
||||
|
||||
assert
|
||||
@@ -139,9 +136,9 @@ module('Acceptance | host-catalogs | delete', function (hooks) {
|
||||
const hostCatalogCount = getHostCatalogCount();
|
||||
await visit(urls.hostCatalogs);
|
||||
|
||||
await click(`[href="${urls.hostCatalog}"]`);
|
||||
await click(MANAGE_DROPDOWN_SELECTOR);
|
||||
await click(DELETE_ACTION_SELECTOR);
|
||||
await click(commonSelectors.HREF(urls.hostCatalog));
|
||||
await click(selectors.MANAGE_DROPDOWN_HOST_CATALOG);
|
||||
await click(selectors.MANAGE_DROPDOWN_HOST_CATALOG_DELETE);
|
||||
await click(commonSelectors.MODAL_WARNING_CANCEL_BTN);
|
||||
|
||||
assert.strictEqual(getHostCatalogCount(), hostCatalogCount);
|
||||
@@ -162,9 +159,9 @@ module('Acceptance | host-catalogs | delete', function (hooks) {
|
||||
);
|
||||
});
|
||||
|
||||
await click(`[href="${urls.hostCatalog}"]`);
|
||||
await click(MANAGE_DROPDOWN_SELECTOR);
|
||||
await click(DELETE_ACTION_SELECTOR);
|
||||
await click(commonSelectors.HREF(urls.hostCatalog));
|
||||
await click(selectors.MANAGE_DROPDOWN_HOST_CATALOG);
|
||||
await click(selectors.MANAGE_DROPDOWN_HOST_CATALOG_DELETE);
|
||||
|
||||
assert.dom(commonSelectors.ALERT_TOAST_BODY).hasText('Oops.');
|
||||
});
|
||||
|
||||
@@ -62,9 +62,10 @@ module('Acceptance | host-catalogs | read', function (hooks) {
|
||||
test('visiting host catalogs', async function (assert) {
|
||||
await visit(urls.hostCatalogs);
|
||||
await a11yAudit();
|
||||
|
||||
assert.strictEqual(currentURL(), urls.hostCatalogs);
|
||||
|
||||
await click(`[href="${urls.hostCatalog}"]`);
|
||||
await click(commonSelectors.HREF(urls.hostCatalog));
|
||||
await a11yAudit();
|
||||
|
||||
assert.strictEqual(currentURL(), urls.hostCatalog);
|
||||
@@ -77,7 +78,7 @@ module('Acceptance | host-catalogs | read', function (hooks) {
|
||||
(item) => item !== 'read',
|
||||
);
|
||||
|
||||
await click(`[href="${urls.hostCatalogs}"]`);
|
||||
await click(commonSelectors.HREF(urls.hostCatalogs));
|
||||
|
||||
assert
|
||||
.dom(commonSelectors.TABLE_RESOURCE_LINK(urls.hostCatalog))
|
||||
@@ -96,11 +97,13 @@ module('Acceptance | host-catalogs | read', function (hooks) {
|
||||
test('users can link to docs page for host catalog', async function (assert) {
|
||||
await visit(urls.projectScope);
|
||||
|
||||
await click(`[href="${urls.hostCatalogs}"]`);
|
||||
await click(commonSelectors.HREF(urls.hostCatalogs));
|
||||
|
||||
assert
|
||||
.dom(
|
||||
`[href="https://developer.hashicorp.com/boundary/docs/concepts/domain-model/host-catalogs"]`,
|
||||
commonSelectors.HREF(
|
||||
'https://developer.hashicorp.com/boundary/docs/concepts/domain-model/host-catalogs',
|
||||
),
|
||||
)
|
||||
.exists();
|
||||
});
|
||||
|
||||
@@ -16,3 +16,17 @@ export const FIELD_PROJECT_VALUE = 'project ID';
|
||||
|
||||
export const FIELD_CLIENT_EMAIL = '[name="client_email"]';
|
||||
export const FIELD_CLIENT_EMAIL_VALUE = 'email';
|
||||
|
||||
export const MANAGE_DROPDOWN_HOST_CATALOG =
|
||||
'[data-test-manage-host-catalogs-dropdown] button:first-child';
|
||||
export const MANAGE_DROPDOWN_HOST_CATALOG_DELETE =
|
||||
'[data-test-manage-host-catalogs-dropdown] ul li button';
|
||||
|
||||
export const FIELD_ROLE_ARN = '[name="role_arn"]';
|
||||
export const FIELD_ROLE_ARN_VALUE = 'arn:aws:iam';
|
||||
|
||||
export const FIELD_CREDENTIAL_TYPE =
|
||||
'.dynamic-credential-selection input:checked';
|
||||
export const FIELD_DYNAMIC_CREDENTIAL = '[name="dynamic-credential"]';
|
||||
export const FIELD_DYNAMIC_CREDENTIAL_VALUE = 'dynamic-credentials';
|
||||
export const FIELD_STATIC_CREDENTIAL = '[name="static-credential"]';
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
import { module, test } from 'qunit';
|
||||
import { visit, currentURL, click, fillIn, find } from '@ember/test-helpers';
|
||||
import { visit, currentURL, click, fillIn } from '@ember/test-helpers';
|
||||
import { setupApplicationTest } from 'admin/tests/helpers';
|
||||
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
|
||||
import { Response } from 'miragejs';
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
TYPE_HOST_CATALOG_PLUGIN_AWS,
|
||||
TYPE_HOST_CATALOG_PLUGIN_GCP,
|
||||
} from 'api/models/host-catalog';
|
||||
import * as selectors from './selectors';
|
||||
|
||||
module('Acceptance | host-catalogs | update', function (hooks) {
|
||||
setupApplicationTest(hooks);
|
||||
@@ -41,13 +42,6 @@ module('Acceptance | host-catalogs | update', function (hooks) {
|
||||
GCPHostCatalog: null,
|
||||
};
|
||||
|
||||
const NAME_INPUT_SELECTOR = '[name="name"]';
|
||||
const EDIT_BUTTON_SELECTOR = '.rose-form-actions [type=button]';
|
||||
const SAVE_BUTTON_SELECTOR = '.rose-form-actions [type="submit"]';
|
||||
const CANCEL_BUTTON_SELECTOR = '.rose-form-actions [type="button"]';
|
||||
const CREDENTIAL_TYPE_SELECTOR =
|
||||
'.dynamic-credential-selection input:checked';
|
||||
|
||||
hooks.beforeEach(async function () {
|
||||
// Generate resources
|
||||
instances.scopes.global = this.server.create('scope', { id: 'global' });
|
||||
@@ -90,33 +84,32 @@ module('Acceptance | host-catalogs | update', function (hooks) {
|
||||
|
||||
test('can update static AWS credentials to Dynamic AWS credentials', async function (assert) {
|
||||
await visit(urls.AWSHostCatalogWithStaticCredential);
|
||||
await click(EDIT_BUTTON_SELECTOR, 'Activate edit mode');
|
||||
await click(commonSelectors.EDIT_BTN);
|
||||
|
||||
assert.strictEqual(
|
||||
find(CREDENTIAL_TYPE_SELECTOR).value,
|
||||
'static-credential',
|
||||
assert.dom(selectors.FIELD_STATIC_CREDENTIAL).isChecked();
|
||||
|
||||
await click(
|
||||
selectors.FIELD_DYNAMIC_CREDENTIAL,
|
||||
selectors.FIELD_DYNAMIC_CREDENTIAL_VALUE,
|
||||
);
|
||||
await click('[value=dynamic-credential]', 'Dynamic Credential');
|
||||
await fillIn('[name=role_arn]', 'arn:aws:iam');
|
||||
await fillIn(selectors.FIELD_ROLE_ARN, selectors.FIELD_ROLE_ARN_VALUE);
|
||||
|
||||
await click(commonSelectors.SAVE_BTN);
|
||||
|
||||
await click(SAVE_BUTTON_SELECTOR);
|
||||
// Check if the host catalog is updated
|
||||
assert.strictEqual(
|
||||
find(CREDENTIAL_TYPE_SELECTOR).value,
|
||||
'dynamic-credential',
|
||||
);
|
||||
assert.dom(selectors.FIELD_DYNAMIC_CREDENTIAL).isChecked();
|
||||
});
|
||||
|
||||
test('can update GCP host catalog', async function (assert) {
|
||||
await visit(urls.GCPHostCatalog);
|
||||
await click(EDIT_BUTTON_SELECTOR, 'Activate edit mode');
|
||||
await fillIn('[name=project_id]', 'project-id');
|
||||
await click(SAVE_BUTTON_SELECTOR);
|
||||
await click(commonSelectors.EDIT_BTN);
|
||||
await fillIn(selectors.FIELD_PROJECT, selectors.FIELD_PROJECT_VALUE);
|
||||
await click(commonSelectors.SAVE_BTN);
|
||||
|
||||
assert.strictEqual(
|
||||
this.server.schema.hostCatalogs.where({ type: 'plugin' }).models[0]
|
||||
.attributes.project_id,
|
||||
'project-id',
|
||||
selectors.FIELD_PROJECT_VALUE,
|
||||
);
|
||||
});
|
||||
|
||||
@@ -124,14 +117,14 @@ module('Acceptance | host-catalogs | update', function (hooks) {
|
||||
assert.notEqual(instances.hostCatalog.name, 'random string');
|
||||
await visit(urls.hostCatalog);
|
||||
|
||||
await click(EDIT_BUTTON_SELECTOR, 'Activate edit mode');
|
||||
await fillIn(NAME_INPUT_SELECTOR, 'random string');
|
||||
await click(SAVE_BUTTON_SELECTOR);
|
||||
await click(commonSelectors.EDIT_BTN);
|
||||
await fillIn(commonSelectors.FIELD_NAME, commonSelectors.FIELD_NAME_VALUE);
|
||||
await click(commonSelectors.SAVE_BTN);
|
||||
|
||||
assert.strictEqual(currentURL(), urls.hostCatalog);
|
||||
assert.strictEqual(
|
||||
this.server.schema.hostCatalogs.all().models[0].name,
|
||||
'random string',
|
||||
commonSelectors.FIELD_NAME_VALUE,
|
||||
);
|
||||
});
|
||||
|
||||
@@ -142,23 +135,28 @@ module('Acceptance | host-catalogs | update', function (hooks) {
|
||||
(item) => item !== 'update',
|
||||
);
|
||||
|
||||
await click(`[href="${urls.hostCatalog}"]`);
|
||||
await click(commonSelectors.HREF(urls.hostCatalog));
|
||||
|
||||
assert.dom(EDIT_BUTTON_SELECTOR).doesNotExist();
|
||||
assert.dom(commonSelectors.EDIT_BTN).doesNotExist();
|
||||
});
|
||||
|
||||
test('clicking cancel in edit mode does not save changes', async function (assert) {
|
||||
await visit(urls.hostCatalog);
|
||||
|
||||
await click(EDIT_BUTTON_SELECTOR, 'Activate edit mode');
|
||||
await fillIn(NAME_INPUT_SELECTOR, 'random string');
|
||||
await click(CANCEL_BUTTON_SELECTOR, 'Click Cancel');
|
||||
await click(commonSelectors.EDIT_BTN);
|
||||
await fillIn(commonSelectors.FIELD_NAME, commonSelectors.FIELD_NAME_VALUE);
|
||||
await click(commonSelectors.CANCEL_BTN);
|
||||
|
||||
assert.notEqual(instances.hostCatalog.name, 'random string');
|
||||
assert.dom(NAME_INPUT_SELECTOR).hasValue(instances.hostCatalog.name);
|
||||
assert.notEqual(
|
||||
instances.hostCatalog.name,
|
||||
commonSelectors.FIELD_NAME_VALUE,
|
||||
);
|
||||
assert.dom(commonSelectors.FIELD_NAME).hasValue(instances.hostCatalog.name);
|
||||
});
|
||||
|
||||
test('saving an existing host catalog with invalid fields displays error messages', async function (assert) {
|
||||
const errorMessage =
|
||||
'Invalid request. Request attempted to make second resource with the same field value that must be unique.';
|
||||
this.server.patch('/host-catalogs/:id', () => {
|
||||
return new Response(
|
||||
400,
|
||||
@@ -166,67 +164,73 @@ module('Acceptance | host-catalogs | update', function (hooks) {
|
||||
{
|
||||
status: 400,
|
||||
code: 'invalid_argument',
|
||||
message: 'The request was invalid.',
|
||||
details: {
|
||||
request_fields: [
|
||||
{
|
||||
name: 'name',
|
||||
description: 'Name is required.',
|
||||
},
|
||||
],
|
||||
},
|
||||
message: errorMessage,
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
await visit(urls.hostCatalog);
|
||||
await click(EDIT_BUTTON_SELECTOR, 'Activate edit mode');
|
||||
await fillIn(NAME_INPUT_SELECTOR, 'random string');
|
||||
await click('[type="submit"]');
|
||||
await click(commonSelectors.EDIT_BTN);
|
||||
await fillIn(commonSelectors.FIELD_NAME, commonSelectors.FIELD_NAME_VALUE);
|
||||
await click(commonSelectors.SAVE_BTN);
|
||||
|
||||
assert
|
||||
.dom(commonSelectors.ALERT_TOAST_BODY)
|
||||
.hasText('The request was invalid.');
|
||||
assert.dom('[data-test-error-message-name]').hasText('Name is required.');
|
||||
assert.dom(commonSelectors.ALERT_TOAST_BODY).hasText(errorMessage);
|
||||
});
|
||||
|
||||
test('can discard unsaved host catalog changes via dialog', async function (assert) {
|
||||
const confirmService = this.owner.lookup('service:confirm');
|
||||
confirmService.enabled = true;
|
||||
assert.notEqual(instances.hostCatalog.name, 'random string');
|
||||
assert.notEqual(
|
||||
instances.hostCatalog.name,
|
||||
commonSelectors.FIELD_NAME_VALUE,
|
||||
);
|
||||
|
||||
await visit(urls.hostCatalog);
|
||||
|
||||
await click(EDIT_BUTTON_SELECTOR, 'Activate edit mode');
|
||||
await fillIn(NAME_INPUT_SELECTOR, 'random string');
|
||||
await click(commonSelectors.EDIT_BTN);
|
||||
await fillIn(commonSelectors.FIELD_NAME, commonSelectors.FIELD_NAME_VALUE);
|
||||
|
||||
assert.strictEqual(currentURL(), urls.hostCatalog);
|
||||
await click(`[href="${urls.hostCatalogs}"]`);
|
||||
|
||||
await click(commonSelectors.HREF(urls.hostCatalogs));
|
||||
|
||||
assert.dom(commonSelectors.MODAL_WARNING).exists();
|
||||
|
||||
await click(commonSelectors.MODAL_WARNING_CONFIRM_BTN, 'Click Discard');
|
||||
|
||||
assert.strictEqual(currentURL(), urls.hostCatalogs);
|
||||
assert.notEqual(
|
||||
this.server.schema.hostCatalogs.first().name,
|
||||
'random string',
|
||||
commonSelectors.FIELD_NAME_VALUE,
|
||||
);
|
||||
});
|
||||
|
||||
test('can click cancel on discard dialog box for unsaved host catalog changes', async function (assert) {
|
||||
const confirmService = this.owner.lookup('service:confirm');
|
||||
confirmService.enabled = true;
|
||||
assert.notEqual(instances.hostCatalog.name, 'random string');
|
||||
|
||||
assert.notEqual(
|
||||
instances.hostCatalog.name,
|
||||
commonSelectors.FIELD_NAME_VALUE,
|
||||
);
|
||||
|
||||
await visit(urls.hostCatalog);
|
||||
|
||||
await click(EDIT_BUTTON_SELECTOR, 'Activate edit mode');
|
||||
await fillIn(NAME_INPUT_SELECTOR, 'random string');
|
||||
await click(commonSelectors.EDIT_BTN);
|
||||
await fillIn(commonSelectors.FIELD_NAME, commonSelectors.FIELD_NAME_VALUE);
|
||||
|
||||
assert.strictEqual(currentURL(), urls.hostCatalog);
|
||||
await click(`[href="${urls.hostCatalogs}"]`);
|
||||
|
||||
await click(commonSelectors.HREF(urls.hostCatalogs));
|
||||
|
||||
assert.dom(commonSelectors.MODAL_WARNING).exists();
|
||||
|
||||
await click(commonSelectors.MODAL_WARNING_CANCEL_BTN, 'Click Cancel');
|
||||
|
||||
assert.strictEqual(currentURL(), urls.hostCatalog);
|
||||
assert.notEqual(
|
||||
this.server.schema.hostCatalogs.all().models[0].name,
|
||||
'random string',
|
||||
commonSelectors.FIELD_NAME_VALUE,
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user