refactor: 💡 remove route-action usage in admin ui (#2534)
✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12945
This commit is contained in:
1 parent
e842eb001d
commit
01a2d8e9a6
14 files changed
+261
-101
No files matched your search
@@ -4,18 +4,111 @@
|
||||
*/
|
||||
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'admin/tests/helpers';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
import { visit } from '@ember/test-helpers';
|
||||
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
|
||||
import { authenticateSession } from 'ember-simple-auth/test-support';
|
||||
|
||||
module(
|
||||
'Unit | Controller | scopes/scope/groups/group/add-members',
|
||||
function (hooks) {
|
||||
setupTest(hooks);
|
||||
setupMirage(hooks);
|
||||
|
||||
test('it exists', function (assert) {
|
||||
let controller = this.owner.lookup(
|
||||
let store;
|
||||
let controller;
|
||||
|
||||
const instances = {
|
||||
scopes: {
|
||||
global: null,
|
||||
org: null,
|
||||
},
|
||||
group: null,
|
||||
user: null,
|
||||
};
|
||||
|
||||
const urls = {
|
||||
globalScope: null,
|
||||
addMembers: null,
|
||||
};
|
||||
|
||||
hooks.beforeEach(function () {
|
||||
authenticateSession({});
|
||||
store = this.owner.lookup('service:store');
|
||||
controller = this.owner.lookup(
|
||||
'controller:scopes/scope/groups/group/add-members',
|
||||
);
|
||||
|
||||
instances.scopes.global = this.server.create('scope', { id: 'global' });
|
||||
instances.scopes.org = this.server.create('scope', {
|
||||
type: 'org',
|
||||
scope: { id: 'global', type: 'global' },
|
||||
});
|
||||
instances.group = this.server.create('group', {
|
||||
scope: instances.scopes.global,
|
||||
});
|
||||
instances.user = this.server.create('user', {
|
||||
scope: instances.scopes.global,
|
||||
});
|
||||
|
||||
urls.globalScope = `/scopes/global`;
|
||||
urls.addMembers = `${urls.globalScope}/groups/${instances.group.id}/add-members`;
|
||||
});
|
||||
|
||||
test('it exists', function (assert) {
|
||||
assert.ok(controller);
|
||||
});
|
||||
|
||||
test('flatSortedScopes returns array of sorted scopes', async function (assert) {
|
||||
const globalScope = await store.findRecord(
|
||||
'scope',
|
||||
instances.scopes.global.id,
|
||||
);
|
||||
const orgScope = await store.findRecord('scope', instances.scopes.org.id);
|
||||
await visit(urls.addMembers);
|
||||
|
||||
assert.deepEqual(controller.flatSortedScopes, [globalScope, orgScope]);
|
||||
});
|
||||
|
||||
test('addMembers action adds users to specified model', async function (assert) {
|
||||
await visit(urls.addMembers);
|
||||
const group = await store.findRecord('group', instances.group.id);
|
||||
const user = await store.findRecord('user', instances.user.id);
|
||||
|
||||
assert.deepEqual(group.members, []);
|
||||
|
||||
await controller.addMembers(group, [instances.user.id]);
|
||||
|
||||
assert.deepEqual(group.members, [user]);
|
||||
});
|
||||
|
||||
test('callFilterBy action adds expected property values to route', async function (assert) {
|
||||
const route = this.owner.lookup(
|
||||
'route:scopes/scope/groups/group/add-members',
|
||||
);
|
||||
await visit(urls.addMembers);
|
||||
const scope = await store.findRecord('scope', instances.scopes.global.id);
|
||||
|
||||
assert.notOk(route.scope);
|
||||
|
||||
controller.callFilterBy('scope', [scope]);
|
||||
|
||||
assert.deepEqual(route.scope, [scope]);
|
||||
});
|
||||
|
||||
test('callClearAllFilters action removes all filter values from route', async function (assert) {
|
||||
const route = this.owner.lookup(
|
||||
'route:scopes/scope/groups/group/add-members',
|
||||
);
|
||||
await visit(urls.addMembers);
|
||||
const scope = await store.findRecord('scope', instances.scopes.global.id);
|
||||
route.scope = [scope];
|
||||
|
||||
assert.deepEqual(route.scope, [scope]);
|
||||
|
||||
controller.callClearAllFilters();
|
||||
|
||||
assert.deepEqual(route.scope, []);
|
||||
});
|
||||
},
|
||||
);
|
||||
@@ -21,6 +21,8 @@ module(
|
||||
const instances = {
|
||||
scopes: {
|
||||
global: null,
|
||||
org: null,
|
||||
project: null,
|
||||
},
|
||||
role: null,
|
||||
user: null,
|
||||
@@ -39,6 +41,14 @@ module(
|
||||
);
|
||||
|
||||
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.role = this.server.create('role', {
|
||||
scopeId: 'global',
|
||||
});
|
||||
@@ -54,6 +64,25 @@ module(
|
||||
assert.ok(controller);
|
||||
});
|
||||
|
||||
test('flatSortedScopes returns array of sorted scopes', async function (assert) {
|
||||
const globalScope = await store.findRecord(
|
||||
'scope',
|
||||
instances.scopes.global.id,
|
||||
);
|
||||
const orgScope = await store.findRecord('scope', instances.scopes.org.id);
|
||||
const projectScope = await store.findRecord(
|
||||
'scope',
|
||||
instances.scopes.project.id,
|
||||
);
|
||||
await visit(urls.addPrincipals);
|
||||
|
||||
assert.deepEqual(controller.flatSortedScopes, [
|
||||
globalScope,
|
||||
orgScope,
|
||||
projectScope,
|
||||
]);
|
||||
});
|
||||
|
||||
test('addPrincipals action adds principals to specified model', async function (assert) {
|
||||
await visit(urls.addPrincipals);
|
||||
const role = await store.findRecord('role', instances.role.id);
|
||||
@@ -70,5 +99,34 @@ module(
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
test('callFilterBy action adds expected property values to route', async function (assert) {
|
||||
const route = this.owner.lookup(
|
||||
'route:scopes/scope/roles/role/add-principals',
|
||||
);
|
||||
await visit(urls.addPrincipals);
|
||||
const scope = await store.findRecord('scope', instances.scopes.global.id);
|
||||
|
||||
assert.notOk(route.scope);
|
||||
|
||||
controller.callFilterBy('scope', [scope]);
|
||||
|
||||
assert.deepEqual(route.scope, [scope]);
|
||||
});
|
||||
|
||||
test('callClearAllFilters action removes all filter values from route', async function (assert) {
|
||||
const route = this.owner.lookup(
|
||||
'route:scopes/scope/roles/role/add-principals',
|
||||
);
|
||||
await visit(urls.addPrincipals);
|
||||
const scope = await store.findRecord('scope', instances.scopes.global.id);
|
||||
route.scope = [scope];
|
||||
|
||||
assert.deepEqual(route.scope, [scope]);
|
||||
|
||||
controller.callClearAllFilters();
|
||||
|
||||
assert.deepEqual(route.scope, []);
|
||||
});
|
||||
},
|
||||
);
|
||||
@@ -39,6 +39,7 @@ module('Unit | Controller | scopes/scope/workers/index', function (hooks) {
|
||||
instances.scopes.global = this.server.create('scope', { id: 'global' });
|
||||
instances.worker = this.server.create('worker', {
|
||||
scope: instances.scopes.global,
|
||||
config_tags: { type: ['dev'] },
|
||||
});
|
||||
|
||||
urls.globalScope = `/scopes/global`;
|
||||
@@ -81,4 +82,31 @@ module('Unit | Controller | scopes/scope/workers/index', function (hooks) {
|
||||
|
||||
assert.strictEqual(getWorkerCount(), workerCount - 1);
|
||||
});
|
||||
|
||||
test('callFilterBy action adds expected property values to route', async function (assert) {
|
||||
const route = this.owner.lookup('route:scopes/scope/workers/index');
|
||||
await visit(urls.workers);
|
||||
const tag = { key: 'type', value: 'dev', type: 'config' };
|
||||
|
||||
assert.notOk(route.tags);
|
||||
|
||||
controller.callFilterBy('tags', [tag]);
|
||||
|
||||
assert.deepEqual(route.tags, [tag]);
|
||||
});
|
||||
|
||||
test('callClearAllFilters action removes all filter values from route', async function (assert) {
|
||||
const route = this.owner.lookup('route:scopes/scope/workers/index');
|
||||
await visit(urls.workers);
|
||||
const tag = { key: 'type', value: 'dev', type: 'config' };
|
||||
controller.callFilterBy('tags', [tag]);
|
||||
|
||||
assert.deepEqual(route.tags, [
|
||||
{ key: 'type', value: 'dev', type: 'config' },
|
||||
]);
|
||||
|
||||
controller.callClearAllFilters();
|
||||
|
||||
assert.deepEqual(route.tags, []);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user