From 247be9b467316a82bcb41d44df0e1da6a4f5e0fb Mon Sep 17 00:00:00 2001 From: lisbet-alvarez <107949262+lisbet-alvarez@users.noreply.github.com> Date: Wed, 9 Nov 2022 09:24:36 -0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20acceptance=20tests?= =?UTF-8?q?=20for=20sessions=20for=20admin=20ui=20(#1404)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ✅ Closes: ICU-6623 --- .../acceptance/credential-store/read-test.js | 12 -- ui/admin/tests/acceptance/sessions-test.js | 108 ++++++++++-------- 2 files changed, 60 insertions(+), 60 deletions(-) diff --git a/ui/admin/tests/acceptance/credential-store/read-test.js b/ui/admin/tests/acceptance/credential-store/read-test.js index 8105329a2..bf252adde 100644 --- a/ui/admin/tests/acceptance/credential-store/read-test.js +++ b/ui/admin/tests/acceptance/credential-store/read-test.js @@ -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); diff --git a/ui/admin/tests/acceptance/sessions-test.js b/ui/admin/tests/acceptance/sessions-test.js index 11799cdb8..cc2a8297b 100644 --- a/ui/admin/tests/acceptance/sessions-test.js +++ b/ui/admin/tests/acceptance/sessions-test.js @@ -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(); }); });