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
@@ -53,10 +53,10 @@ define(
|
||||
'domainObject',
|
||||
['getCapability', 'useCapability', 'getModel']
|
||||
);
|
||||
mockFailure.domainObject.getCapability.andCallFake(function (c) {
|
||||
mockFailure.domainObject.getCapability.and.callFake(function (c) {
|
||||
return (c === 'persistence') && mockPersistence;
|
||||
});
|
||||
mockFailure.domainObject.getModel.andReturn({ id: id, modified: index });
|
||||
mockFailure.domainObject.getModel.and.returnValue({ id: id, modified: index });
|
||||
mockFailure.persistence = mockPersistence;
|
||||
mockFailure.id = id;
|
||||
mockFailure.error = { key: Constants.REVISION_ERROR_KEY };
|
||||
@@ -68,9 +68,9 @@ define(
|
||||
mockDialogService = jasmine.createSpyObj('dialogService', ['getUserChoice']);
|
||||
mockFailures = ['a', 'b', 'c'].map(makeMockFailure);
|
||||
mockPromise = jasmine.createSpyObj('promise', ['then']);
|
||||
mockDialogService.getUserChoice.andReturn(mockPromise);
|
||||
mockQ.all.andReturn(mockPromise);
|
||||
mockPromise.then.andReturn(mockPromise);
|
||||
mockDialogService.getUserChoice.and.returnValue(mockPromise);
|
||||
mockQ.all.and.returnValue(mockPromise);
|
||||
mockPromise.then.and.returnValue(mockPromise);
|
||||
handler = new PersistenceFailureHandler(mockQ, mockDialogService);
|
||||
});
|
||||
|
||||
@@ -80,10 +80,10 @@ define(
|
||||
});
|
||||
|
||||
it("overwrites on request", function () {
|
||||
mockQ.all.andReturn(asPromise([]));
|
||||
mockQ.all.and.returnValue(asPromise([]));
|
||||
handler.handle(mockFailures);
|
||||
// User chooses overwrite
|
||||
mockPromise.then.mostRecentCall.args[0](Constants.OVERWRITE_KEY);
|
||||
mockPromise.then.calls.mostRecent().args[0](Constants.OVERWRITE_KEY);
|
||||
// Should refresh, remutate, and requeue all objects
|
||||
mockFailures.forEach(function (mockFailure, i) {
|
||||
expect(mockFailure.persistence.refresh).toHaveBeenCalled();
|
||||
@@ -93,16 +93,16 @@ define(
|
||||
jasmine.any(Function),
|
||||
i // timestamp
|
||||
);
|
||||
expect(mockFailure.domainObject.useCapability.mostRecentCall.args[1]())
|
||||
expect(mockFailure.domainObject.useCapability.calls.mostRecent().args[1]())
|
||||
.toEqual({ id: mockFailure.id, modified: i });
|
||||
});
|
||||
});
|
||||
|
||||
it("discards on request", function () {
|
||||
mockQ.all.andReturn(asPromise([]));
|
||||
mockQ.all.and.returnValue(asPromise([]));
|
||||
handler.handle(mockFailures);
|
||||
// User chooses overwrite
|
||||
mockPromise.then.mostRecentCall.args[0](false);
|
||||
mockPromise.then.calls.mostRecent().args[0](false);
|
||||
// Should refresh, but not remutate, and requeue all objects
|
||||
mockFailures.forEach(function (mockFailure) {
|
||||
expect(mockFailure.persistence.refresh).toHaveBeenCalled();
|
||||
|
||||
@@ -49,7 +49,7 @@ define(
|
||||
'persistence-' + id,
|
||||
['persist', 'refresh']
|
||||
);
|
||||
mockPersistence.persist.andReturn(asPromise(true));
|
||||
mockPersistence.persist.and.returnValue(asPromise(true));
|
||||
return mockPersistence;
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ define(
|
||||
'domainObject-' + id,
|
||||
['getId']
|
||||
);
|
||||
mockDomainObject.getId.andReturn(id);
|
||||
mockDomainObject.getId.and.returnValue(id);
|
||||
return mockDomainObject;
|
||||
}
|
||||
|
||||
@@ -73,8 +73,8 @@ define(
|
||||
mockDomainObjects[id] = makeMockDomainObject(id);
|
||||
});
|
||||
mockRejection = jasmine.createSpyObj('rejection', ['then']);
|
||||
mockQ.all.andReturn(asPromise([]));
|
||||
mockRejection.then.andCallFake(function (callback, fallback) {
|
||||
mockQ.all.and.returnValue(asPromise([]));
|
||||
mockRejection.then.and.callFake(function (callback, fallback) {
|
||||
return asPromise(fallback({ someKey: "some value" }));
|
||||
});
|
||||
handler = new PersistenceQueueHandler(mockQ, mockFailureHandler);
|
||||
@@ -90,8 +90,8 @@ define(
|
||||
});
|
||||
|
||||
it("handles failures that occur", function () {
|
||||
mockPersistences.b.persist.andReturn(mockRejection);
|
||||
mockPersistences.c.persist.andReturn(mockRejection);
|
||||
mockPersistences.b.persist.and.returnValue(mockRejection);
|
||||
mockPersistences.c.persist.and.returnValue(mockRejection);
|
||||
handler.persist(mockPersistences, mockDomainObjects, mockQueue);
|
||||
expect(mockFailureHandler.handle).toHaveBeenCalledWith([
|
||||
{
|
||||
@@ -115,14 +115,14 @@ define(
|
||||
// This method is needed by PersistenceFailureHandler
|
||||
// to allow requeuing of objects for persistence when
|
||||
// Overwrite is chosen.
|
||||
mockPersistences.b.persist.andReturn(mockRejection);
|
||||
mockPersistences.b.persist.and.returnValue(mockRejection);
|
||||
handler.persist(mockPersistences, mockDomainObjects, mockQueue);
|
||||
|
||||
// Verify precondition
|
||||
expect(mockQueue.put).not.toHaveBeenCalled();
|
||||
|
||||
// Invoke requeue
|
||||
mockFailureHandler.handle.mostRecentCall.args[0][0].requeue();
|
||||
mockFailureHandler.handle.calls.mostRecent().args[0][0].requeue();
|
||||
|
||||
// Should have returned the object to the queue
|
||||
expect(mockQueue.put).toHaveBeenCalledWith(
|
||||
|
||||
@@ -40,7 +40,7 @@ define(
|
||||
'domainObject-' + id,
|
||||
['getId']
|
||||
);
|
||||
mockDomainObject.getId.andReturn(id);
|
||||
mockDomainObject.getId.and.returnValue(id);
|
||||
return mockDomainObject;
|
||||
}
|
||||
|
||||
@@ -59,10 +59,10 @@ define(
|
||||
mockDeferred = jasmine.createSpyObj('deferred', ['resolve']);
|
||||
mockDeferred.promise = jasmine.createSpyObj('promise', ['then']);
|
||||
mockPromise = jasmine.createSpyObj('promise', ['then']);
|
||||
mockQ.defer.andReturn(mockDeferred);
|
||||
mockTimeout.andReturn({});
|
||||
mockHandler.persist.andReturn(mockPromise);
|
||||
mockPromise.then.andReturn(mockPromise);
|
||||
mockQ.defer.and.returnValue(mockDeferred);
|
||||
mockTimeout.and.returnValue({});
|
||||
mockHandler.persist.and.returnValue(mockPromise);
|
||||
mockPromise.then.and.returnValue(mockPromise);
|
||||
queue = new PersistenceQueueImpl(
|
||||
mockQ,
|
||||
mockTimeout,
|
||||
@@ -87,7 +87,7 @@ define(
|
||||
queue.put(makeMockDomainObject('a'), makeMockPersistence('a'));
|
||||
queue.put(makeMockDomainObject('b'), makeMockPersistence('b'));
|
||||
queue.put(makeMockDomainObject('c'), makeMockPersistence('c'));
|
||||
expect(mockTimeout.calls.length).toEqual(1);
|
||||
expect(mockTimeout.calls.count()).toEqual(1);
|
||||
});
|
||||
|
||||
it("returns a promise", function () {
|
||||
@@ -99,14 +99,14 @@ define(
|
||||
// Keep adding objects to the queue between timeouts.
|
||||
// Should keep scheduling timeouts instead of resolving.
|
||||
queue.put(makeMockDomainObject('a'), makeMockPersistence('a'));
|
||||
expect(mockTimeout.calls.length).toEqual(1);
|
||||
mockTimeout.mostRecentCall.args[0]();
|
||||
expect(mockTimeout.calls.count()).toEqual(1);
|
||||
mockTimeout.calls.mostRecent().args[0]();
|
||||
queue.put(makeMockDomainObject('b'), makeMockPersistence('b'));
|
||||
expect(mockTimeout.calls.length).toEqual(2);
|
||||
mockTimeout.mostRecentCall.args[0]();
|
||||
expect(mockTimeout.calls.count()).toEqual(2);
|
||||
mockTimeout.calls.mostRecent().args[0]();
|
||||
queue.put(makeMockDomainObject('c'), makeMockPersistence('c'));
|
||||
expect(mockTimeout.calls.length).toEqual(3);
|
||||
mockTimeout.mostRecentCall.args[0]();
|
||||
expect(mockTimeout.calls.count()).toEqual(3);
|
||||
mockTimeout.calls.mostRecent().args[0]();
|
||||
expect(mockHandler.persist).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@@ -115,8 +115,8 @@ define(
|
||||
queue.put(makeMockDomainObject('a'), makeMockPersistence('a'));
|
||||
queue.put(makeMockDomainObject('b'), makeMockPersistence('b'));
|
||||
queue.put(makeMockDomainObject('c'), makeMockPersistence('c'));
|
||||
mockTimeout.mostRecentCall.args[0]();
|
||||
mockTimeout.mostRecentCall.args[0]();
|
||||
mockTimeout.calls.mostRecent().args[0]();
|
||||
mockTimeout.calls.mostRecent().args[0]();
|
||||
expect(mockHandler.persist).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@@ -124,28 +124,28 @@ define(
|
||||
// Persist some objects
|
||||
queue.put(makeMockDomainObject('a'), makeMockPersistence('a'));
|
||||
queue.put(makeMockDomainObject('b'), makeMockPersistence('b'));
|
||||
mockTimeout.mostRecentCall.args[0]();
|
||||
mockTimeout.mostRecentCall.args[0]();
|
||||
expect(mockTimeout.calls.length).toEqual(2);
|
||||
mockTimeout.calls.mostRecent().args[0]();
|
||||
mockTimeout.calls.mostRecent().args[0]();
|
||||
expect(mockTimeout.calls.count()).toEqual(2);
|
||||
// Adding a new object should not trigger a new timeout,
|
||||
// because we haven't completed the previous flush
|
||||
queue.put(makeMockDomainObject('c'), makeMockPersistence('c'));
|
||||
expect(mockTimeout.calls.length).toEqual(2);
|
||||
expect(mockTimeout.calls.count()).toEqual(2);
|
||||
});
|
||||
|
||||
it("clears the active flush after it has completed", function () {
|
||||
// Persist some objects
|
||||
queue.put(makeMockDomainObject('a'), makeMockPersistence('a'));
|
||||
queue.put(makeMockDomainObject('b'), makeMockPersistence('b'));
|
||||
mockTimeout.mostRecentCall.args[0]();
|
||||
mockTimeout.mostRecentCall.args[0]();
|
||||
expect(mockTimeout.calls.length).toEqual(2);
|
||||
mockTimeout.calls.mostRecent().args[0]();
|
||||
mockTimeout.calls.mostRecent().args[0]();
|
||||
expect(mockTimeout.calls.count()).toEqual(2);
|
||||
// Resolve the promise from handler.persist
|
||||
mockPromise.then.calls[0].args[0](true);
|
||||
mockPromise.then.calls.all()[0].args[0](true);
|
||||
// Adding a new object should now trigger a new timeout,
|
||||
// because we have completed the previous flush
|
||||
queue.put(makeMockDomainObject('c'), makeMockPersistence('c'));
|
||||
expect(mockTimeout.calls.length).toEqual(3);
|
||||
expect(mockTimeout.calls.count()).toEqual(3);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -53,10 +53,10 @@ define(
|
||||
['getId']
|
||||
);
|
||||
|
||||
mockCapabilityService.getCapabilities.andReturn({
|
||||
mockCapabilityService.getCapabilities.and.returnValue({
|
||||
persistence: mockPersistenceConstructor
|
||||
});
|
||||
mockPersistenceConstructor.andReturn(mockPersistence);
|
||||
mockPersistenceConstructor.and.returnValue(mockPersistence);
|
||||
|
||||
decorator = new QueuingPersistenceCapabilityDecorator(
|
||||
mockQueue,
|
||||
|
||||
Reference in New Issue
Block a user