refactor: 💡 remove route-action usage for storage-policies (#2286)
* refactor: 💡 remove route-action usage for storage-policies ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12607
This commit is contained in:
1 parent
91fe148df4
commit
9ca1beaa0e
19 files changed
+430
-115
No files matched your search
@@ -0,0 +1,79 @@
|
||||
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/add-storage-policy/create',
|
||||
function (hooks) {
|
||||
setupTest(hooks);
|
||||
setupMirage(hooks);
|
||||
|
||||
let store;
|
||||
let controller;
|
||||
|
||||
const instances = {
|
||||
scopes: {
|
||||
global: null,
|
||||
},
|
||||
policy: null,
|
||||
};
|
||||
|
||||
const urls = {
|
||||
globalScope: null,
|
||||
addStoragePolicy: null,
|
||||
};
|
||||
|
||||
hooks.beforeEach(async function () {
|
||||
authenticateSession({});
|
||||
store = this.owner.lookup('service:store');
|
||||
controller = this.owner.lookup(
|
||||
'controller:scopes/scope/add-storage-policy/create',
|
||||
);
|
||||
|
||||
instances.scopes.global = this.server.create('scope', { id: 'global' });
|
||||
instances.policy = this.server.create('policy', {
|
||||
scopeId: 'global',
|
||||
});
|
||||
|
||||
urls.globalScope = `/scopes/global`;
|
||||
urls.addStoragePolicy = `${urls.globalScope}/add-storage-policy`;
|
||||
});
|
||||
|
||||
test('it exists', function (assert) {
|
||||
assert.ok(controller);
|
||||
});
|
||||
|
||||
test('cancel action rolls-back changes on the specified model', async function (assert) {
|
||||
await visit(urls.addStoragePolicy);
|
||||
const policyBefore = await store.findRecord(
|
||||
'policy',
|
||||
instances.policy.id,
|
||||
);
|
||||
policyBefore.name = 'test';
|
||||
|
||||
assert.strictEqual(policyBefore.name, 'test');
|
||||
|
||||
await controller.cancel(policyBefore);
|
||||
const policyAfter = await store.findRecord('policy', instances.policy.id);
|
||||
|
||||
assert.notEqual(policyAfter.name, 'test');
|
||||
assert.deepEqual(policyBefore, policyAfter);
|
||||
});
|
||||
|
||||
test('save action saves changes on the specified model', async function (assert) {
|
||||
await visit(urls.addStoragePolicy);
|
||||
const policyBefore = await store.findRecord(
|
||||
'policy',
|
||||
instances.policy.id,
|
||||
);
|
||||
policyBefore.name = 'test';
|
||||
|
||||
await controller.save(policyBefore);
|
||||
const policyAfter = await store.findRecord('policy', instances.policy.id);
|
||||
|
||||
assert.strictEqual(policyAfter.name, 'test');
|
||||
});
|
||||
},
|
||||
);
|
||||
@@ -0,0 +1,85 @@
|
||||
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/add-storage-policy/index',
|
||||
function (hooks) {
|
||||
setupTest(hooks);
|
||||
setupMirage(hooks);
|
||||
|
||||
let store;
|
||||
let controller;
|
||||
|
||||
const instances = {
|
||||
scopes: {
|
||||
global: null,
|
||||
},
|
||||
policy: null,
|
||||
};
|
||||
|
||||
const urls = {
|
||||
globalScope: null,
|
||||
addStoragePolicy: null,
|
||||
};
|
||||
|
||||
hooks.beforeEach(async function () {
|
||||
authenticateSession({});
|
||||
store = this.owner.lookup('service:store');
|
||||
controller = this.owner.lookup(
|
||||
'controller:scopes/scope/add-storage-policy/index',
|
||||
);
|
||||
|
||||
instances.scopes.global = this.server.create('scope', { id: 'global' });
|
||||
instances.policy = this.server.create('policy', {
|
||||
scopeId: 'global',
|
||||
});
|
||||
|
||||
urls.globalScope = `/scopes/global`;
|
||||
urls.addStoragePolicy = `${urls.globalScope}/add-storage-policy`;
|
||||
});
|
||||
|
||||
test('it exists', function (assert) {
|
||||
assert.ok(controller);
|
||||
});
|
||||
|
||||
test('cancel action rolls-back changes on the specified model', async function (assert) {
|
||||
await visit(urls.addStoragePolicy);
|
||||
const scopeBefore = await store.findRecord(
|
||||
'scope',
|
||||
instances.scopes.global.id,
|
||||
);
|
||||
scopeBefore.storage_policy_id = instances.policy.id;
|
||||
|
||||
assert.strictEqual(scopeBefore.storage_policy_id, instances.policy.id);
|
||||
|
||||
await controller.cancel(scopeBefore);
|
||||
const scopeAfter = await store.findRecord(
|
||||
'scope',
|
||||
instances.scopes.global.id,
|
||||
);
|
||||
|
||||
assert.notOk(scopeAfter.storage_policy_id);
|
||||
assert.deepEqual(scopeBefore, scopeAfter);
|
||||
});
|
||||
|
||||
test('attachStoragePolicy action saves changes on the specified model', async function (assert) {
|
||||
await visit(urls.addStoragePolicy);
|
||||
const scopeBefore = await store.findRecord(
|
||||
'scope',
|
||||
instances.scopes.global.id,
|
||||
);
|
||||
scopeBefore.storage_policy_id = instances.policy.id;
|
||||
|
||||
await controller.attachStoragePolicy(scopeBefore);
|
||||
const scopeAfter = await store.findRecord(
|
||||
'scope',
|
||||
instances.scopes.global.id,
|
||||
);
|
||||
|
||||
assert.strictEqual(scopeAfter.storage_policy_id, instances.policy.id);
|
||||
});
|
||||
},
|
||||
);
|
||||
@@ -0,0 +1,83 @@
|
||||
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 { setupIndexedDb } from 'api/test-support/helpers/indexed-db';
|
||||
import { authenticateSession } from 'ember-simple-auth/test-support';
|
||||
|
||||
module('Unit | Controller | scopes/scope/policies/index', function (hooks) {
|
||||
setupTest(hooks);
|
||||
setupMirage(hooks);
|
||||
setupIndexedDb(hooks);
|
||||
|
||||
let store;
|
||||
let controller;
|
||||
let getPolicyCount;
|
||||
|
||||
const instances = {
|
||||
scopes: {
|
||||
global: null,
|
||||
},
|
||||
policy: null,
|
||||
};
|
||||
|
||||
const urls = {
|
||||
globalScope: null,
|
||||
policies: null,
|
||||
};
|
||||
|
||||
hooks.beforeEach(async function () {
|
||||
authenticateSession({});
|
||||
store = this.owner.lookup('service:store');
|
||||
controller = this.owner.lookup('controller:scopes/scope/policies/index');
|
||||
|
||||
instances.scopes.global = this.server.create('scope', { id: 'global' });
|
||||
instances.policy = this.server.create('policy', {
|
||||
scopeId: 'global',
|
||||
});
|
||||
|
||||
urls.globalScope = `/scopes/global`;
|
||||
urls.policies = `${urls.globalScope}/policies`;
|
||||
|
||||
getPolicyCount = () => this.server.schema.policies.all().models.length;
|
||||
});
|
||||
|
||||
test('it exists', function (assert) {
|
||||
assert.ok(controller);
|
||||
});
|
||||
|
||||
test('cancel action rolls-back changes on the specified model', async function (assert) {
|
||||
await visit(urls.policies);
|
||||
const policyBefore = await store.findRecord('policy', instances.policy.id);
|
||||
policyBefore.name = 'test';
|
||||
|
||||
assert.strictEqual(policyBefore.name, 'test');
|
||||
|
||||
await controller.cancel(policyBefore);
|
||||
const policyAfter = await store.findRecord('policy', instances.policy.id);
|
||||
|
||||
assert.notEqual(policyAfter.name, 'test');
|
||||
assert.deepEqual(policyBefore, policyAfter);
|
||||
});
|
||||
|
||||
test('save action saves changes on the specified model', async function (assert) {
|
||||
await visit(urls.policies);
|
||||
const policyBefore = await store.findRecord('policy', instances.policy.id);
|
||||
policyBefore.name = 'test';
|
||||
|
||||
await controller.save(policyBefore);
|
||||
const policyAfter = await store.findRecord('policy', instances.policy.id);
|
||||
|
||||
assert.strictEqual(policyAfter.name, 'test');
|
||||
});
|
||||
|
||||
test('delete action destroys specified model', async function (assert) {
|
||||
await visit(urls.globalScope);
|
||||
const policy = await store.findRecord('policy', instances.policy.id);
|
||||
const policyCount = getPolicyCount();
|
||||
|
||||
await controller.delete(policy);
|
||||
|
||||
assert.strictEqual(getPolicyCount(), policyCount - 1);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,11 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
|
||||
module('Unit | Controller | scopes/scope/policies/new', function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
test('it exists', function (assert) {
|
||||
let controller = this.owner.lookup('controller:scopes/scope/policies/new');
|
||||
assert.ok(controller);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,16 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
|
||||
module(
|
||||
'Unit | Controller | scopes/scope/policies/policy/index',
|
||||
function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
test('it exists', function (assert) {
|
||||
let controller = this.owner.lookup(
|
||||
'controller:scopes/scope/policies/policy/index',
|
||||
);
|
||||
assert.ok(controller);
|
||||
});
|
||||
},
|
||||
);
|
||||
Reference in new issue
Block a user