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

@@ -112,7 +112,7 @@ define(
mockDomainObjectCapability = jasmine.createSpyObj('capability',
['inEditContext', 'listen']
);
mockDomainObjectCapability.listen.andReturn(unlistenFunc);
mockDomainObjectCapability.listen.and.returnValue(unlistenFunc);
mockCompositionCapability = mockPromise(mockCompositionObjects);
@@ -132,12 +132,12 @@ define(
'off',
'get'
]);
mockSelection.get.andReturn(selectable);
mockSelection.get.and.returnValue(selectable);
mockObjects = jasmine.createSpyObj('objects', [
'get'
]);
mockObjects.get.andReturn(mockPromise(mockDomainObject("mockObject")));
mockObjects.get.and.returnValue(mockPromise(mockDomainObject("mockObject")));
mockOpenMCT = {
selection: mockSelection,
objects: mockObjects
@@ -147,17 +147,18 @@ define(
$(document).find('body').append($element);
spyOn($element[0], 'click');
spyOn(mockScope.domainObject, "useCapability").andCallThrough();
spyOn(mockScope.domainObject, "useCapability").and.callThrough();
controller = new LayoutController(mockScope, $element, mockOpenMCT);
spyOn(controller, "layoutPanels").andCallThrough();
spyOn(controller, "layoutPanels").and.callThrough();
spyOn(controller, "commit");
jasmine.Clock.useMock();
jasmine.clock().install();
});
afterEach(function () {
$element.remove();
jasmine.clock().uninstall();
});
@@ -174,7 +175,7 @@ define(
jasmine.any(Function)
);
mockScope.$on.calls[0].args[1]();
mockScope.$on.calls.all()[0].args[1]();
expect(mockOpenMCT.selection.off).toHaveBeenCalledWith(
'change',
@@ -192,7 +193,7 @@ define(
});
it("Retrieves updated composition from composition capability", function () {
mockScope.$watchCollection.mostRecentCall.args[1]();
mockScope.$watchCollection.calls.mostRecent().args[1]();
expect(mockScope.domainObject.useCapability).toHaveBeenCalledWith(
"composition"
);
@@ -208,11 +209,11 @@ define(
secondCompositionCB;
spyOn(mockCompositionCapability, "then");
mockScope.$watchCollection.mostRecentCall.args[1]();
mockScope.$watchCollection.mostRecentCall.args[1]();
mockScope.$watchCollection.calls.mostRecent().args[1]();
mockScope.$watchCollection.calls.mostRecent().args[1]();
firstCompositionCB = mockCompositionCapability.then.calls[0].args[0];
secondCompositionCB = mockCompositionCapability.then.calls[1].args[0];
firstCompositionCB = mockCompositionCapability.then.calls.all()[0].args[0];
secondCompositionCB = mockCompositionCapability.then.calls.all()[1].args[0];
//Resolve promises in reverse order
secondCompositionCB(secondMockCompositionObjects);
@@ -226,7 +227,7 @@ define(
it("provides styles for frames, from configuration", function () {
mockScope.$watchCollection.mostRecentCall.args[1]();
mockScope.$watchCollection.calls.mostRecent().args[1]();
expect(controller.getFrameStyle("a")).toEqual({
top: "320px",
left: "640px",
@@ -241,7 +242,7 @@ define(
var styleB, styleC;
// b and c do not have configured positions
mockScope.$watchCollection.mostRecentCall.args[1]();
mockScope.$watchCollection.calls.mostRecent().args[1]();
styleB = controller.getFrameStyle("b");
styleC = controller.getFrameStyle("c");
@@ -258,7 +259,7 @@ define(
it("allows panels to be dragged", function () {
// Populate scope
mockScope.$watchCollection.mostRecentCall.args[1]();
mockScope.$watchCollection.calls.mostRecent().args[1]();
// Verify precondition
expect(testConfiguration.panels.b).not.toBeDefined();
@@ -277,7 +278,7 @@ define(
it("invokes commit after drag", function () {
// Populate scope
mockScope.$watchCollection.mostRecentCall.args[1]();
mockScope.$watchCollection.calls.mostRecent().args[1]();
// Do a drag
controller.startDrag("b", [1, 1], [0, 0]);
@@ -300,7 +301,7 @@ define(
expect(testConfiguration.panels.d).not.toBeDefined();
// Notify that a drop occurred
mockScope.$on.mostRecentCall.args[1](
mockScope.$on.calls.mostRecent().args[1](
mockEvent,
'd',
{ x: 300, y: 100 }
@@ -315,7 +316,7 @@ define(
mockEvent.defaultPrevented = true;
// Notify that a drop occurred
mockScope.$on.mostRecentCall.args[1](
mockScope.$on.calls.mostRecent().args[1](
mockEvent,
'd',
{ x: 300, y: 100 }
@@ -330,8 +331,8 @@ define(
testModel.layoutGrid = [1, 1];
// White-boxy; we know which watch is which
mockScope.$watch.calls[0].args[1](testModel.layoutGrid);
mockScope.$watchCollection.calls[0].args[1](testModel.composition);
mockScope.$watch.calls.all()[0].args[1](testModel.layoutGrid);
mockScope.$watchCollection.calls.all()[0].args[1](testModel.composition);
styleB = controller.getFrameStyle("b");
@@ -345,7 +346,7 @@ define(
// Start with a very small frame size
testModel.layoutGrid = [1, 1];
mockScope.$watch.calls[0].args[1](testModel.layoutGrid);
mockScope.$watch.calls.all()[0].args[1](testModel.layoutGrid);
// Add a new object to the composition
mockComposition = ["a", "b", "c", "d"];
@@ -353,7 +354,7 @@ define(
mockCompositionCapability = mockPromise(mockCompositionObjects);
// Notify that a drop occurred
mockScope.$on.mostRecentCall.args[1](
mockScope.$on.calls.mostRecent().args[1](
mockEvent,
'd',
{ x: 300, y: 100 }
@@ -369,14 +370,14 @@ define(
it("updates positions of existing objects on a drop", function () {
var oldStyle;
mockScope.$watchCollection.mostRecentCall.args[1]();
mockScope.$watchCollection.calls.mostRecent().args[1]();
oldStyle = controller.getFrameStyle("b");
expect(oldStyle).toBeDefined();
// ...drop event...
mockScope.$on.mostRecentCall
mockScope.$on.calls.mostRecent()
.args[1](mockEvent, 'b', { x: 300, y: 100 });
expect(controller.getFrameStyle("b"))
@@ -384,16 +385,16 @@ define(
});
it("allows objects to be selected", function () {
mockScope.$watchCollection.mostRecentCall.args[1]();
mockScope.$watchCollection.calls.mostRecent().args[1]();
var childObj = mockCompositionObjects[0];
selectable[0].context.oldItem = childObj;
mockOpenMCT.selection.on.mostRecentCall.args[1](selectable);
mockOpenMCT.selection.on.calls.mostRecent().args[1](selectable);
expect(controller.selected(childObj)).toBe(true);
});
it("prevents event bubbling while drag is in progress", function () {
mockScope.$watchCollection.mostRecentCall.args[1]();
mockScope.$watchCollection.calls.mostRecent().args[1]();
var childObj = mockCompositionObjects[0];
// Do a drag
@@ -407,57 +408,57 @@ define(
expect(mockEvent.stopPropagation).toHaveBeenCalled();
// Shoud be able to select another object when dragging is done.
jasmine.Clock.tick(0);
mockEvent.stopPropagation.reset();
jasmine.clock().tick(0);
mockEvent.stopPropagation.calls.reset();
controller.bypassSelection(mockEvent);
expect(mockEvent.stopPropagation).not.toHaveBeenCalled();
});
it("shows frames by default", function () {
mockScope.$watchCollection.mostRecentCall.args[1]();
mockScope.$watchCollection.calls.mostRecent().args[1]();
expect(controller.hasFrame(mockCompositionObjects[0])).toBe(true);
});
it("hyperlinks hide frame by default", function () {
mockScope.$watchCollection.mostRecentCall.args[1]();
mockScope.$watchCollection.calls.mostRecent().args[1]();
expect(controller.hasFrame(mockCompositionObjects[1])).toBe(false);
});
it("selects the parent object when selected object is removed", function () {
mockScope.$watchCollection.mostRecentCall.args[1]();
mockScope.$watchCollection.calls.mostRecent().args[1]();
var childObj = mockCompositionObjects[0];
selectable[0].context.oldItem = childObj;
mockOpenMCT.selection.on.mostRecentCall.args[1](selectable);
mockOpenMCT.selection.on.calls.mostRecent().args[1](selectable);
var composition = ["b", "c"];
mockScope.$watchCollection.mostRecentCall.args[1](composition);
mockScope.$watchCollection.calls.mostRecent().args[1](composition);
expect($element[0].click).toHaveBeenCalled();
});
it("allows objects to be drilled-in only when editing", function () {
mockScope.$watchCollection.mostRecentCall.args[1]();
mockScope.$watchCollection.calls.mostRecent().args[1]();
var childObj = mockCompositionObjects[0];
childObj.getCapability().inEditContext.andReturn(false);
childObj.getCapability().inEditContext.and.returnValue(false);
controller.drill(mockEvent, childObj);
expect(controller.isDrilledIn(childObj)).toBe(false);
});
it("allows objects to be drilled-in only if it has sub objects", function () {
mockScope.$watchCollection.mostRecentCall.args[1]();
mockScope.$watchCollection.calls.mostRecent().args[1]();
var childObj = mockCompositionObjects[1];
childObj.getCapability().inEditContext.andReturn(true);
childObj.getCapability().inEditContext.and.returnValue(true);
controller.drill(mockEvent, childObj);
expect(controller.isDrilledIn(childObj)).toBe(false);
});
it("selects a newly-dropped object", function () {
mockScope.$on.mostRecentCall.args[1](
mockScope.$on.calls.mostRecent().args[1](
mockEvent,
'd',
{ x: 300, y: 100 }
@@ -469,7 +470,7 @@ define(
spyOn(testElement[0], 'click');
controller.selectIfNew('some-id', childObj);
jasmine.Clock.tick(0);
jasmine.clock().tick(0);
expect(testElement[0].click).toHaveBeenCalled();
});