Files
threshold-ui/ui/admin/tests/acceptance/targets/list-test.js
T

141 lines
4.0 KiB
JavaScript
Raw Normal View History

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
2021-08-31 23:34:32 -07:00
import { module, test } from 'qunit';
import { visit, click } from '@ember/test-helpers';
2021-08-31 23:34:32 -07:00
import { setupApplicationTest } from 'ember-qunit';
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
import {
authenticateSession,
// These are left here intentionally for future reference.
//currentSession,
//invalidateSession,
} from 'ember-simple-auth/test-support';
module('Acceptance | targets | list', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);
const instances = {
scopes: {
global: null,
org: null,
project: null,
2021-08-31 23:34:32 -07:00
},
target: null,
2021-08-31 23:34:32 -07:00
};
const urls = {
orgScope: null,
2021-08-31 23:34:32 -07:00
projectScope: null,
targets: null,
2021-08-31 23:34:32 -07:00
};
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' },
});
2021-08-31 23:34:32 -07:00
instances.scopes.project = this.server.create('scope', {
type: 'project',
scope: { id: instances.scopes.org.id, type: 'org' },
2021-08-31 23:34:32 -07:00
});
instances.target = this.server.create('target', {
scope: instances.scopes.project,
});
urls.orgScope = `/scopes/${instances.scopes.org.id}/scopes`;
2021-08-31 23:34:32 -07:00
urls.projectScope = `/scopes/${instances.scopes.project.id}`;
urls.targets = `${urls.projectScope}/targets`;
authenticateSession({});
});
test('can navigate to targets with proper authorization', async function (assert) {
assert.expect(3);
await visit(urls.orgScope);
await click(`[href="${urls.projectScope}"]`);
assert.true(
2021-08-31 23:34:32 -07:00
instances.scopes.project.authorized_collection_actions.targets.includes(
'list'
)
);
assert.true(
instances.scopes.project.authorized_collection_actions.targets.includes(
'create'
)
);
assert.dom(`[href="${urls.targets}"]`).exists();
2021-08-31 23:34:32 -07:00
});
test('user cannot navigate to index without either list or create actions', async function (assert) {
assert.expect(3);
2021-08-31 23:34:32 -07:00
instances.scopes.project.authorized_collection_actions.targets = [];
await visit(urls.orgScope);
await click(`[href="${urls.projectScope}"]`);
assert.false(
2021-08-31 23:34:32 -07:00
instances.scopes.project.authorized_collection_actions.targets.includes(
'list'
)
);
assert.false(
instances.scopes.project.authorized_collection_actions.targets.includes(
'create'
)
);
assert
.dom('[title="Resources"] a:nth-of-type(2)')
.doesNotIncludeText('Targets');
2021-08-31 23:34:32 -07:00
});
test('user can navigate to index with only create action', async function (assert) {
assert.expect(3);
instances.scopes.project.authorized_collection_actions.targets =
instances.scopes.project.authorized_collection_actions.targets.filter(
(item) => item !== 'list'
);
await visit(urls.orgScope);
await click(`[href="${urls.projectScope}"]`);
assert.true(
instances.scopes.project.authorized_collection_actions.targets.includes(
'create'
)
);
assert.false(
instances.scopes.project.authorized_collection_actions.targets.includes(
'list'
)
);
assert.dom(`[href="${urls.targets}"]`).exists();
});
test('user can navigate to index with only list action', async function (assert) {
assert.expect(3);
instances.scopes.project.authorized_collection_actions.targets =
instances.scopes.project.authorized_collection_actions.targets.filter(
(item) => item !== 'create'
);
await visit(urls.orgScope);
await click(`[href="${urls.projectScope}"]`);
assert.false(
instances.scopes.project.authorized_collection_actions.targets.includes(
'create'
)
);
assert.true(
instances.scopes.project.authorized_collection_actions.targets.includes(
'list'
)
);
assert.dom(`[href="${urls.targets}"]`).exists();
2021-08-31 23:34:32 -07:00
});
});