refactor: 💡 acceptance tests for sessions for admin ui (#1404)
✅ Closes: ICU-6623
This commit is contained in:
1 parent
a9f6821a3a
commit
247be9b467
2 files changed
+60
-60
No files matched your search
@@ -83,18 +83,6 @@ module('Acceptance | credential-stores | read', function (hooks) {
|
||||
assert.strictEqual(currentURL(), urls.vaultCredentialStore);
|
||||
});
|
||||
|
||||
test('cannot navigate to credential stores tab without proper authorization', async function (assert) {
|
||||
assert.expect(1);
|
||||
await visit(urls.orgScope);
|
||||
instances.scopes.project.authorized_collection_actions[
|
||||
'credential-stores'
|
||||
] = [];
|
||||
|
||||
await click(`[href="${urls.projectScope}"]`);
|
||||
|
||||
assert.dom(`[href="${urls.credentialStores}"]`).doesNotExist();
|
||||
});
|
||||
|
||||
test('cannot navigate to a static credential store form without proper authorization', async function (assert) {
|
||||
assert.expect(2);
|
||||
await visit(urls.projectScope);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { visit, currentURL, findAll, find, click } from '@ember/test-helpers';
|
||||
import { visit, currentURL, click } from '@ember/test-helpers';
|
||||
import { setupApplicationTest } from 'ember-qunit';
|
||||
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
|
||||
import a11yAudit from 'ember-a11y-testing/test-support/audit';
|
||||
@@ -18,26 +18,18 @@ module('Acceptance | sessions', function (hooks) {
|
||||
scopes: {
|
||||
global: null,
|
||||
org: null,
|
||||
project: null,
|
||||
},
|
||||
sessions: null,
|
||||
orgScope: null,
|
||||
};
|
||||
const urls = {
|
||||
orgScope: null,
|
||||
projectScope: null,
|
||||
sessions: null,
|
||||
};
|
||||
|
||||
hooks.beforeEach(function () {
|
||||
authenticateSession({});
|
||||
instances.scopes.global = this.server.create('scope', { id: 'global' });
|
||||
instances.orgScope = this.server.create(
|
||||
'scope',
|
||||
{
|
||||
type: 'org',
|
||||
scope: { id: 'global', type: 'global' },
|
||||
},
|
||||
'withChildren'
|
||||
);
|
||||
instances.scopes.org = this.server.create('scope', {
|
||||
type: 'org',
|
||||
scope: { id: 'global', type: 'global' },
|
||||
@@ -52,12 +44,6 @@ module('Acceptance | sessions', function (hooks) {
|
||||
{ scope: instances.scopes.org },
|
||||
'withMembers'
|
||||
);
|
||||
this.server.createList(
|
||||
'host-catalog',
|
||||
1,
|
||||
{ scope: instances.scopes.project },
|
||||
'withChildren'
|
||||
);
|
||||
this.server.createList(
|
||||
'target',
|
||||
1,
|
||||
@@ -73,74 +59,100 @@ module('Acceptance | sessions', function (hooks) {
|
||||
},
|
||||
'withAssociations'
|
||||
);
|
||||
urls.orgScope = `/scopes/${instances.scopes.project.id}`;
|
||||
urls.sessions = `/scopes/${instances.scopes.project.id}/sessions`;
|
||||
urls.orgScope = `/scopes/${instances.scopes.org.id}/scopes`;
|
||||
urls.projectScope = `/scopes/${instances.scopes.project.id}`;
|
||||
urls.sessions = `${urls.projectScope}/sessions`;
|
||||
|
||||
authenticateSession({});
|
||||
});
|
||||
|
||||
test('visiting sessions', async function (assert) {
|
||||
assert.expect(2);
|
||||
authenticateSession({});
|
||||
await visit(urls.sessions);
|
||||
await visit(urls.projectScope);
|
||||
await a11yAudit();
|
||||
|
||||
await click(`[href="${urls.sessions}"]`);
|
||||
await a11yAudit();
|
||||
|
||||
assert.strictEqual(currentURL(), urls.sessions);
|
||||
assert.strictEqual(findAll('tbody tr').length, instances.sessions.length);
|
||||
assert.dom('tbody tr').exists({ count: instances.sessions.length });
|
||||
});
|
||||
|
||||
test('Users cannot navigate to sessions without proper authorization', async function (assert) {
|
||||
test('users cannot navigate to sessions tab without proper authorization', async function (assert) {
|
||||
assert.expect(2);
|
||||
instances.scopes.project.authorized_collection_actions.sessions = [];
|
||||
authenticateSession({});
|
||||
await visit(urls.orgScope);
|
||||
assert.notOk(
|
||||
await a11yAudit();
|
||||
instances.scopes.project.authorized_collection_actions.sessions =
|
||||
instances.scopes.project.authorized_collection_actions.sessions.filter(
|
||||
(item) => item !== 'list'
|
||||
);
|
||||
|
||||
await click(`[href="${urls.projectScope}"]`);
|
||||
|
||||
assert.false(
|
||||
instances.scopes.project.authorized_collection_actions.sessions.includes(
|
||||
'list'
|
||||
)
|
||||
);
|
||||
assert.notOk(find(`[href="${urls.sessions}"]`));
|
||||
assert.dom(`[href="${urls.sessions}"]`).doesNotExist();
|
||||
});
|
||||
|
||||
test('Users can navigate to sessions with proper authorization', async function (assert) {
|
||||
test('users can navigate to sessions with proper authorization', async function (assert) {
|
||||
assert.expect(2);
|
||||
instances.scopes.project.authorized_collection_actions.sessions = ['list'];
|
||||
authenticateSession({});
|
||||
await visit(urls.orgScope);
|
||||
assert.ok(
|
||||
|
||||
await click(`[href="${urls.projectScope}"]`);
|
||||
|
||||
assert.true(
|
||||
instances.scopes.project.authorized_collection_actions.sessions.includes(
|
||||
'list'
|
||||
)
|
||||
);
|
||||
assert.ok(find(`[href="${urls.sessions}"]`));
|
||||
assert.dom(`[href="${urls.sessions}"]`).exists();
|
||||
});
|
||||
|
||||
test('visiting sessions without users or targets is OK', async function (assert) {
|
||||
assert.expect(2);
|
||||
assert.expect(1);
|
||||
await visit(urls.projectScope);
|
||||
instances.sessions[0].update({
|
||||
userId: null,
|
||||
targetId: null,
|
||||
});
|
||||
authenticateSession({});
|
||||
await visit(urls.sessions);
|
||||
await a11yAudit();
|
||||
assert.strictEqual(currentURL(), urls.sessions);
|
||||
assert.strictEqual(findAll('tbody tr').length, instances.sessions.length);
|
||||
|
||||
await click(`[href="${urls.sessions}"]`);
|
||||
|
||||
assert.dom('tbody tr').exists({ count: instances.sessions.length });
|
||||
});
|
||||
|
||||
test('cancelling a session', async function (assert) {
|
||||
assert.expect(2);
|
||||
authenticateSession({});
|
||||
await visit(urls.sessions);
|
||||
assert.strictEqual(currentURL(), urls.sessions);
|
||||
assert.expect(1);
|
||||
await visit(urls.projectScope);
|
||||
|
||||
await click(`[href="${urls.sessions}"]`);
|
||||
await click('tbody tr:first-child td:last-child button');
|
||||
assert.ok(find('[role="alert"].is-success'));
|
||||
|
||||
assert.dom('[role="alert"] .rose-notification-header').hasText('Success');
|
||||
});
|
||||
|
||||
test('cancelling a session with error shows notification', async function (assert) {
|
||||
assert.expect(2);
|
||||
assert.expect(1);
|
||||
await visit(urls.projectScope);
|
||||
this.server.post('/sessions/:id_method', () => new Response(400));
|
||||
authenticateSession({});
|
||||
await visit(urls.sessions);
|
||||
assert.strictEqual(currentURL(), urls.sessions);
|
||||
|
||||
await click(`[href="${urls.sessions}"]`);
|
||||
await click('tbody tr:first-child td:last-child button');
|
||||
assert.ok(find('[role="alert"].is-error'));
|
||||
|
||||
assert.dom('[role="alert"] .rose-notification-header').hasText('Error');
|
||||
});
|
||||
|
||||
test('users can link to docs page for sessions', async function (assert) {
|
||||
assert.expect(1);
|
||||
await visit(urls.projectScope);
|
||||
|
||||
await click(`[href="${urls.sessions}"]`);
|
||||
|
||||
assert
|
||||
.dom(`[href="https://boundaryproject.io/help/admin-ui/sessions"]`)
|
||||
.exists();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user