[Tree] Add capabilities to child objects for testing
This commit is contained in:
@@ -36,6 +36,31 @@ define([
|
|||||||
testCapabilities,
|
testCapabilities,
|
||||||
treeView;
|
treeView;
|
||||||
|
|
||||||
|
function makeMockDomainObject(id, model, capabilities) {
|
||||||
|
var mockDomainObject = jasmine.createSpyObj(
|
||||||
|
'domainObject-' + id,
|
||||||
|
[
|
||||||
|
'getId',
|
||||||
|
'getModel',
|
||||||
|
'getCapability',
|
||||||
|
'hasCapability',
|
||||||
|
'useCapability'
|
||||||
|
]
|
||||||
|
);
|
||||||
|
mockDomainObject.getId.andReturn(id);
|
||||||
|
mockDomainObject.getModel.andReturn(model);
|
||||||
|
mockDomainObject.hasCapability.andCallFake(function (c) {
|
||||||
|
return !!(capabilities[c]);
|
||||||
|
});
|
||||||
|
mockDomainObject.getCapability.andCallFake(function (c) {
|
||||||
|
return capabilities[c];
|
||||||
|
});
|
||||||
|
mockDomainObject.useCapability.andCallFake(function (c) {
|
||||||
|
return capabilities[c] && capabilities[c].invoke();
|
||||||
|
});
|
||||||
|
return mockDomainObject;
|
||||||
|
}
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
mockGestureService = jasmine.createSpyObj(
|
mockGestureService = jasmine.createSpyObj(
|
||||||
'gestureService',
|
'gestureService',
|
||||||
@@ -46,33 +71,14 @@ define([
|
|||||||
|
|
||||||
mockGestureService.attachGestures.andReturn(mockGestureHandle);
|
mockGestureService.attachGestures.andReturn(mockGestureHandle);
|
||||||
|
|
||||||
mockDomainObject = jasmine.createSpyObj(
|
|
||||||
'domainObject',
|
|
||||||
[
|
|
||||||
'getId',
|
|
||||||
'getModel',
|
|
||||||
'getCapability',
|
|
||||||
'hasCapability',
|
|
||||||
'useCapability'
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
mockMutation = jasmine.createSpyObj('mutation', ['listen']);
|
mockMutation = jasmine.createSpyObj('mutation', ['listen']);
|
||||||
mockUnlisten = jasmine.createSpy('unlisten');
|
mockUnlisten = jasmine.createSpy('unlisten');
|
||||||
mockMutation.listen.andReturn(mockUnlisten);
|
mockMutation.listen.andReturn(mockUnlisten);
|
||||||
|
|
||||||
testCapabilities = { mutation: mockMutation };
|
testCapabilities = { mutation: mockMutation };
|
||||||
|
|
||||||
mockDomainObject.getId.andReturn('parent');
|
mockDomainObject =
|
||||||
mockDomainObject.hasCapability.andCallFake(function (c) {
|
makeMockDomainObject('parent', {}, testCapabilities);
|
||||||
return !!(testCapabilities[c]);
|
|
||||||
});
|
|
||||||
mockDomainObject.getCapability.andCallFake(function (c) {
|
|
||||||
return testCapabilities[c];
|
|
||||||
});
|
|
||||||
mockDomainObject.useCapability.andCallFake(function (c) {
|
|
||||||
return testCapabilities[c] && testCapabilities[c].invoke();
|
|
||||||
});
|
|
||||||
|
|
||||||
treeView = new TreeView(mockGestureService);
|
treeView = new TreeView(mockGestureService);
|
||||||
});
|
});
|
||||||
@@ -94,8 +100,9 @@ define([
|
|||||||
var mockComposition;
|
var mockComposition;
|
||||||
|
|
||||||
function waitForCompositionCallback() {
|
function waitForCompositionCallback() {
|
||||||
var calledBack = false;
|
var calledBack = false,
|
||||||
testCapabilities.composition.invoke().then(function () {
|
n = Math.random();
|
||||||
|
testCapabilities.composition.invoke().then(function (c) {
|
||||||
calledBack = true;
|
calledBack = true;
|
||||||
});
|
});
|
||||||
waitsFor(function () {
|
waitsFor(function () {
|
||||||
@@ -105,34 +112,29 @@ define([
|
|||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
mockComposition = ['a', 'b', 'c'].map(function (id) {
|
mockComposition = ['a', 'b', 'c'].map(function (id) {
|
||||||
var mockChild = jasmine.createSpyObj(
|
var mockContext =
|
||||||
'domainObject-' + id,
|
jasmine.createSpyObj('context', [ 'getPath' ]),
|
||||||
[
|
mockType =
|
||||||
'getId',
|
jasmine.createSpyObj('type', [ 'getGlyph' ]),
|
||||||
'getModel',
|
mockLocation =
|
||||||
'getCapability',
|
jasmine.createSpyObj('location', [ 'isLink' ]),
|
||||||
'hasCapability',
|
mockMutation =
|
||||||
'useCapability'
|
jasmine.createSpyObj('mutation', [ 'listen' ]),
|
||||||
]
|
mockChild = makeMockDomainObject(id, {}, {
|
||||||
),
|
context: mockContext,
|
||||||
mockContext = jasmine.createSpyObj(
|
type: mockType,
|
||||||
'context',
|
mutation: mockMutation,
|
||||||
[ 'getPath' ]
|
location: mockLocation
|
||||||
);
|
});
|
||||||
mockChild.getId.andReturn(id);
|
|
||||||
mockChild.getModel.andReturn({});
|
|
||||||
mockChild.getCapability.andCallFake(function (c) {
|
|
||||||
return c === 'context' && mockContext;
|
|
||||||
});
|
|
||||||
mockContext.getPath
|
mockContext.getPath
|
||||||
.andReturn([mockDomainObject, mockChild]);
|
.andReturn([mockDomainObject, mockChild]);
|
||||||
|
|
||||||
return mockChild;
|
return mockChild;
|
||||||
});
|
});
|
||||||
|
|
||||||
testCapabilities.composition = jasmine.createSpyObj(
|
testCapabilities.composition =
|
||||||
'composition',
|
jasmine.createSpyObj('composition', ['invoke']);
|
||||||
['invoke']
|
|
||||||
);
|
|
||||||
testCapabilities.composition.invoke
|
testCapabilities.composition.invoke
|
||||||
.andReturn(Promise.resolve(mockComposition));
|
.andReturn(Promise.resolve(mockComposition));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user