Files
threshold-ui/ui/admin/tests/acceptance/host-catalogs/read-test.js
T
Carlos Alcaide Corvo b51c8203ee chore: 🤖 Upgrade eslint-plugin-qunit (#2011)
* chore: 🤖 Upgrade eslint-plugin-qunit

* Delete unnecessary assert.expect from tests
2023-12-08 12:56:00 -08:00

121 lines
3.7 KiB
JavaScript

/**
* 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 '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) {
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) {
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) {
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) {
await visit(urls.projectScope);
await click(`[href="${urls.hostCatalogs}"]`);
assert
.dom(`[href="https://boundaryproject.io/help/admin-ui/host-catalogs"]`)
.exists();
});
test('users can navigate to host catalog and incorrect url autocorrects', async function (assert) {
const projectScope = this.server.create('scope', {
type: 'project',
scope: { id: instances.scopes.org.id, type: 'org' },
});
const hostCatalog = this.server.create('host-catalog', {
scope: projectScope,
});
const incorrectUrl = `${urls.hostCatalogs}/${hostCatalog.id}/host-sets`;
const correctUrl = `/scopes/${projectScope.id}/host-catalogs/${hostCatalog.id}/host-sets`;
await visit(incorrectUrl);
assert.notEqual(currentURL(), incorrectUrl);
assert.strictEqual(currentURL(), correctUrl);
});
});