Update test specs to use Jasmine 3 (#2089)
* Updated Karma and Jasmine versions * Added DOMObserver class. Supports promise-based testing of DOM changes Update asynchronous test specs to use promises or done() instead of waitsFor/runs * Modified ActionCapability to duplicate context object properties as own properties for better object equality comparisons * Global find + replace to fix syntax issues * Fixed various issues caused by non-deterministic runtime order of tests in Jasmine 3. Fixed issues caused by changes to determination of object equality * Addressed review comments * Resolved merge conflicts with master * Fixed style errors * Use spy.calls.count() instead of manually tracking
This commit is contained in:
committed by
Pete Richards
parent
013eba744d
commit
433dee0314
@@ -24,8 +24,8 @@
|
||||
* Module defining ActionCapability. Created by vwoeltje on 11/10/14.
|
||||
*/
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
['lodash'],
|
||||
function (_) {
|
||||
|
||||
/**
|
||||
* The ActionCapability allows applicable Actions to be retrieved and
|
||||
@@ -74,10 +74,14 @@ define(
|
||||
// Get all actions which are valid in this context;
|
||||
// this simply redirects to the action service,
|
||||
// but additionally adds a domainObject field.
|
||||
var baseContext = typeof context === 'string' ?
|
||||
{ key: context } : (context || {}),
|
||||
actionContext = Object.create(baseContext);
|
||||
var baseContext;
|
||||
if (typeof context === 'string') {
|
||||
baseContext = { key: context };
|
||||
} else {
|
||||
baseContext = context || {};
|
||||
}
|
||||
|
||||
var actionContext = _.extend({}, baseContext);
|
||||
actionContext.domainObject = this.domainObject;
|
||||
|
||||
return this.actionService.getActions(actionContext);
|
||||
|
||||
@@ -33,7 +33,7 @@ define(
|
||||
|
||||
function createMockActionProvider(actions, i) {
|
||||
var spy = jasmine.createSpyObj("agg" + i, ["getActions"]);
|
||||
spy.getActions.andReturn(actions);
|
||||
spy.getActions.and.returnValue(actions);
|
||||
return spy;
|
||||
}
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ define(
|
||||
["getId", "getModel", "getCapability", "hasCapability", "useCapability"]
|
||||
);
|
||||
|
||||
mockActionService.getActions.andReturn([mockAction, {}]);
|
||||
mockActionService.getActions.and.returnValue([mockAction, {}]);
|
||||
|
||||
capability = new ActionCapability(
|
||||
mockQ,
|
||||
@@ -77,8 +77,8 @@ define(
|
||||
|
||||
it("promises the result of performed actions", function () {
|
||||
var mockPromise = jasmine.createSpyObj("promise", ["then"]);
|
||||
mockQ.when.andReturn(mockPromise);
|
||||
mockAction.perform.andReturn("the action's result");
|
||||
mockQ.when.and.returnValue(mockPromise);
|
||||
mockAction.perform.and.returnValue("the action's result");
|
||||
|
||||
// Verify precondition
|
||||
expect(mockAction.perform).not.toHaveBeenCalled();
|
||||
|
||||
@@ -176,7 +176,7 @@ define(
|
||||
|
||||
it("reports the error's message", function () {
|
||||
expect(
|
||||
mockLog.error.mostRecentCall.args[0].indexOf(errorText)
|
||||
mockLog.error.calls.mostRecent().args[0].indexOf(errorText)
|
||||
).not.toEqual(-1);
|
||||
});
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ define(
|
||||
["error", "warn", "info", "debug"]
|
||||
);
|
||||
|
||||
mockActionService.getActions.andReturn([mockAction]);
|
||||
mockActionService.getActions.and.returnValue([mockAction]);
|
||||
|
||||
decorator = new LoggingActionDecorator(
|
||||
mockLog,
|
||||
|
||||
@@ -72,7 +72,7 @@ define(
|
||||
}
|
||||
};
|
||||
|
||||
mockObjectService.getObjects.andReturn(mockPromise([]));
|
||||
mockObjectService.getObjects.and.returnValue(mockPromise([]));
|
||||
|
||||
composition = new CompositionCapability(
|
||||
mockInjector,
|
||||
@@ -90,7 +90,7 @@ define(
|
||||
it("requests ids found in model's composition from the object service", function () {
|
||||
var ids = ["a", "b", "c", "xyz"];
|
||||
|
||||
mockDomainObject.getModel.andReturn({ composition: ids });
|
||||
mockDomainObject.getModel.and.returnValue({ composition: ids });
|
||||
|
||||
composition.invoke();
|
||||
|
||||
@@ -101,9 +101,9 @@ define(
|
||||
var result,
|
||||
mockChild = jasmine.createSpyObj("child", DOMAIN_OBJECT_METHODS);
|
||||
|
||||
mockDomainObject.getModel.andReturn({ composition: ["x"] });
|
||||
mockObjectService.getObjects.andReturn(mockPromise({x: mockChild}));
|
||||
mockChild.getCapability.andReturn(undefined);
|
||||
mockDomainObject.getModel.and.returnValue({ composition: ["x"] });
|
||||
mockObjectService.getObjects.and.returnValue(mockPromise({x: mockChild}));
|
||||
mockChild.getCapability.and.returnValue(undefined);
|
||||
|
||||
composition.invoke().then(function (c) {
|
||||
result = c;
|
||||
@@ -119,12 +119,12 @@ define(
|
||||
testModel = { composition: [] },
|
||||
mockChild = jasmine.createSpyObj("child", DOMAIN_OBJECT_METHODS);
|
||||
|
||||
mockDomainObject.getModel.andReturn(testModel);
|
||||
mockObjectService.getObjects.andReturn(mockPromise({a: mockChild}));
|
||||
mockChild.getCapability.andReturn(undefined);
|
||||
mockChild.getId.andReturn('a');
|
||||
mockDomainObject.getModel.and.returnValue(testModel);
|
||||
mockObjectService.getObjects.and.returnValue(mockPromise({a: mockChild}));
|
||||
mockChild.getCapability.and.returnValue(undefined);
|
||||
mockChild.getId.and.returnValue('a');
|
||||
|
||||
mockDomainObject.useCapability.andCallFake(function (key, mutator) {
|
||||
mockDomainObject.useCapability.and.callFake(function (key, mutator) {
|
||||
if (key === 'mutation') {
|
||||
mutator(testModel);
|
||||
return mockPromise(true);
|
||||
@@ -149,12 +149,12 @@ define(
|
||||
testModel = { composition: ['a'] },
|
||||
mockChild = jasmine.createSpyObj("child", DOMAIN_OBJECT_METHODS);
|
||||
|
||||
mockDomainObject.getModel.andReturn(testModel);
|
||||
mockObjectService.getObjects.andReturn(mockPromise({a: mockChild}));
|
||||
mockChild.getCapability.andReturn(undefined);
|
||||
mockChild.getId.andReturn('a');
|
||||
mockDomainObject.getModel.and.returnValue(testModel);
|
||||
mockObjectService.getObjects.and.returnValue(mockPromise({a: mockChild}));
|
||||
mockChild.getCapability.and.returnValue(undefined);
|
||||
mockChild.getId.and.returnValue('a');
|
||||
|
||||
mockDomainObject.useCapability.andCallFake(function (key, mutator) {
|
||||
mockDomainObject.useCapability.and.callFake(function (key, mutator) {
|
||||
if (key === 'mutation') {
|
||||
mutator(testModel);
|
||||
return mockPromise(true);
|
||||
@@ -180,12 +180,12 @@ define(
|
||||
testModel = { composition: ['a', 'b', 'c'] },
|
||||
mockChild = jasmine.createSpyObj("child", DOMAIN_OBJECT_METHODS);
|
||||
|
||||
mockDomainObject.getModel.andReturn(testModel);
|
||||
mockObjectService.getObjects.andReturn(mockPromise({a: mockChild}));
|
||||
mockChild.getCapability.andReturn(undefined);
|
||||
mockChild.getId.andReturn('a');
|
||||
mockDomainObject.getModel.and.returnValue(testModel);
|
||||
mockObjectService.getObjects.and.returnValue(mockPromise({a: mockChild}));
|
||||
mockChild.getCapability.and.returnValue(undefined);
|
||||
mockChild.getId.and.returnValue('a');
|
||||
|
||||
mockDomainObject.useCapability.andCallFake(function (key, mutator) {
|
||||
mockDomainObject.useCapability.and.callFake(function (key, mutator) {
|
||||
if (key === 'mutation') {
|
||||
mutator(testModel);
|
||||
return mockPromise(true);
|
||||
|
||||
@@ -48,10 +48,10 @@ define(
|
||||
mockGrandparent = jasmine.createSpyObj("grandparent", DOMAIN_OBJECT_METHODS);
|
||||
mockContext = jasmine.createSpyObj("context", ["getParent", "getRoot", "getPath"]);
|
||||
|
||||
mockParent.getCapability.andReturn(mockContext);
|
||||
mockContext.getParent.andReturn(mockGrandparent);
|
||||
mockContext.getRoot.andReturn(mockGrandparent);
|
||||
mockContext.getPath.andReturn([mockGrandparent, mockParent]);
|
||||
mockParent.getCapability.and.returnValue(mockContext);
|
||||
mockContext.getParent.and.returnValue(mockGrandparent);
|
||||
mockContext.getRoot.and.returnValue(mockGrandparent);
|
||||
mockContext.getPath.and.returnValue([mockGrandparent, mockParent]);
|
||||
|
||||
context = new ContextCapability(mockParent, mockDomainObject);
|
||||
});
|
||||
@@ -69,7 +69,7 @@ define(
|
||||
});
|
||||
|
||||
it("treats ancestors with no context capability as deepest ancestors", function () {
|
||||
mockParent.getCapability.andReturn(undefined);
|
||||
mockParent.getCapability.and.returnValue(undefined);
|
||||
expect(context.getPath()).toEqual([mockParent, mockDomainObject]);
|
||||
expect(context.getRoot()).toEqual(mockParent);
|
||||
});
|
||||
|
||||
@@ -49,8 +49,8 @@ define(
|
||||
|
||||
model = { someKey: "some value" };
|
||||
|
||||
mockDomainObject.getCapability.andReturn("some capability");
|
||||
mockDomainObject.getModel.andReturn(model);
|
||||
mockDomainObject.getCapability.and.returnValue("some capability");
|
||||
mockDomainObject.getModel.and.returnValue(model);
|
||||
|
||||
contextualDomainObject = new ContextualDomainObject(
|
||||
mockDomainObject,
|
||||
|
||||
@@ -49,6 +49,8 @@ define(
|
||||
}
|
||||
|
||||
beforeEach(function () {
|
||||
KeylessCapability.key = undefined;
|
||||
|
||||
mockLog = jasmine.createSpyObj(
|
||||
"$log",
|
||||
["error", "warn", "info", "debug"]
|
||||
|
||||
@@ -49,16 +49,16 @@ define(
|
||||
['getId', 'getCapability', 'getModel']
|
||||
);
|
||||
|
||||
mockInjector.get.andCallFake(function (key) {
|
||||
mockInjector.get.and.callFake(function (key) {
|
||||
return {
|
||||
'instantiate': mockInstantiate
|
||||
}[key];
|
||||
});
|
||||
mockIdentifierService.parse.andReturn(mockIdentifier);
|
||||
mockIdentifierService.generate.andReturn("some-id");
|
||||
mockIdentifierService.parse.and.returnValue(mockIdentifier);
|
||||
mockIdentifierService.generate.and.returnValue("some-id");
|
||||
|
||||
mockNow = jasmine.createSpy();
|
||||
mockNow.andReturn(1234321);
|
||||
mockNow.and.returnValue(1234321);
|
||||
|
||||
instantiation = new InstantiationCapability(
|
||||
mockInjector,
|
||||
@@ -81,7 +81,7 @@ define(
|
||||
'useCapability',
|
||||
'hasCapability'
|
||||
]), testModel = { someKey: "some value" };
|
||||
mockInstantiate.andReturn(mockDomainObj);
|
||||
mockInstantiate.and.returnValue(mockDomainObj);
|
||||
instantiation.instantiate(testModel);
|
||||
expect(mockInstantiate)
|
||||
.toHaveBeenCalledWith({
|
||||
|
||||
@@ -58,18 +58,18 @@ define(
|
||||
'property-' + k,
|
||||
['getValue', 'getDefinition']
|
||||
);
|
||||
mockProperty.getValue.andReturn("Value " + k);
|
||||
mockProperty.getDefinition.andReturn({ name: "Property " + k});
|
||||
mockProperty.getValue.and.returnValue("Value " + k);
|
||||
mockProperty.getDefinition.and.returnValue({ name: "Property " + k});
|
||||
return mockProperty;
|
||||
});
|
||||
testModel = { name: "" };
|
||||
|
||||
mockDomainObject.getId.andReturn("Test id");
|
||||
mockDomainObject.getModel.andReturn(testModel);
|
||||
mockDomainObject.getCapability.andCallFake(getCapability);
|
||||
mockDomainObject.useCapability.andCallFake(getCapability);
|
||||
mockType.getProperties.andReturn(mockProperties);
|
||||
mockType.getName.andReturn("Test type");
|
||||
mockDomainObject.getId.and.returnValue("Test id");
|
||||
mockDomainObject.getModel.and.returnValue(testModel);
|
||||
mockDomainObject.getCapability.and.callFake(getCapability);
|
||||
mockDomainObject.useCapability.and.callFake(getCapability);
|
||||
mockType.getProperties.and.returnValue(mockProperties);
|
||||
mockType.getName.and.returnValue("Test type");
|
||||
|
||||
metadata = new MetadataCapability(mockDomainObject);
|
||||
});
|
||||
|
||||
@@ -48,7 +48,7 @@ define(
|
||||
testModel = { number: 6 };
|
||||
topic = new Topic();
|
||||
mockNow = jasmine.createSpy('now');
|
||||
mockNow.andReturn(12321);
|
||||
mockNow.and.returnValue(12321);
|
||||
mutation = new MutationCapability(
|
||||
topic,
|
||||
mockNow,
|
||||
@@ -105,7 +105,7 @@ define(
|
||||
m.number = 8;
|
||||
});
|
||||
expect(mockCallback).toHaveBeenCalled();
|
||||
expect(mockCallback.mostRecentCall.args[0].number)
|
||||
expect(mockCallback.calls.mostRecent().args[0].number)
|
||||
.toEqual(8);
|
||||
});
|
||||
|
||||
@@ -130,7 +130,7 @@ define(
|
||||
m.number = 8;
|
||||
});
|
||||
expect(mockCallback).toHaveBeenCalled();
|
||||
expect(mockCallback.mostRecentCall.args[0].number)
|
||||
expect(mockCallback.calls.mostRecent().args[0].number)
|
||||
.toEqual(8);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -95,15 +95,15 @@ define(
|
||||
useCapability: jasmine.createSpy()
|
||||
};
|
||||
// Simulate mutation capability
|
||||
mockDomainObject.useCapability.andCallFake(function (capability, mutator) {
|
||||
mockDomainObject.useCapability.and.callFake(function (capability, mutator) {
|
||||
if (capability === 'mutation') {
|
||||
model = mutator(model) || model;
|
||||
}
|
||||
});
|
||||
mockIdentifierService.parse.andReturn(mockIdentifier);
|
||||
mockIdentifier.getSpace.andReturn(SPACE);
|
||||
mockIdentifier.getKey.andReturn(key);
|
||||
mockQ.when.andCallFake(asPromise);
|
||||
mockIdentifierService.parse.and.returnValue(mockIdentifier);
|
||||
mockIdentifier.getSpace.and.returnValue(SPACE);
|
||||
mockIdentifier.getKey.and.returnValue(key);
|
||||
mockQ.when.and.callFake(asPromise);
|
||||
persistence = new PersistenceCapability(
|
||||
mockCacheService,
|
||||
mockPersistenceService,
|
||||
@@ -116,8 +116,8 @@ define(
|
||||
|
||||
describe("successful persistence", function () {
|
||||
beforeEach(function () {
|
||||
mockPersistenceService.updateObject.andReturn(happyPromise);
|
||||
mockPersistenceService.createObject.andReturn(happyPromise);
|
||||
mockPersistenceService.updateObject.and.returnValue(happyPromise);
|
||||
mockPersistenceService.createObject.and.returnValue(happyPromise);
|
||||
});
|
||||
it("creates unpersisted objects with the persistence service", function () {
|
||||
// Verify precondition; no call made during constructor
|
||||
@@ -158,7 +158,7 @@ define(
|
||||
it("refreshes the domain object model from persistence", function () {
|
||||
var refreshModel = {someOtherKey: "some other value"};
|
||||
model.persisted = 1;
|
||||
mockPersistenceService.readObject.andReturn(asPromise(refreshModel));
|
||||
mockPersistenceService.readObject.and.returnValue(asPromise(refreshModel));
|
||||
persistence.refresh();
|
||||
expect(model).toEqual(refreshModel);
|
||||
});
|
||||
@@ -178,7 +178,7 @@ define(
|
||||
}
|
||||
};
|
||||
beforeEach(function () {
|
||||
mockPersistenceService.createObject.andReturn(sadPromise);
|
||||
mockPersistenceService.createObject.and.returnValue(sadPromise);
|
||||
});
|
||||
it("rejects on falsey persistence result", function () {
|
||||
persistence.persist();
|
||||
|
||||
@@ -69,7 +69,7 @@ define(
|
||||
}
|
||||
};
|
||||
|
||||
mockObjectService.getObjects.andReturn(mockPromise([]));
|
||||
mockObjectService.getObjects.and.returnValue(mockPromise([]));
|
||||
|
||||
relationship = new RelationshipCapability(
|
||||
mockInjector,
|
||||
@@ -87,7 +87,7 @@ define(
|
||||
it("requests ids found in model's composition from the object service", function () {
|
||||
var ids = ["a", "b", "c", "xyz"];
|
||||
|
||||
mockDomainObject.getModel.andReturn({ relationships: { xyz: ids } });
|
||||
mockDomainObject.getModel.and.returnValue({ relationships: { xyz: ids } });
|
||||
|
||||
relationship.getRelatedObjects('xyz');
|
||||
|
||||
@@ -95,7 +95,7 @@ define(
|
||||
});
|
||||
|
||||
it("provides a list of relationship types", function () {
|
||||
mockDomainObject.getModel.andReturn({ relationships: {
|
||||
mockDomainObject.getModel.and.returnValue({ relationships: {
|
||||
abc: ['a', 'b'],
|
||||
def: "not an array, should be ignored",
|
||||
xyz: []
|
||||
@@ -107,14 +107,14 @@ define(
|
||||
// Lookups can be expensive, so this capability
|
||||
// should have some self-caching
|
||||
mockDomainObject.getModel
|
||||
.andReturn({ relationships: { xyz: ['a'] } });
|
||||
.and.returnValue({ relationships: { xyz: ['a'] } });
|
||||
|
||||
// Call twice; response should be the same object instance
|
||||
expect(relationship.getRelatedObjects('xyz'))
|
||||
.toBe(relationship.getRelatedObjects('xyz'));
|
||||
|
||||
// Should have only made one call
|
||||
expect(mockObjectService.getObjects.calls.length)
|
||||
expect(mockObjectService.getObjects.calls.count())
|
||||
.toEqual(1);
|
||||
});
|
||||
|
||||
@@ -125,7 +125,7 @@ define(
|
||||
|
||||
testModel = { relationships: { xyz: ['a'] } };
|
||||
|
||||
mockDomainObject.getModel.andReturn(testModel);
|
||||
mockDomainObject.getModel.and.returnValue(testModel);
|
||||
|
||||
// Call twice, but as if modification had occurred in between
|
||||
relationship.getRelatedObjects('xyz');
|
||||
@@ -133,7 +133,7 @@ define(
|
||||
relationship.getRelatedObjects('xyz');
|
||||
|
||||
// Should have only made one call
|
||||
expect(mockObjectService.getObjects.calls.length)
|
||||
expect(mockObjectService.getObjects.calls.count())
|
||||
.toEqual(2);
|
||||
});
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ define(
|
||||
a: { someKey: "some value" },
|
||||
b: { someOtherKey: "some other value" }
|
||||
};
|
||||
mockModelService.getModels.andReturn(asPromise(testModels));
|
||||
mockModelService.getModels.and.returnValue(asPromise(testModels));
|
||||
decorator = new CachingModelDecorator(
|
||||
new ModelCacheService(),
|
||||
mockModelService
|
||||
@@ -80,19 +80,19 @@ define(
|
||||
});
|
||||
|
||||
it("does not try to reload cached models", function () {
|
||||
mockModelService.getModels.andReturn(asPromise({ a: testModels.a }));
|
||||
mockModelService.getModels.and.returnValue(asPromise({ a: testModels.a }));
|
||||
decorator.getModels(['a']);
|
||||
mockModelService.getModels.andReturn(asPromise(testModels));
|
||||
mockModelService.getModels.and.returnValue(asPromise(testModels));
|
||||
decorator.getModels(['a', 'b']);
|
||||
expect(mockModelService.getModels).not.toHaveBeenCalledWith(['a', 'b']);
|
||||
expect(mockModelService.getModels.mostRecentCall.args[0]).toEqual(['b']);
|
||||
expect(mockModelService.getModels.calls.mostRecent().args[0]).toEqual(['b']);
|
||||
});
|
||||
|
||||
it("does not call its wrapped model service if not needed", function () {
|
||||
decorator.getModels(['a', 'b']);
|
||||
expect(mockModelService.getModels.calls.length).toEqual(1);
|
||||
expect(mockModelService.getModels.calls.count()).toEqual(1);
|
||||
decorator.getModels(['a', 'b']).then(mockCallback);
|
||||
expect(mockModelService.getModels.calls.length).toEqual(1);
|
||||
expect(mockModelService.getModels.calls.count()).toEqual(1);
|
||||
// Verify that we still got back our models, even though
|
||||
// no new call to the wrapped service was made
|
||||
expect(mockCallback).toHaveBeenCalledWith(testModels);
|
||||
@@ -105,9 +105,9 @@ define(
|
||||
promiseB = fakePromise();
|
||||
|
||||
// Issue two calls before those promises resolve
|
||||
mockModelService.getModels.andReturn(promiseA);
|
||||
mockModelService.getModels.and.returnValue(promiseA);
|
||||
decorator.getModels(['a']);
|
||||
mockModelService.getModels.andReturn(promiseB);
|
||||
mockModelService.getModels.and.returnValue(promiseB);
|
||||
decorator.getModels(['a']).then(mockCallback);
|
||||
|
||||
// Then resolve those promises. Note that we're whiteboxing here
|
||||
@@ -119,9 +119,9 @@ define(
|
||||
});
|
||||
|
||||
// Ensure that we have a pointer-identical instance
|
||||
expect(mockCallback.mostRecentCall.args[0].a)
|
||||
expect(mockCallback.calls.mostRecent().args[0].a)
|
||||
.toEqual({ someNewKey: "some other value" });
|
||||
expect(mockCallback.mostRecentCall.args[0].a)
|
||||
expect(mockCallback.calls.mostRecent().args[0].a)
|
||||
.toBe(testModels.a);
|
||||
});
|
||||
|
||||
@@ -132,9 +132,9 @@ define(
|
||||
promiseB = fakePromise();
|
||||
|
||||
// Issue two calls before those promises resolve
|
||||
mockModelService.getModels.andReturn(promiseA);
|
||||
mockModelService.getModels.and.returnValue(promiseA);
|
||||
decorator.getModels(['a']);
|
||||
mockModelService.getModels.andReturn(promiseB);
|
||||
mockModelService.getModels.and.returnValue(promiseB);
|
||||
decorator.getModels(['a']).then(mockCallback);
|
||||
|
||||
// Some model providers might erroneously add undefined values
|
||||
@@ -147,7 +147,7 @@ define(
|
||||
});
|
||||
|
||||
// Should still have gotten the model
|
||||
expect(mockCallback.mostRecentCall.args[0].a)
|
||||
expect(mockCallback.calls.mostRecent().args[0].a)
|
||||
.toEqual({ someNewKey: "some other value" });
|
||||
});
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ define(
|
||||
testId: { someKey: "some value" }
|
||||
};
|
||||
|
||||
mockModelService.getModels.andReturn(asPromise(testModels));
|
||||
mockModelService.getModels.and.returnValue(asPromise(testModels));
|
||||
|
||||
decorator = new MissingModelDecorator(mockModelService);
|
||||
});
|
||||
|
||||
@@ -43,11 +43,11 @@ define(
|
||||
"mockProvider" + i,
|
||||
["getModels"]
|
||||
);
|
||||
mockProvider.getModels.andReturn(models);
|
||||
mockProvider.getModels.and.returnValue(models);
|
||||
return mockProvider;
|
||||
});
|
||||
|
||||
mockQ.all.andReturn({
|
||||
mockQ.all.and.returnValue({
|
||||
then: function (c) {
|
||||
return c(modelList);
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ define(
|
||||
mockNow = jasmine.createSpy("now");
|
||||
|
||||
mockPersistenceService.readObject
|
||||
.andCallFake(function (space, id) {
|
||||
.and.callFake(function (space, id) {
|
||||
return mockPromise({
|
||||
space: space,
|
||||
id: id,
|
||||
@@ -76,7 +76,7 @@ define(
|
||||
});
|
||||
});
|
||||
mockPersistenceService.listSpaces
|
||||
.andReturn(mockPromise([SPACE]));
|
||||
.and.returnValue(mockPromise([SPACE]));
|
||||
|
||||
provider = new PersistedModelProvider(
|
||||
mockPersistenceService,
|
||||
@@ -94,9 +94,9 @@ define(
|
||||
});
|
||||
|
||||
expect(models).toEqual({
|
||||
a: { space: SPACE, id: "a", persisted: 0 },
|
||||
x: { space: SPACE, id: "x", persisted: 0 },
|
||||
zz: { space: SPACE, id: "zz", persisted: 0 }
|
||||
a: { space: SPACE, id: "a", persisted: 0, modified: undefined },
|
||||
x: { space: SPACE, id: "x", persisted: 0, modified: undefined },
|
||||
zz: { space: SPACE, id: "zz", persisted: 0, modified: undefined }
|
||||
});
|
||||
});
|
||||
|
||||
@@ -110,12 +110,12 @@ define(
|
||||
d: { name: "D" }
|
||||
};
|
||||
|
||||
mockPersistenceService.readObject.andCallFake(
|
||||
mockPersistenceService.readObject.and.callFake(
|
||||
function (space, id) {
|
||||
return mockPromise(testModels[id]);
|
||||
}
|
||||
);
|
||||
mockNow.andReturn(12321);
|
||||
mockNow.and.returnValue(12321);
|
||||
|
||||
provider.getModels(Object.keys(testModels)).then(mockCallback);
|
||||
|
||||
|
||||
@@ -58,17 +58,17 @@ define(
|
||||
var mockPromise = { then: function () {
|
||||
return;
|
||||
} };
|
||||
mockQ.when.andReturn(mockPromise);
|
||||
mockQ.when.and.returnValue(mockPromise);
|
||||
|
||||
// Verify that we got the promise as the return value
|
||||
expect(provider.getModels(["a", "b"])).toEqual(mockPromise);
|
||||
|
||||
// Verify that the promise has the desired models
|
||||
expect(mockQ.when.callCount).toEqual(1);
|
||||
expect(mockQ.when.mostRecentCall.args[0].a.name).toEqual("Thing A");
|
||||
expect(mockQ.when.mostRecentCall.args[0].a.someProperty).toEqual("Some Value A");
|
||||
expect(mockQ.when.mostRecentCall.args[0].b.name).toEqual("Thing B");
|
||||
expect(mockQ.when.mostRecentCall.args[0].b.someProperty).toEqual("Some Value B");
|
||||
expect(mockQ.when.calls.count()).toEqual(1);
|
||||
expect(mockQ.when.calls.mostRecent().args[0].a.name).toEqual("Thing A");
|
||||
expect(mockQ.when.calls.mostRecent().args[0].a.someProperty).toEqual("Some Value A");
|
||||
expect(mockQ.when.calls.mostRecent().args[0].b.name).toEqual("Thing B");
|
||||
expect(mockQ.when.calls.mostRecent().args[0].b.someProperty).toEqual("Some Value B");
|
||||
});
|
||||
|
||||
|
||||
@@ -76,8 +76,8 @@ define(
|
||||
provider.getModels(["c"]);
|
||||
|
||||
// Verify that the promise has the desired models
|
||||
expect(mockQ.when.callCount).toEqual(1);
|
||||
expect(mockQ.when.mostRecentCall.args[0].c).toBeUndefined();
|
||||
expect(mockQ.when.calls.count()).toEqual(1);
|
||||
expect(mockQ.when.calls.mostRecent().args[0].c).toBeUndefined();
|
||||
});
|
||||
|
||||
it("logs a warning when model definitions are malformed", function () {
|
||||
@@ -94,7 +94,7 @@ define(
|
||||
], mockQ, mockLog)).toBeDefined();
|
||||
|
||||
// Should show warnings
|
||||
expect(mockLog.warn.callCount).toEqual(5);
|
||||
expect(mockLog.warn.calls.count()).toEqual(5);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -53,7 +53,7 @@ define(
|
||||
);
|
||||
mockInstantiate = jasmine.createSpy("instantiate");
|
||||
|
||||
mockInstantiate.andCallFake(function (model, id) {
|
||||
mockInstantiate.and.callFake(function (model, id) {
|
||||
return new DomainObjectImpl(id, model, {});
|
||||
});
|
||||
|
||||
@@ -65,7 +65,7 @@ define(
|
||||
|
||||
it("requests models from the model service", function () {
|
||||
var ids = ["a", "b", "c"];
|
||||
mockModelService.getModels.andReturn(mockPromise({}));
|
||||
mockModelService.getModels.and.returnValue(mockPromise({}));
|
||||
provider.getObjects(ids);
|
||||
expect(mockModelService.getModels).toHaveBeenCalledWith(ids);
|
||||
});
|
||||
@@ -75,7 +75,7 @@ define(
|
||||
var ids = ["a", "b", "c"],
|
||||
model = { someKey: "some value"},
|
||||
result;
|
||||
mockModelService.getModels.andReturn(mockPromise({ a: model }));
|
||||
mockModelService.getModels.and.returnValue(mockPromise({ a: model }));
|
||||
result = provider.getObjects(ids).testValue;
|
||||
expect(mockInstantiate).toHaveBeenCalledWith(model, 'a');
|
||||
expect(result.a.getId()).toEqual("a");
|
||||
|
||||
@@ -51,15 +51,15 @@ define(
|
||||
['persist', 'refresh', 'persisted']
|
||||
);
|
||||
|
||||
mockTopic.andCallFake(function (t) {
|
||||
mockTopic.and.callFake(function (t) {
|
||||
return (t === 'mutation') && mockMutationTopic;
|
||||
});
|
||||
|
||||
mockDomainObject.getCapability.andCallFake(function (c) {
|
||||
mockDomainObject.getCapability.and.callFake(function (c) {
|
||||
return (c === 'persistence') && mockPersistence;
|
||||
});
|
||||
|
||||
mockPersistence.persisted.andReturn(true);
|
||||
mockPersistence.persisted.and.returnValue(true);
|
||||
|
||||
return new TransactingMutationListener(
|
||||
mockTopic,
|
||||
@@ -83,12 +83,12 @@ define(
|
||||
var innerVerb = isActive ? "does" : "doesn't";
|
||||
|
||||
beforeEach(function () {
|
||||
mockTransactionService.isActive.andReturn(isActive);
|
||||
mockTransactionService.isActive.and.returnValue(isActive);
|
||||
});
|
||||
|
||||
describe("and mutation occurs", function () {
|
||||
beforeEach(function () {
|
||||
mockMutationTopic.listen.mostRecentCall
|
||||
mockMutationTopic.listen.calls.mostRecent()
|
||||
.args[0](mockDomainObject);
|
||||
});
|
||||
|
||||
|
||||
@@ -49,12 +49,12 @@ define(
|
||||
);
|
||||
mockCapabilityConstructor = jasmine.createSpy('capability');
|
||||
mockCapabilityInstance = {};
|
||||
mockCapabilityService.getCapabilities.andReturn({
|
||||
mockCapabilityService.getCapabilities.and.returnValue({
|
||||
something: mockCapabilityConstructor
|
||||
});
|
||||
mockCapabilityConstructor.andReturn(mockCapabilityInstance);
|
||||
mockCapabilityConstructor.and.returnValue(mockCapabilityInstance);
|
||||
|
||||
mockIdentifierService.generate.andCallFake(function (space) {
|
||||
mockIdentifierService.generate.and.callFake(function (space) {
|
||||
return (space ? (space + ":") : "") +
|
||||
"some-id-" + (idCounter += 1);
|
||||
});
|
||||
|
||||
@@ -34,7 +34,7 @@ define(
|
||||
mockTimeout = jasmine.createSpy("$timeout");
|
||||
mockPromise = jasmine.createSpyObj("promise", ["then"]);
|
||||
mockFn = jasmine.createSpy("fn");
|
||||
mockTimeout.andReturn(mockPromise);
|
||||
mockTimeout.and.returnValue(mockPromise);
|
||||
throttle = new Throttle(mockTimeout);
|
||||
});
|
||||
|
||||
@@ -53,18 +53,18 @@ define(
|
||||
throttled();
|
||||
throttled();
|
||||
throttled();
|
||||
expect(mockTimeout.calls.length).toEqual(1);
|
||||
expect(mockTimeout.calls.count()).toEqual(1);
|
||||
});
|
||||
|
||||
it("schedules additional invocations after resolution", function () {
|
||||
var throttled = throttle(mockFn);
|
||||
throttled();
|
||||
mockTimeout.mostRecentCall.args[0](); // Resolve timeout
|
||||
mockTimeout.calls.mostRecent().args[0](); // Resolve timeout
|
||||
throttled();
|
||||
mockTimeout.mostRecentCall.args[0]();
|
||||
mockTimeout.calls.mostRecent().args[0]();
|
||||
throttled();
|
||||
mockTimeout.mostRecentCall.args[0]();
|
||||
expect(mockTimeout.calls.length).toEqual(3);
|
||||
mockTimeout.calls.mostRecent().args[0]();
|
||||
expect(mockTimeout.calls.count()).toEqual(3);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ define(
|
||||
var mockBadCallback = jasmine.createSpy("bad-callback"),
|
||||
t = topic();
|
||||
|
||||
mockBadCallback.andCallFake(function () {
|
||||
mockBadCallback.and.callFake(function () {
|
||||
throw new Error("I'm afraid I can't do that.");
|
||||
});
|
||||
|
||||
|
||||
@@ -42,16 +42,22 @@ define(
|
||||
"domainObject",
|
||||
["getId", "getModel", "getCapability"]
|
||||
);
|
||||
mockType = { someKey: "some value" };
|
||||
mockType = {
|
||||
someKey: "some value",
|
||||
someOtherProperty: "some other property",
|
||||
aThirdProperty: "a third property"
|
||||
};
|
||||
|
||||
mockTypeService.getType.andReturn(mockType);
|
||||
mockDomainObject.getModel.andReturn({type: "mockType"});
|
||||
mockTypeService.getType.and.returnValue(mockType);
|
||||
mockDomainObject.getModel.and.returnValue({type: "mockType"});
|
||||
|
||||
type = new TypeCapability(mockTypeService, mockDomainObject);
|
||||
});
|
||||
|
||||
it("looks up an object's type from type service", function () {
|
||||
expect(type).toEqual(mockType);
|
||||
expect(type.someKey).toEqual(mockType.someKey);
|
||||
expect(type.someOtherProperty).toEqual(mockType.someOtherProperty);
|
||||
expect(type.aThirdProperty).toEqual(mockType.aThirdProperty);
|
||||
expect(mockTypeService.getType).toHaveBeenCalledWith("mockType");
|
||||
});
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ define(
|
||||
"domainObject",
|
||||
["getId", "getModel", "getCapability"]
|
||||
);
|
||||
mockViewService.getViews.andReturn(views);
|
||||
mockViewService.getViews.and.returnValue(views);
|
||||
view = new ViewCapability(mockViewService, mockDomainObject);
|
||||
});
|
||||
|
||||
|
||||
@@ -116,17 +116,17 @@ define(
|
||||
"type",
|
||||
["instanceOf", "invoke", "getDefinition"]
|
||||
);
|
||||
capabilities.type.invoke.andReturn(capabilities.type);
|
||||
capabilities.type.invoke.and.returnValue(capabilities.type);
|
||||
|
||||
// Should be included when types match
|
||||
capabilities.type.instanceOf.andReturn(true);
|
||||
capabilities.type.instanceOf.and.returnValue(true);
|
||||
expect(viewProvider.getViews(mockDomainObject))
|
||||
.toEqual([testView]);
|
||||
expect(capabilities.type.instanceOf)
|
||||
.toHaveBeenCalledWith(testType);
|
||||
|
||||
// ...but not when they don't
|
||||
capabilities.type.instanceOf.andReturn(false);
|
||||
capabilities.type.instanceOf.and.returnValue(false);
|
||||
expect(viewProvider.getViews(mockDomainObject))
|
||||
.toEqual([]);
|
||||
|
||||
@@ -141,17 +141,17 @@ define(
|
||||
"type",
|
||||
["instanceOf", "invoke", "getDefinition"]
|
||||
);
|
||||
capabilities.type.invoke.andReturn(capabilities.type);
|
||||
capabilities.type.invoke.and.returnValue(capabilities.type);
|
||||
|
||||
// Should be included when view keys match
|
||||
capabilities.type.getDefinition
|
||||
.andReturn({ views: [testView.key]});
|
||||
.and.returnValue({ views: [testView.key]});
|
||||
expect(viewProvider.getViews(mockDomainObject))
|
||||
.toEqual([testView]);
|
||||
|
||||
// ...but not when they don't
|
||||
capabilities.type.getDefinition
|
||||
.andReturn({ views: ["somethingElse"]});
|
||||
.and.returnValue({ views: ["somethingElse"]});
|
||||
expect(viewProvider.getViews(mockDomainObject))
|
||||
.toEqual([]);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user