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:
Andrew Henry
2018-06-29 17:32:59 -07:00
committed by Pete Richards
parent 013eba744d
commit 433dee0314
305 changed files with 2866 additions and 3324 deletions

View File

@@ -50,9 +50,9 @@ define(
['instanceOf']
);
mockDomainObject.getId.andReturn('test-id');
mockDomainObject.getCapability.andReturn(mockType);
mockType.instanceOf.andCallFake(function (t) {
mockDomainObject.getId.and.returnValue('test-id');
mockDomainObject.getCapability.and.returnValue(mockType);
mockType.instanceOf.and.callFake(function (t) {
return t === testType;
});

View File

@@ -60,10 +60,10 @@ define(
['getId', 'getModel', 'getCapability', 'useCapability']
);
mockDomainObj.getId.andReturn(id);
mockDomainObj.getModel.andReturn({ composition: composition });
mockDomainObj.useCapability.andReturn(asPromise(mockTimespans[id]));
mockDomainObj.getCapability.andCallFake(function (c) {
mockDomainObj.getId.and.returnValue(id);
mockDomainObj.getModel.and.returnValue({ composition: composition });
mockDomainObj.useCapability.and.returnValue(asPromise(mockTimespans[id]));
mockDomainObj.getCapability.and.callFake(function (c) {
return {
mutation: mockMutations[id]
}[c];
@@ -84,9 +84,9 @@ define(
'mutation-' + id,
['mutate']
);
mockTimespans[id].getStart.andReturn(index * 1000);
mockTimespans[id].getDuration.andReturn(4000 + index);
mockTimespans[id].getEnd.andReturn(4000 + index + index * 1000);
mockTimespans[id].getStart.and.returnValue(index * 1000);
mockTimespans[id].getDuration.and.returnValue(4000 + index);
mockTimespans[id].getEnd.and.returnValue(4000 + index + index * 1000);
});
mockLoader = jasmine.createSpyObj('objectLoader', ['load']);
@@ -104,7 +104,7 @@ define(
testConfiguration = {};
mockLoader.load.andReturn(asPromise(
mockLoader.load.and.returnValue(asPromise(
subgraph(mockDomainObject, mockDomainObjects)
));
@@ -193,7 +193,7 @@ define(
it("prevents bulk moves past 0", function () {
// Have a start later; new lowest start is b, at 1000
mockTimespans.a.getStart.andReturn(10000);
mockTimespans.a.getStart.and.returnValue(10000);
handler.move('a', -10000);
// Verify that move was stopped at 0, for b, even though
// move was initiated at a

View File

@@ -42,7 +42,7 @@ define(
);
mockSwimlane.domainObject = mockDomainObject;
mockObjectLoader.load.andReturn(mockPromise);
mockObjectLoader.load.and.returnValue(mockPromise);
populator = new TimelineDragPopulator(mockObjectLoader);
});

View File

@@ -44,19 +44,19 @@ define(
['toMillis', 'toPixels']
);
mockDragHandler.end.andReturn(12321);
mockDragHandler.end.and.returnValue(12321);
// Echo back the value from snapper for most tests
mockSnapHandler.snap.andCallFake(function (ts) {
mockSnapHandler.snap.and.callFake(function (ts) {
return ts;
});
// Double pixels to get millis, for test purposes
mockZoomController.toMillis.andCallFake(function (px) {
mockZoomController.toMillis.and.callFake(function (px) {
return px * 2;
});
mockZoomController.toPixels.andCallFake(function (ms) {
mockZoomController.toPixels.and.callFake(function (ms) {
return ms / 2;
});
@@ -88,7 +88,7 @@ define(
});
it("snaps drags to other end points", function () {
mockSnapHandler.snap.andReturn(42);
mockSnapHandler.snap.and.returnValue(42);
handle.begin();
handle.drag(-10, mockZoomController);
// Should have used snap-to timestamp

View File

@@ -44,21 +44,21 @@ define(
['toMillis', 'toPixels']
);
mockDragHandler.start.andReturn(12321);
mockDragHandler.duration.andReturn(4200);
mockDragHandler.end.andReturn(12321 + 4200);
mockDragHandler.start.and.returnValue(12321);
mockDragHandler.duration.and.returnValue(4200);
mockDragHandler.end.and.returnValue(12321 + 4200);
// Echo back the value from snapper for most tests
mockSnapHandler.snap.andCallFake(function (ts) {
mockSnapHandler.snap.and.callFake(function (ts) {
return ts;
});
// Double pixels to get millis, for test purposes
mockZoomController.toMillis.andCallFake(function (px) {
mockZoomController.toMillis.and.callFake(function (px) {
return px * 2;
});
mockZoomController.toPixels.andCallFake(function (ms) {
mockZoomController.toPixels.and.callFake(function (ms) {
return ms / 2;
});
@@ -100,8 +100,8 @@ define(
);
// Reflect the change from the drag handler
mockDragHandler.start.andReturn(12521);
mockDragHandler.end.andReturn(12521 + 4200);
mockDragHandler.start.and.returnValue(12521);
mockDragHandler.end.and.returnValue(12521 + 4200);
// ....followed by a +100 ms change.
handle.drag(150, mockZoomController);
@@ -112,7 +112,7 @@ define(
});
it("snaps drags to other end points", function () {
mockSnapHandler.snap.andCallFake(function (ts) {
mockSnapHandler.snap.and.callFake(function (ts) {
return ts + 10;
});
handle.begin();
@@ -129,7 +129,7 @@ define(
handle.begin();
expect(mockSnapHandler.snap).not.toHaveBeenCalled();
handle.drag(100, mockZoomController);
expect(mockSnapHandler.snap.calls.length).toEqual(2);
expect(mockSnapHandler.snap.calls.count()).toEqual(2);
});
it("chooses the closest snap-to location", function () {
@@ -139,7 +139,7 @@ define(
// regardless of whether it is the start/end (which
// will vary based on the initial state of this toggle.)
var toggle = false;
mockSnapHandler.snap.andCallFake(function (ts) {
mockSnapHandler.snap.and.callFake(function (ts) {
toggle = !toggle;
return ts + (toggle ? -5 : 10);
});
@@ -151,8 +151,8 @@ define(
);
// Reflect the change from the drag handler
mockDragHandler.start.andReturn(12521 - 5);
mockDragHandler.end.andReturn(12521 + 4200 - 5);
mockDragHandler.start.and.returnValue(12521 - 5);
mockDragHandler.end.and.returnValue(12521 + 4200 - 5);
toggle = true; // Change going-in state
handle.drag(300, mockZoomController);

View File

@@ -37,11 +37,11 @@ define(
['start', 'end', 'ids']
);
mockDragHandler.ids.andReturn(['a', 'b', 'c', 'd']);
mockDragHandler.start.andCallFake(function (id) {
mockDragHandler.ids.and.returnValue(['a', 'b', 'c', 'd']);
mockDragHandler.start.and.callFake(function (id) {
return starts[id];
});
mockDragHandler.end.andCallFake(function (id) {
mockDragHandler.end.and.callFake(function (id) {
return ends[id];
});

View File

@@ -44,19 +44,19 @@ define(
['toMillis', 'toPixels']
);
mockDragHandler.start.andReturn(12321);
mockDragHandler.start.and.returnValue(12321);
// Echo back the value from snapper for most tests
mockSnapHandler.snap.andCallFake(function (ts) {
mockSnapHandler.snap.and.callFake(function (ts) {
return ts;
});
// Double pixels to get millis, for test purposes
mockZoomController.toMillis.andCallFake(function (px) {
mockZoomController.toMillis.and.callFake(function (px) {
return px * 2;
});
mockZoomController.toPixels.andCallFake(function (ms) {
mockZoomController.toPixels.and.callFake(function (ms) {
return ms / 2;
});
@@ -87,7 +87,7 @@ define(
});
it("snaps drags to other end points", function () {
mockSnapHandler.snap.andReturn(42);
mockSnapHandler.snap.and.returnValue(42);
handle.begin();
handle.drag(-10, mockZoomController);
// Should have used snap-to timestamp