chore: 🤖 add initial scope service
This commit is contained in:
7 files changed
+193
-3
No files matched your search
@@ -0,0 +1,10 @@
|
||||
import Route from '@ember/routing/route';
|
||||
import { inject as service } from '@ember/service';
|
||||
|
||||
export default class ApplicationRoute extends Route {
|
||||
@service scope;
|
||||
|
||||
afterModel() {
|
||||
//console.log(this.scope);
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,3 @@
|
||||
<h2 id="title">Welcome to Ember</h2>
|
||||
|
||||
{{outlet}}
|
||||
{{outlet}}
|
||||
@@ -0,0 +1 @@
|
||||
index
|
||||
@@ -0,0 +1,67 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
import { Scope } from '../../../services/scope';
|
||||
|
||||
module('Unit | Service | scope class', function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
test('it provides a scope class', function (assert) {
|
||||
assert.expect(1);
|
||||
assert.ok(Scope);
|
||||
});
|
||||
|
||||
test('it has initializable org and project members', function (assert) {
|
||||
assert.expect(2);
|
||||
const org = { id: 1 };
|
||||
const project = { id: 2 };
|
||||
const scope = new Scope(org, project);
|
||||
assert.equal(scope.org.id, 1);
|
||||
assert.equal(scope.project.id, 2);
|
||||
});
|
||||
|
||||
test('it has a null project if org is null, even if project was initialized to non-null', function (assert) {
|
||||
assert.expect(2);
|
||||
const org = null;
|
||||
const project = { id: 2 };
|
||||
const scope = new Scope(org, project);
|
||||
assert.notOk(scope.org);
|
||||
assert.notOk(scope.project);
|
||||
});
|
||||
|
||||
test('it serializes to JSON', function (assert) {
|
||||
assert.expect(2);
|
||||
let scope = new Scope({ id: 1 });
|
||||
assert.deepEqual(JSON.parse(scope.toJSON()), {
|
||||
org: { id: 1 },
|
||||
project: null,
|
||||
});
|
||||
scope = new Scope({ id: 1 }, { id: 2 });
|
||||
assert.deepEqual(JSON.parse(scope.toJSON()), {
|
||||
org: { id: 1 },
|
||||
project: { id: 2 },
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
module('Unit | Service | scope', function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
test('it returns nulls when scope is not set', function (assert) {
|
||||
assert.expect(3);
|
||||
const service = this.owner.lookup('service:scope');
|
||||
assert.equal(service.scope, null);
|
||||
assert.equal(service.org, null);
|
||||
assert.equal(service.project, null);
|
||||
});
|
||||
|
||||
test('it aliases org and project to a scope instance', function (assert) {
|
||||
assert.expect(2);
|
||||
const service = this.owner.lookup('service:scope');
|
||||
const org = { id: 1 };
|
||||
const project = { id: 2 };
|
||||
service.org = org;
|
||||
service.project = project;
|
||||
assert.equal(service.org, service.scope.org);
|
||||
assert.equal(service.project, service.scope.project);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user