Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: πŸ’ update selectors for credential-library tests #2630

Merged
merged 2 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 24 additions & 26 deletions ui/admin/tests/acceptance/credential-library/delete-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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,
Expand Down Expand Up @@ -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}`;
Expand All @@ -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);
});

Expand All @@ -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) {
Expand All @@ -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);
});
Expand All @@ -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);
});
Expand All @@ -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.');
});
});
23 changes: 11 additions & 12 deletions ui/admin/tests/acceptance/credential-library/list-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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,
Expand All @@ -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();
});
});
5 changes: 5 additions & 0 deletions ui/admin/tests/acceptance/credential-library/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Loading