Files
threshold-ui/ui/admin/tests/acceptance/host-catalogs/host-sets/read-test.js
T
2021-08-18 13:03:28 -07:00

95 lines
3.1 KiB
JavaScript

import { module, test } from 'qunit';
import { visit, currentURL, find } 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 | host sets | read', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);
const instances = {
scopes: {
global: null,
org: null,
project: null,
hostCatalog: null,
host: null,
},
};
const urls = {
globalScope: null,
orgScope: null,
projectScope: null,
hostCatalogs: null,
hostCatalog: null,
hostSets: null,
hostSet: null,
unknownHostSet: null,
newHostSet: 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,
});
instances.hostSet = this.server.create('host-set', {
scope: instances.scopes.project,
hostCatalog: instances.hostCatalog,
});
// 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.hostSets = `${urls.hostCatalog}/host-sets`;
urls.hostSet = `${urls.hostSets}/${instances.hostSet.id}`;
urls.unknownHostSet = `${urls.hostSets}/foo`;
urls.newHostSet = `${urls.hostSets}/new`;
// Generate resource couner
authenticateSession({});
});
test('visiting host sets', async function (assert) {
assert.expect(2);
await visit(urls.hostSets);
await a11yAudit();
assert.equal(currentURL(), urls.hostSets);
await visit(urls.hostSet);
await a11yAudit();
assert.equal(currentURL(), urls.hostSet);
});
test('cannot navigate to a host set form without proper authorization', async function (assert) {
assert.expect(1);
instances.hostSet.authorized_actions =
instances.hostSet.authorized_actions.filter((item) => item !== 'read');
await visit(urls.hostSet);
assert.notOk(find('main tbody .rose-table-header-cell:nth-child(1) a'));
});
test('visiting an unknown host set displays 404 message', async function (assert) {
assert.expect(1);
await visit(urls.unknownHostSet);
await a11yAudit();
assert.ok(find('.rose-message-subtitle').textContent.trim(), 'Error 404');
});
});