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
@@ -59,15 +59,15 @@ define(
|
||||
);
|
||||
|
||||
mockActionContext = {domainObject: mockDomainObject, event: mockEvent};
|
||||
mockDomainObject.getCapability.andReturn(mockContextMenuAction);
|
||||
mockContextMenuAction.perform.andReturn(jasmine.any(Function));
|
||||
mockAgentService.isMobile.andReturn(false);
|
||||
mockDomainObject.getCapability.and.returnValue(mockContextMenuAction);
|
||||
mockContextMenuAction.perform.and.returnValue(jasmine.any(Function));
|
||||
mockAgentService.isMobile.and.returnValue(false);
|
||||
|
||||
|
||||
gesture = new ContextMenuGesture(mockTimeout, mockAgentService, mockElement, mockDomainObject);
|
||||
|
||||
// Capture the contextmenu callback
|
||||
fireGesture = mockElement.on.mostRecentCall.args[1];
|
||||
fireGesture = mockElement.on.calls.mostRecent().args[1];
|
||||
});
|
||||
|
||||
it("attaches a callback for context menu events", function () {
|
||||
@@ -86,7 +86,7 @@ define(
|
||||
|
||||
expect(mockElement.off).toHaveBeenCalledWith(
|
||||
"contextmenu",
|
||||
//mockElement.on.mostRecentCall.args[1]
|
||||
//mockElement.on.calls.mostRecent().args[1]
|
||||
mockDomainObject.calls
|
||||
);
|
||||
});
|
||||
@@ -96,15 +96,15 @@ define(
|
||||
mockTouchEvent = jasmine.createSpyObj("event", ["preventDefault", "touches"]);
|
||||
mockTouch = jasmine.createSpyObj("touch", ["length"]);
|
||||
mockTouch.length = 1;
|
||||
mockTouchEvent.touches.andReturn(mockTouch);
|
||||
mockAgentService.isMobile.andReturn(true);
|
||||
mockTouchEvent.touches.and.returnValue(mockTouch);
|
||||
mockAgentService.isMobile.and.returnValue(true);
|
||||
|
||||
// Then create new (mobile) gesture
|
||||
gesture = new ContextMenuGesture(mockTimeout, mockAgentService, mockElement, mockDomainObject);
|
||||
|
||||
// Set calls for the touchstart and touchend gestures
|
||||
fireTouchStartGesture = mockElement.on.calls[1].args[1];
|
||||
fireTouchEndGesture = mockElement.on.mostRecentCall.args[1];
|
||||
fireTouchStartGesture = mockElement.on.calls.all()[1].args[1];
|
||||
fireTouchEndGesture = mockElement.on.calls.mostRecent().args[1];
|
||||
|
||||
// Fire touchstart and expect touch start to begin
|
||||
fireTouchStartGesture(mockTouchEvent);
|
||||
@@ -115,7 +115,7 @@ define(
|
||||
|
||||
// Expect timeout to begin and then fireTouchEnd
|
||||
expect(mockTimeout).toHaveBeenCalled();
|
||||
mockTimeout.mostRecentCall.args[0]();
|
||||
mockTimeout.calls.mostRecent().args[0]();
|
||||
fireTouchEndGesture(mockTouchEvent);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -51,15 +51,15 @@ define(
|
||||
mockDomainObject = jasmine.createSpyObj("domainObject", DOMAIN_OBJECT_METHODS);
|
||||
mockDataTransfer = jasmine.createSpyObj("dataTransfer", ["setData"]);
|
||||
|
||||
mockDomainObject.getId.andReturn(TEST_ID);
|
||||
mockDomainObject.getModel.andReturn({});
|
||||
mockDomainObject.getId.and.returnValue(TEST_ID);
|
||||
mockDomainObject.getModel.and.returnValue({});
|
||||
|
||||
handlers = {};
|
||||
|
||||
gesture = new DragGesture(mockLog, mockDndService, mockElement, mockDomainObject);
|
||||
|
||||
// Look up all handlers registered by the gesture
|
||||
mockElement.on.calls.forEach(function (call) {
|
||||
mockElement.on.calls.all().forEach(function (call) {
|
||||
handlers[call.args[0]] = call.args[1];
|
||||
});
|
||||
});
|
||||
|
||||
@@ -76,21 +76,21 @@ define(
|
||||
mockAction = jasmine.createSpyObj('action', ['getActions']);
|
||||
mockCompose = jasmine.createSpyObj('compose', ['perform']);
|
||||
|
||||
mockDomainObject.getId.andReturn(TEST_ID);
|
||||
mockDomainObject.getModel.andReturn(testModel);
|
||||
mockDomainObject.getCapability.andCallFake(function (c) {
|
||||
mockDomainObject.getId.and.returnValue(TEST_ID);
|
||||
mockDomainObject.getModel.and.returnValue(testModel);
|
||||
mockDomainObject.getCapability.and.callFake(function (c) {
|
||||
return {
|
||||
persistence: mockPersistence,
|
||||
action: mockAction
|
||||
}[c];
|
||||
});
|
||||
mockDomainObject.useCapability.andReturn(true);
|
||||
mockEvent.dataTransfer.getData.andReturn(DROP_ID);
|
||||
mockDomainObject.useCapability.and.returnValue(true);
|
||||
mockEvent.dataTransfer.getData.and.returnValue(DROP_ID);
|
||||
mockElement[0] = mockUnwrappedElement;
|
||||
mockElement.scope.andReturn(mockScope);
|
||||
mockUnwrappedElement.getBoundingClientRect.andReturn(testRect);
|
||||
mockDndService.getData.andReturn(mockDraggedObject);
|
||||
mockAction.getActions.andReturn([mockCompose]);
|
||||
mockElement.scope.and.returnValue(mockScope);
|
||||
mockUnwrappedElement.getBoundingClientRect.and.returnValue(testRect);
|
||||
mockDndService.getData.and.returnValue(mockDraggedObject);
|
||||
mockAction.getActions.and.returnValue([mockCompose]);
|
||||
|
||||
gesture = new DropGesture(
|
||||
mockDndService,
|
||||
@@ -101,7 +101,7 @@ define(
|
||||
|
||||
// Get a reference to all callbacks registered during constructor
|
||||
callbacks = {};
|
||||
mockElement.on.calls.forEach(function (call) {
|
||||
mockElement.on.calls.all().forEach(function (call) {
|
||||
callbacks[call.args[0]] = call.args[1];
|
||||
});
|
||||
});
|
||||
@@ -132,7 +132,7 @@ define(
|
||||
|
||||
it("invokes compose on drop in edit mode", function () {
|
||||
// Set the mockDomainObject to have the editor capability
|
||||
mockDomainObject.hasCapability.andReturn(true);
|
||||
mockDomainObject.hasCapability.and.returnValue(true);
|
||||
|
||||
callbacks.dragover(mockEvent);
|
||||
expect(mockAction.getActions).toHaveBeenCalledWith({
|
||||
@@ -145,9 +145,9 @@ define(
|
||||
|
||||
it("invokes compose on drop in browse mode for folders", function () {
|
||||
// Set the mockDomainObject to not have the editor capability
|
||||
mockDomainObject.hasCapability.andReturn(false);
|
||||
mockDomainObject.hasCapability.and.returnValue(false);
|
||||
// Set the mockDomainObject to have a type of folder
|
||||
mockDomainObject.getModel.andReturn({type: 'folder'});
|
||||
mockDomainObject.getModel.and.returnValue({type: 'folder'});
|
||||
|
||||
callbacks.dragover(mockEvent);
|
||||
expect(mockAction.getActions).toHaveBeenCalledWith({
|
||||
@@ -160,7 +160,7 @@ define(
|
||||
|
||||
it("broadcasts drop position (in edit mode)", function () {
|
||||
// Set the mockDomainObject to have the editor capability
|
||||
mockDomainObject.hasCapability.andReturn(true);
|
||||
mockDomainObject.hasCapability.and.returnValue(true);
|
||||
|
||||
testRect.left = 42;
|
||||
testRect.top = 36;
|
||||
|
||||
@@ -47,7 +47,7 @@ define(
|
||||
GESTURE_KEYS.forEach(function (key) {
|
||||
mockDestroys[key] = jasmine.createSpy("destroy-" + key);
|
||||
mockGestures[key] = jasmine.createSpy("gesture-" + key);
|
||||
mockGestures[key].andReturn({ destroy: mockDestroys[key] });
|
||||
mockGestures[key].and.returnValue({ destroy: mockDestroys[key] });
|
||||
mockGestures[key].key = key;
|
||||
});
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ define(
|
||||
|
||||
mockElement = { someKey: "some value" };
|
||||
|
||||
mockGestureService.attachGestures.andReturn(mockGestureHandle);
|
||||
mockGestureService.attachGestures.and.returnValue(mockGestureHandle);
|
||||
|
||||
representer = new GestureRepresenter(
|
||||
mockGestureService,
|
||||
|
||||
Reference in New Issue
Block a user