test: 💍 update selectors for credential-library tests (#2630)
delete and list ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-15468
This commit is contained in:
1 parent
584e62cff3
commit
daed714b98
3 files changed
+40
-38
No files matched your search
@@ -4,23 +4,21 @@
|
||||
*/
|
||||
|
||||
import { module, test } from 'qunit';
|
||||
import { visit, click, find } from '@ember/test-helpers';
|
||||
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';
|
||||
import { Response } from 'miragejs';
|
||||
import { resolve, reject } from 'rsvp';
|
||||
import sinon from 'sinon';
|
||||
import * as selectors from './selectors';
|
||||
import * as commonSelectors from 'admin/tests/helpers/selectors';
|
||||
|
||||
module('Acceptance | credential-libraries | delete', function (hooks) {
|
||||
setupApplicationTest(hooks);
|
||||
setupMirage(hooks);
|
||||
|
||||
let getCredentialLibraryCount;
|
||||
const MANAGE_DROPDOWN_SELECTOR =
|
||||
'[data-test-manage-credential-library-dropdown] button:first-child';
|
||||
const DELETE_ACTION_SELECTOR =
|
||||
'[data-test-manage-credential-library-dropdown] ul li button';
|
||||
|
||||
const instances = {
|
||||
scopes: {
|
||||
@@ -31,9 +29,6 @@ module('Acceptance | credential-libraries | delete', function (hooks) {
|
||||
};
|
||||
|
||||
const urls = {
|
||||
globalScope: null,
|
||||
orgScope: null,
|
||||
projectScope: null,
|
||||
credentialStores: null,
|
||||
credentialStore: null,
|
||||
credentialLibrary: null,
|
||||
@@ -61,10 +56,7 @@ module('Acceptance | credential-libraries | delete', function (hooks) {
|
||||
credentialStore: instances.credentialStore,
|
||||
});
|
||||
// Generate route URLs for resources
|
||||
urls.globalScope = `/scopes/global/scopes`;
|
||||
urls.orgScope = `/scopes/${instances.scopes.org.id}/scopes`;
|
||||
urls.projectScope = `/scopes/${instances.scopes.project.id}`;
|
||||
urls.credentialStores = `${urls.projectScope}/credential-stores`;
|
||||
urls.credentialStores = `/scopes/${instances.scopes.project.id}/credential-stores`;
|
||||
urls.credentialStore = `${urls.credentialStores}/${instances.credentialStore.id}`;
|
||||
urls.credentialLibraries = `${urls.credentialStore}/credential-libraries`;
|
||||
urls.credentialLibrary = `${urls.credentialLibraries}/${instances.credentialLibrary.id}`;
|
||||
@@ -79,8 +71,10 @@ module('Acceptance | credential-libraries | delete', function (hooks) {
|
||||
test('can delete resource', async function (assert) {
|
||||
const count = getCredentialLibraryCount();
|
||||
await visit(urls.credentialLibrary);
|
||||
await click(MANAGE_DROPDOWN_SELECTOR);
|
||||
await click(DELETE_ACTION_SELECTOR);
|
||||
|
||||
await click(selectors.MANAGE_DROPDOWN_CRED_LIB);
|
||||
await click(selectors.MANAGE_DROPDOWN_CRED_LIB_DELETE);
|
||||
|
||||
assert.strictEqual(getCredentialLibraryCount(), count - 1);
|
||||
});
|
||||
|
||||
@@ -89,10 +83,10 @@ module('Acceptance | credential-libraries | delete', function (hooks) {
|
||||
instances.credentialLibrary.authorized_actions.filter(
|
||||
(item) => item !== 'delete',
|
||||
);
|
||||
|
||||
await visit(urls.credentialLibrary);
|
||||
assert.notOk(
|
||||
find('.rose-layout-page-actions .rose-dropdown-button-danger'),
|
||||
);
|
||||
|
||||
assert.dom(selectors.MANAGE_DROPDOWN_CRED_LIB).doesNotExist();
|
||||
});
|
||||
|
||||
test('can accept delete credential library via dialog', async function (assert) {
|
||||
@@ -101,8 +95,10 @@ module('Acceptance | credential-libraries | delete', function (hooks) {
|
||||
confirmService.confirm = sinon.fake.returns(resolve());
|
||||
const count = getCredentialLibraryCount();
|
||||
await visit(urls.credentialLibrary);
|
||||
await click(MANAGE_DROPDOWN_SELECTOR);
|
||||
await click(DELETE_ACTION_SELECTOR);
|
||||
|
||||
await click(selectors.MANAGE_DROPDOWN_CRED_LIB);
|
||||
await click(selectors.MANAGE_DROPDOWN_CRED_LIB_DELETE);
|
||||
|
||||
assert.strictEqual(getCredentialLibraryCount(), count - 1);
|
||||
assert.ok(confirmService.confirm.calledOnce);
|
||||
});
|
||||
@@ -113,8 +109,10 @@ module('Acceptance | credential-libraries | delete', function (hooks) {
|
||||
confirmService.confirm = sinon.fake.returns(reject());
|
||||
const count = getCredentialLibraryCount();
|
||||
await visit(urls.credentialLibrary);
|
||||
await click(MANAGE_DROPDOWN_SELECTOR);
|
||||
await click(DELETE_ACTION_SELECTOR);
|
||||
|
||||
await click(selectors.MANAGE_DROPDOWN_CRED_LIB);
|
||||
await click(selectors.MANAGE_DROPDOWN_CRED_LIB_DELETE);
|
||||
|
||||
assert.strictEqual(getCredentialLibraryCount(), count);
|
||||
assert.ok(confirmService.confirm.calledOnce);
|
||||
});
|
||||
@@ -132,10 +130,10 @@ module('Acceptance | credential-libraries | delete', function (hooks) {
|
||||
);
|
||||
});
|
||||
await visit(urls.credentialLibrary);
|
||||
await click(MANAGE_DROPDOWN_SELECTOR);
|
||||
await click(DELETE_ACTION_SELECTOR);
|
||||
assert
|
||||
.dom('[data-test-toast-notification] .hds-alert__description')
|
||||
.hasText('Oops.');
|
||||
|
||||
await click(selectors.MANAGE_DROPDOWN_CRED_LIB);
|
||||
await click(selectors.MANAGE_DROPDOWN_CRED_LIB_DELETE);
|
||||
|
||||
assert.dom(commonSelectors.ALERT_TOAST_BODY).hasText('Oops.');
|
||||
});
|
||||
});
|
||||
@@ -4,10 +4,11 @@
|
||||
*/
|
||||
|
||||
import { module, test } from 'qunit';
|
||||
import { visit, find } from '@ember/test-helpers';
|
||||
import { visit } 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';
|
||||
import * as commonSelectors from 'admin/tests/helpers/selectors';
|
||||
|
||||
module('Acceptance | credential-libraries | list', function (hooks) {
|
||||
setupApplicationTest(hooks);
|
||||
@@ -22,9 +23,6 @@ module('Acceptance | credential-libraries | list', function (hooks) {
|
||||
};
|
||||
|
||||
const urls = {
|
||||
globalScope: null,
|
||||
orgScope: null,
|
||||
projectScope: null,
|
||||
credentialStores: null,
|
||||
credentialStore: null,
|
||||
credentialLibrary: null,
|
||||
@@ -49,44 +47,45 @@ module('Acceptance | credential-libraries | list', function (hooks) {
|
||||
credentialStore: instances.credentialStore,
|
||||
});
|
||||
// Generate route URLs for resources
|
||||
urls.globalScope = `/scopes/global/scopes`;
|
||||
urls.orgScope = `/scopes/${instances.scopes.org.id}/scopes`;
|
||||
urls.projectScope = `/scopes/${instances.scopes.project.id}`;
|
||||
urls.credentialStores = `${urls.projectScope}/credential-stores`;
|
||||
urls.credentialStores = `/scopes/${instances.scopes.project.id}/credential-stores`;
|
||||
urls.credentialStore = `${urls.credentialStores}/${instances.credentialStore.id}`;
|
||||
urls.credentialLibraries = `${urls.credentialStore}/credential-libraries`;
|
||||
urls.credentialLibrary = `${urls.credentialLibraries}/${instances.credentialLibrary.id}`;
|
||||
await authenticateSession({});
|
||||
});
|
||||
|
||||
test('Users can navigate to credential libraries with proper authorization', async function (assert) {
|
||||
await visit(urls.credentialStore);
|
||||
|
||||
assert.ok(
|
||||
instances.credentialStore.authorized_collection_actions[
|
||||
'credential-libraries'
|
||||
].includes('list'),
|
||||
);
|
||||
assert.ok(find(`[href="${urls.credentialLibraries}"]`));
|
||||
assert.dom(commonSelectors.HREF(urls.credentialLibraries)).isVisible();
|
||||
});
|
||||
|
||||
test('Users cannot navigate to index without either list or create actions', async function (assert) {
|
||||
instances.credentialStore.authorized_collection_actions[
|
||||
'credential-libraries'
|
||||
] = [];
|
||||
|
||||
await visit(urls.credentialStore);
|
||||
|
||||
assert.notOk(
|
||||
instances.credentialStore.authorized_collection_actions[
|
||||
'credential-libraries'
|
||||
].includes('list'),
|
||||
);
|
||||
assert.notOk(find(`[href="${urls.credentialLibraries}"]`));
|
||||
assert.dom(commonSelectors.HREF(urls.credentialLibraries)).doesNotExist();
|
||||
});
|
||||
|
||||
test('Users can navigate to index with only create action', async function (assert) {
|
||||
instances.credentialStore.authorized_collection_actions[
|
||||
'credential-libraries'
|
||||
] = ['create'];
|
||||
|
||||
await visit(urls.credentialStore);
|
||||
assert.ok(find(`[href="${urls.credentialLibraries}"]`));
|
||||
|
||||
assert.dom(commonSelectors.HREF(urls.credentialLibraries)).isVisible();
|
||||
});
|
||||
});
|
||||
@@ -46,3 +46,8 @@ export const FIELD_EXT_KEY =
|
||||
export const FIELD_EXT_VALUE =
|
||||
'[name="extensions"] tbody td:nth-of-type(2) input';
|
||||
export const FIELD_EXT_BTN = '[name="extensions"] button';
|
||||
|
||||
export const MANAGE_DROPDOWN_CRED_LIB =
|
||||
'[data-test-manage-credential-library-dropdown] button:first-child';
|
||||
export const MANAGE_DROPDOWN_CRED_LIB_DELETE =
|
||||
'[data-test-manage-credential-library-dropdown] ul li button';
|
||||
Reference in new issue
Block a user