refactor: 💡 remove route-action usage for users (#2299)
* refactor: 💡 remove route-action usage for users ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12612
This commit is contained in:
1 parent
2f6e36c035
commit
ea460c1391
18 files changed
+323
-116
No files matched your search
@@ -5,18 +5,57 @@
|
||||
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
import { waitUntil } from '@ember/test-helpers';
|
||||
import { waitUntil, visit } from '@ember/test-helpers';
|
||||
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
|
||||
import { setupIndexedDb } from 'api/test-support/helpers/indexed-db';
|
||||
import { authenticateSession } from 'ember-simple-auth/test-support';
|
||||
|
||||
module('Unit | Controller | scopes/scope/users/index', function (hooks) {
|
||||
setupTest(hooks);
|
||||
setupMirage(hooks);
|
||||
setupIndexedDb(hooks);
|
||||
|
||||
let store;
|
||||
let controller;
|
||||
let getUserCount;
|
||||
|
||||
const instances = {
|
||||
scopes: {
|
||||
global: null,
|
||||
},
|
||||
user: null,
|
||||
account: null,
|
||||
};
|
||||
|
||||
const urls = {
|
||||
globalScope: null,
|
||||
users: null,
|
||||
};
|
||||
|
||||
hooks.beforeEach(function () {
|
||||
authenticateSession({});
|
||||
store = this.owner.lookup('service:store');
|
||||
controller = this.owner.lookup('controller:scopes/scope/users/index');
|
||||
|
||||
instances.scopes.global = this.server.create('scope', { id: 'global' });
|
||||
instances.user = this.server.create('user', {
|
||||
scope: instances.scopes.global,
|
||||
});
|
||||
instances.account = this.server.create('account', {
|
||||
scope: instances.scopes.global,
|
||||
});
|
||||
|
||||
urls.globalScope = `/scopes/global`;
|
||||
urls.users = `${urls.globalScope}/users`;
|
||||
|
||||
getUserCount = () => this.server.schema.users.all().models.length;
|
||||
});
|
||||
|
||||
test('it exists', function (assert) {
|
||||
let controller = this.owner.lookup('controller:scopes/scope/users/index');
|
||||
assert.ok(controller);
|
||||
});
|
||||
|
||||
test('handleSearchInput action sets expected values correctly', async function (assert) {
|
||||
let controller = this.owner.lookup('controller:scopes/scope/users/index');
|
||||
const searchValue = 'test';
|
||||
controller.handleSearchInput({ target: { value: searchValue } });
|
||||
await waitUntil(() => controller.search === searchValue);
|
||||
@@ -24,4 +63,46 @@ module('Unit | Controller | scopes/scope/users/index', function (hooks) {
|
||||
assert.strictEqual(controller.page, 1);
|
||||
assert.strictEqual(controller.search, searchValue);
|
||||
});
|
||||
|
||||
test('cancel action rolls-back changes on the specified model', async function (assert) {
|
||||
await visit(urls.users);
|
||||
const user = await store.findRecord('user', instances.user.id);
|
||||
user.name = 'test';
|
||||
|
||||
assert.strictEqual(user.name, 'test');
|
||||
|
||||
await controller.cancel(user);
|
||||
|
||||
assert.notEqual(user.name, 'test');
|
||||
});
|
||||
|
||||
test('save action saves changes on the specified model', async function (assert) {
|
||||
await visit(urls.users);
|
||||
const user = await store.findRecord('user', instances.user.id);
|
||||
user.name = 'test';
|
||||
|
||||
await controller.save(user);
|
||||
|
||||
assert.strictEqual(user.name, 'test');
|
||||
});
|
||||
|
||||
test('delete action destroys specified model', async function (assert) {
|
||||
const user = await store.findRecord('user', instances.user.id);
|
||||
const userCount = getUserCount();
|
||||
|
||||
await controller.delete(user);
|
||||
|
||||
assert.strictEqual(getUserCount(), userCount - 1);
|
||||
});
|
||||
|
||||
test('removeAccount action removes specified account from model', async function (assert) {
|
||||
const user = await store.findRecord('user', instances.user.id);
|
||||
await user.addAccounts([instances.account.id]);
|
||||
|
||||
assert.deepEqual(user.account_ids, [instances.account.id]);
|
||||
|
||||
await controller.removeAccount(user, instances.account);
|
||||
|
||||
assert.deepEqual(user.account_ids, []);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,11 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
|
||||
module('Unit | Controller | scopes/scope/users/new', function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
test('it exists', function (assert) {
|
||||
let controller = this.owner.lookup('controller:scopes/scope/users/new');
|
||||
assert.ok(controller);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,16 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
|
||||
module(
|
||||
'Unit | Controller | scopes/scope/users/user/accounts',
|
||||
function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
test('it exists', function (assert) {
|
||||
let controller = this.owner.lookup(
|
||||
'controller:scopes/scope/users/user/accounts',
|
||||
);
|
||||
assert.ok(controller);
|
||||
});
|
||||
},
|
||||
);
|
||||
@@ -0,0 +1,63 @@
|
||||
import { module, test } from 'qunit';
|
||||
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/users/user/add-accounts',
|
||||
function (hooks) {
|
||||
setupTest(hooks);
|
||||
setupMirage(hooks);
|
||||
|
||||
let store;
|
||||
let controller;
|
||||
|
||||
const instances = {
|
||||
scopes: {
|
||||
global: null,
|
||||
},
|
||||
user: null,
|
||||
account: null,
|
||||
};
|
||||
|
||||
const urls = {
|
||||
globalScope: null,
|
||||
addAccounts: null,
|
||||
};
|
||||
|
||||
hooks.beforeEach(function () {
|
||||
authenticateSession({});
|
||||
store = this.owner.lookup('service:store');
|
||||
controller = this.owner.lookup(
|
||||
'controller:scopes/scope/users/user/add-accounts',
|
||||
);
|
||||
|
||||
instances.scopes.global = this.server.create('scope', { id: 'global' });
|
||||
instances.user = this.server.create('user', {
|
||||
scope: instances.scopes.global,
|
||||
});
|
||||
instances.account = this.server.create('account', {
|
||||
scope: instances.scopes.global,
|
||||
});
|
||||
|
||||
urls.globalScope = `/scopes/global`;
|
||||
urls.addAccounts = `${urls.globalScope}/users/add-accounts`;
|
||||
});
|
||||
|
||||
test('it exists', function (assert) {
|
||||
assert.ok(controller);
|
||||
});
|
||||
|
||||
test('addAccount action adds specified account to model', async function (assert) {
|
||||
await visit(urls.addAccounts);
|
||||
const user = await store.findRecord('user', instances.user.id);
|
||||
|
||||
assert.deepEqual(user.account_ids, []);
|
||||
|
||||
await controller.addAccounts(user, [instances.account.id]);
|
||||
|
||||
assert.deepEqual(user.account_ids, [instances.account.id]);
|
||||
});
|
||||
},
|
||||
);
|
||||
@@ -0,0 +1,13 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
|
||||
module('Unit | Controller | scopes/scope/users/user/index', function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
test('it exists', function (assert) {
|
||||
let controller = this.owner.lookup(
|
||||
'controller:scopes/scope/users/user/index',
|
||||
);
|
||||
assert.ok(controller);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user