Files
threshold-ui/ui/admin/tests/acceptance/host-catalogs/read-test.js
T
lisbet-alvarezandCameron Perera e8a3650fbe refactor: 💡 adjust css selector for specific asserts (#1468)
* refactor: 💡 adjust css selector for specific asserts

✅ Closes: ICU-6889

* refactor: 💡 small update

* refactor: 💡 selectors for .doesNotExist()

* Update addons/core/tests/integration/helpers/relative-datetime-live-test.js

Co-authored-by: Cameron Perera <cameron.perera@hashicorp.com>
2022-11-28 14:44:34 -08:00

104 lines
3.1 KiB
JavaScript

import { module, test } from 'qunit';
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';
import {
authenticateSession,
// These are left here intentionally for future reference.
//currentSession,
//invalidateSession,
} from 'ember-simple-auth/test-support';
module('Acceptance | host-catalogs | read', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);
const instances = {
scopes: {
global: null,
org: null,
project: null,
},
hostCatalogs: null,
hostCatalog: null,
};
const urls = {
globalScope: null,
orgScope: null,
projectScope: null,
hostCatalogs: null,
hostCatalog: null,
};
hooks.beforeEach(function () {
// Generate resources
instances.scopes.global = this.server.create('scope', { id: 'global' });
instances.scopes.org = this.server.create('scope', {
type: 'org',
scope: { id: 'global', type: 'global' },
});
instances.scopes.project = this.server.create('scope', {
type: 'project',
scope: { id: instances.scopes.org.id, type: 'org' },
});
instances.hostCatalog = this.server.create('host-catalog', {
scope: instances.scopes.project,
});
// 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.hostCatalogs = `${urls.projectScope}/host-catalogs`;
urls.hostCatalog = `${urls.hostCatalogs}/${instances.hostCatalog.id}`;
urls.unknownHostCatalog = `${urls.hostCatalogs}/foo`;
authenticateSession({});
});
test('visiting host catalogs', async function (assert) {
assert.expect(2);
await visit(urls.hostCatalogs);
await a11yAudit();
assert.strictEqual(currentURL(), urls.hostCatalogs);
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 click(`[href="${urls.hostCatalogs}"]`);
assert.dom('.rose-table-body tr:first-child a').doesNotExist();
});
test('visiting an unknown host catalog displays 404 message', async function (assert) {
assert.expect(1);
await visit(urls.unknownHostCatalog);
await a11yAudit();
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();
});
});