refactor: 💡 remove route-action usage for workers (#2302)
✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12613
This commit is contained in:
1 parent
ea460c1391
commit
12e0982d4b
11 files changed
+252
-98
No files matched your search
@@ -0,0 +1,77 @@
|
||||
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/workers/index', function (hooks) {
|
||||
setupTest(hooks);
|
||||
setupMirage(hooks);
|
||||
|
||||
let store;
|
||||
let controller;
|
||||
let getWorkerCount;
|
||||
|
||||
const instances = {
|
||||
scopes: {
|
||||
global: null,
|
||||
},
|
||||
worker: null,
|
||||
};
|
||||
|
||||
const urls = {
|
||||
globalScope: null,
|
||||
workers: null,
|
||||
};
|
||||
|
||||
hooks.beforeEach(function () {
|
||||
authenticateSession({});
|
||||
store = this.owner.lookup('service:store');
|
||||
controller = this.owner.lookup('controller:scopes/scope/workers/index');
|
||||
|
||||
instances.scopes.global = this.server.create('scope', { id: 'global' });
|
||||
instances.worker = this.server.create('worker', {
|
||||
scope: instances.scopes.global,
|
||||
});
|
||||
|
||||
urls.globalScope = `/scopes/global`;
|
||||
urls.workers = `${urls.globalScope}/workers`;
|
||||
|
||||
getWorkerCount = () => this.server.schema.workers.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.workers);
|
||||
const worker = await store.findRecord('worker', instances.worker.id);
|
||||
worker.name = 'test';
|
||||
|
||||
assert.strictEqual(worker.name, 'test');
|
||||
|
||||
await controller.cancel(worker);
|
||||
|
||||
assert.notEqual(worker.name, 'test');
|
||||
});
|
||||
|
||||
test('save action saves changes on the specified model', async function (assert) {
|
||||
await visit(urls.workers);
|
||||
const worker = await store.findRecord('worker', instances.worker.id);
|
||||
worker.name = 'test';
|
||||
|
||||
await controller.save(worker);
|
||||
|
||||
assert.strictEqual(worker.name, 'test');
|
||||
});
|
||||
|
||||
test('delete action destroys specified model', async function (assert) {
|
||||
const worker = await store.findRecord('worker', instances.worker.id);
|
||||
const workerCount = getWorkerCount();
|
||||
|
||||
await controller.delete(worker);
|
||||
|
||||
assert.strictEqual(getWorkerCount(), workerCount - 1);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,65 @@
|
||||
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/workers/new', function (hooks) {
|
||||
setupTest(hooks);
|
||||
setupMirage(hooks);
|
||||
|
||||
let store;
|
||||
let controller;
|
||||
|
||||
const instances = {
|
||||
scopes: {
|
||||
global: null,
|
||||
},
|
||||
worker: null,
|
||||
};
|
||||
|
||||
const urls = {
|
||||
globalScope: null,
|
||||
workers: null,
|
||||
};
|
||||
|
||||
hooks.beforeEach(function () {
|
||||
authenticateSession({});
|
||||
store = this.owner.lookup('service:store');
|
||||
controller = this.owner.lookup('controller:scopes/scope/workers/new');
|
||||
|
||||
instances.scopes.global = this.server.create('scope', { id: 'global' });
|
||||
instances.worker = this.server.create('worker', {
|
||||
scope: instances.scopes.global,
|
||||
});
|
||||
|
||||
urls.globalScope = `/scopes/global`;
|
||||
urls.workers = `${urls.globalScope}/workers`;
|
||||
});
|
||||
|
||||
test('it exists', function (assert) {
|
||||
assert.ok(controller);
|
||||
});
|
||||
|
||||
test('cancel action rolls-back changes on a new model', async function (assert) {
|
||||
await visit(urls.workers);
|
||||
const worker = store.createRecord('worker', instances.worker.id);
|
||||
worker.name = 'test';
|
||||
|
||||
assert.strictEqual(worker.name, 'test');
|
||||
|
||||
await controller.cancel(worker);
|
||||
|
||||
assert.notEqual(worker.name, 'test');
|
||||
});
|
||||
|
||||
test('createWorkerLed action saves changes on the specified model', async function (assert) {
|
||||
await visit(urls.workers);
|
||||
const worker = await store.findRecord('worker', instances.worker.id);
|
||||
worker.name = 'test';
|
||||
|
||||
await controller.createWorkerLed(worker);
|
||||
|
||||
assert.strictEqual(worker.name, 'test');
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user