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, []);
|
||||
});
|
||||
},
|
||||
);
|
||||
Reference in new issue
Block a user