From 94c302739202f20dbc98a81cc8b8df3b2fec4013 Mon Sep 17 00:00:00 2001 From: lisbet-alvarez <107949262+lisbet-alvarez@users.noreply.github.com> Date: Wed, 8 Mar 2023 08:42:20 -0800 Subject: [PATCH] =?UTF-8?q?test:=20=F0=9F=92=8D=20acceptance=20tests=20for?= =?UTF-8?q?=20navigation=20link=20(#102)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * test: 💍 acceptance tests for navigation link ✅ Closes: ICU-8224 --- ui/admin/app/templates/scopes/scope.hbs | 16 +- .../acceptance/storage-buckets/list-test.js | 139 ++++++++++++++++++ .../acceptance/storage-buckets/read-test.js | 57 +++++++ 3 files changed, 205 insertions(+), 7 deletions(-) create mode 100644 ui/admin/tests/acceptance/storage-buckets/list-test.js create mode 100644 ui/admin/tests/acceptance/storage-buckets/read-test.js diff --git a/ui/admin/app/templates/scopes/scope.hbs b/ui/admin/app/templates/scopes/scope.hbs index 7d9a2836d..22be84374 100644 --- a/ui/admin/app/templates/scopes/scope.hbs +++ b/ui/admin/app/templates/scopes/scope.hbs @@ -32,13 +32,15 @@ {{t 'resources.session-recording.title_plural'}} - - - {{t 'resources.storage-bucket.title_plural'}} - + {{#if (can 'navigate model' @model collection='storage-buckets')}} + + + {{t 'resources.storage-bucket.title_plural'}} + + {{/if}} {{/if}} {{#if (and diff --git a/ui/admin/tests/acceptance/storage-buckets/list-test.js b/ui/admin/tests/acceptance/storage-buckets/list-test.js new file mode 100644 index 000000000..3821a4631 --- /dev/null +++ b/ui/admin/tests/acceptance/storage-buckets/list-test.js @@ -0,0 +1,139 @@ +/** + * Copyright (c) HashiCorp, Inc. + * SPDX-License-Identifier: MPL-2.0 + */ + +import { module, test } from 'qunit'; +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'; + +module('Acceptance | storage-buckets | list', function (hooks) { + setupApplicationTest(hooks); + setupMirage(hooks); + + let features; + const STORAGE_BUCKET_LINK = 'Storage Buckets'; + + const instances = { + scopes: { + global: null, + org: null, + }, + }; + + const urls = { + globalScope: null, + storageBuckets: null, + }; + + hooks.beforeEach(function () { + instances.scopes.global = this.server.create('scope', { id: 'global' }); + instances.scopes.org = this.server.create('scope', { + type: 'org', + scope: { id: 'global', type: 'global' }, + }); + urls.globalScope = `/scopes/global`; + urls.storageBuckets = `${urls.globalScope}/storage-buckets`; + + features = this.owner.lookup('service:features'); + features.enable('session-recording'); + authenticateSession({}); + }); + + test('users can navigate to storage-buckets with proper authorization', async function (assert) { + assert.expect(3); + + await visit(urls.globalScope); + + assert.true( + instances.scopes.global.authorized_collection_actions[ + 'storage-buckets' + ].includes('list') + ); + assert.true( + instances.scopes.global.authorized_collection_actions[ + 'storage-buckets' + ].includes('create') + ); + assert.dom(`[href="${urls.storageBuckets}"]`).exists(); + }); + + test('user cannot navigate to index without either list or create actions', async function (assert) { + assert.expect(3); + instances.scopes.global.authorized_collection_actions['storage-buckets'] = + []; + + await visit(urls.globalScope); + + assert.false( + instances.scopes.global.authorized_collection_actions[ + 'storage-buckets' + ].includes('list') + ); + assert.false( + instances.scopes.global.authorized_collection_actions[ + 'storage-buckets' + ].includes('create') + ); + assert + .dom('[title="General"] a:nth-of-type(3)') + .doesNotIncludeText(STORAGE_BUCKET_LINK); + }); + + test('user can navigate to index with only create action', async function (assert) { + assert.expect(3); + instances.scopes.global.authorized_collection_actions['storage-buckets'] = + instances.scopes.global.authorized_collection_actions[ + 'storage-buckets' + ].filter((item) => item !== 'list'); + + await visit(urls.globalScope); + + assert.false( + instances.scopes.global.authorized_collection_actions[ + 'storage-buckets' + ].includes('list') + ); + assert.true( + instances.scopes.global.authorized_collection_actions[ + 'storage-buckets' + ].includes('create') + ); + assert.dom(`[href="${urls.storageBuckets}"]`).exists(); + }); + + test('user can navigate to index with only list action', async function (assert) { + assert.expect(3); + instances.scopes.global.authorized_collection_actions['storage-buckets'] = + instances.scopes.global.authorized_collection_actions[ + 'storage-buckets' + ].filter((item) => item !== 'create'); + + await visit(urls.globalScope); + + assert.true( + instances.scopes.global.authorized_collection_actions[ + 'storage-buckets' + ].includes('list') + ); + assert.false( + instances.scopes.global.authorized_collection_actions[ + 'storage-buckets' + ].includes('create') + ); + assert.dom(`[href="${urls.storageBuckets}"]`).exists(); + }); + + test('user cannot navigate to index when feature is disabled', async function (assert) { + assert.expect(1); + features.disable('session-recording'); + + await visit(urls.globalScope); + + assert + .dom('[title="General"] a:nth-of-type(2)') + .doesNotIncludeText(STORAGE_BUCKET_LINK); + }); +}); diff --git a/ui/admin/tests/acceptance/storage-buckets/read-test.js b/ui/admin/tests/acceptance/storage-buckets/read-test.js new file mode 100644 index 000000000..e734e79f7 --- /dev/null +++ b/ui/admin/tests/acceptance/storage-buckets/read-test.js @@ -0,0 +1,57 @@ +/** + * Copyright (c) HashiCorp, Inc. + * SPDX-License-Identifier: MPL-2.0 + */ + +import { module, test } from 'qunit'; +import { visit, currentURL, click } from '@ember/test-helpers'; +import { setupApplicationTest } from 'admin/tests/helpers'; +import setupMirage from 'ember-cli-mirage/test-support/setup-mirage'; +import a11yAudit from 'ember-a11y-testing/test-support/audit'; +import { authenticateSession } from 'ember-simple-auth/test-support'; + +module('Acceptance | storage-buckets | read', function (hooks) { + setupApplicationTest(hooks); + setupMirage(hooks); + + let features; + + const instances = { + scopes: { + global: null, + org: null, + }, + }; + + const urls = { + globalScope: null, + storageBuckets: null, + }; + + hooks.beforeEach(function () { + instances.scopes.global = this.server.create('scope', { id: 'global' }); + instances.scopes.org = this.server.create('scope', { + type: 'org', + scope: { id: 'global', type: 'global' }, + }); + instances.storageBucket = this.server.create('storage-bucket', { + scope: instances.scopes.global, + }); + urls.globalScope = `/scopes/global`; + urls.storageBuckets = `${urls.globalScope}/storage-buckets`; + + features = this.owner.lookup('service:features'); + features.enable('session-recording'); + authenticateSession({}); + }); + + test('visiting storage buckets', async function (assert) { + assert.expect(1); + await visit(urls.globalScope); + await a11yAudit(); + + await click(`[href="${urls.storageBuckets}"]`); + + assert.strictEqual(currentURL(), urls.storageBuckets); + }); +});