refactor: 💡 host-catalogs read acceptance test (#1400)

* refactor: 💡 host-catalogs read acceptance test

✅ Closes: ICU-6544

Co-authored-by: Zhihe Li <zhihe.li@hashicorp.com>
Co-authored-by: Cameron Perera <cameron.perera@hashicorp.com>
This commit is contained in:
authored and GitHub committed 2022-11-02 09:27:01 -07:00
1 parent 1111cbd6a2
commit 4b231f64f3
1 file changed
+29 -8
@@ -1,5 +1,5 @@
import { module, test } from 'qunit';
import { visit, currentURL, find } 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';
@@ -20,6 +20,8 @@ module('Acceptance | host-catalogs | read', function (hooks) {
org: null,
project: null,
},
hostCatalogs: null,
hostCatalog: null,
};
const urls = {
globalScope: null,
@@ -27,7 +29,6 @@ module('Acceptance | host-catalogs | read', function (hooks) {
projectScope: null,
hostCatalogs: null,
hostCatalog: null,
newHostCatalog: null,
};
hooks.beforeEach(function () {
@@ -51,7 +52,7 @@ module('Acceptance | host-catalogs | read', function (hooks) {
urls.hostCatalogs = `${urls.projectScope}/host-catalogs`;
urls.hostCatalog = `${urls.hostCatalogs}/${instances.hostCatalog.id}`;
urls.unknownHostCatalog = `${urls.hostCatalogs}/foo`;
urls.newHostCatalog = `${urls.hostCatalogs}/new`;
authenticateSession({});
});
@@ -60,25 +61,45 @@ module('Acceptance | host-catalogs | read', function (hooks) {
await visit(urls.hostCatalogs);
await a11yAudit();
assert.strictEqual(currentURL(), urls.hostCatalogs);
await visit(urls.hostCatalog);
await click(`[href="${urls.hostCatalog}"]`);
await a11yAudit();
assert.strictEqual(currentURL(), urls.hostCatalog);
});
test('cannot navigate to a host catalog form without proper authorization', async function (assert) {
assert.expect(1);
await visit(urls.projectScope);
instances.hostCatalog.authorized_actions =
instances.hostCatalog.authorized_actions.filter(
(item) => item !== 'read'
);
await visit(urls.hostCatalog);
assert.notOk(find('main tbody .rose-table-header-cell:nth-child(1) a'));
await click(`[href="${urls.hostCatalogs}"]`);
assert.dom(`[href="${urls.hostCatalog}"]`).doesNotExist();
});
test('visiting an unknown host catalog displays 404 message', async function (assert) {
assert.expect(1);
assert.expect(2);
await visit(urls.hostCatalogs);
assert.dom(`[href="${urls.unknownHostCatalog}"]`).doesNotExist();
await visit(urls.unknownHostCatalog);
await a11yAudit();
assert.ok(find('.rose-message-subtitle').textContent.trim(), 'Error 404');
assert.dom('.rose-message-subtitle').hasText('Error 404');
});
test('users can link to docs page for host catalog', async function (assert) {
assert.expect(1);
await visit(urls.projectScope);
await click(`[href="${urls.hostCatalogs}"]`);
assert
.dom(`[href="https://boundaryproject.io/help/admin-ui/host-catalogs"]`)
.exists();
});
});