mirror of
https://github.com/nasa/openmct.git
synced 2025-06-18 15:18:12 +00:00
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
@ -43,7 +43,7 @@ define(
|
||||
mockBounds;
|
||||
|
||||
function getCallback(target, event) {
|
||||
return target.calls.filter(function (call) {
|
||||
return target.calls.all().filter(function (call) {
|
||||
return call.args[0] === event;
|
||||
})[0].args[1];
|
||||
}
|
||||
@ -60,8 +60,8 @@ define(
|
||||
"off",
|
||||
"timeSystem"
|
||||
]);
|
||||
mockConductor.bounds.andReturn(mockBounds);
|
||||
mockConductor.clock.andReturn(undefined);
|
||||
mockConductor.bounds.and.returnValue(mockBounds);
|
||||
mockConductor.clock.and.returnValue(undefined);
|
||||
|
||||
mockDomainObject = jasmine.createSpyObj("domainObject", [
|
||||
"getModel",
|
||||
@ -69,9 +69,9 @@ define(
|
||||
"useCapability",
|
||||
"hasCapability"
|
||||
]);
|
||||
mockDomainObject.getModel.andReturn({});
|
||||
mockDomainObject.getId.andReturn("mockId");
|
||||
mockDomainObject.useCapability.andReturn(true);
|
||||
mockDomainObject.getModel.and.returnValue({});
|
||||
mockDomainObject.getId.and.returnValue("mockId");
|
||||
mockDomainObject.useCapability.and.returnValue(true);
|
||||
|
||||
mockCompositionAPI = jasmine.createSpyObj("compositionAPI", [
|
||||
"get"
|
||||
@ -81,7 +81,7 @@ define(
|
||||
"observe"
|
||||
]);
|
||||
unobserve = jasmine.createSpy("unobserve");
|
||||
mockObjectAPI.observe.andReturn(unobserve);
|
||||
mockObjectAPI.observe.and.returnValue(unobserve);
|
||||
|
||||
mockScope = jasmine.createSpyObj("scope", [
|
||||
"$on",
|
||||
@ -99,9 +99,14 @@ define(
|
||||
"limitEvaluator",
|
||||
"getValueFormatter"
|
||||
]);
|
||||
mockTelemetryAPI.commonValuesForHints.andReturn([]);
|
||||
mockTelemetryAPI.request.andReturn(Promise.resolve([]));
|
||||
mockTelemetryAPI.getValueFormatter.andCallFake(function (metadata) {
|
||||
mockTelemetryAPI.commonValuesForHints.and.returnValue([]);
|
||||
mockTelemetryAPI.request.and.returnValue(Promise.resolve([]));
|
||||
mockTelemetryAPI.getMetadata.and.returnValue({
|
||||
values: function () {
|
||||
return [];
|
||||
}
|
||||
});
|
||||
mockTelemetryAPI.getValueFormatter.and.callFake(function (metadata) {
|
||||
var formatter = jasmine.createSpyObj(
|
||||
'telemetryFormatter:' + metadata.key,
|
||||
[
|
||||
@ -112,19 +117,15 @@ define(
|
||||
var getter = function (datum) {
|
||||
return datum[metadata.key];
|
||||
};
|
||||
formatter.format.andCallFake(getter);
|
||||
formatter.parse.andCallFake(getter);
|
||||
formatter.format.and.callFake(getter);
|
||||
formatter.parse.and.callFake(getter);
|
||||
return formatter;
|
||||
});
|
||||
mockTelemetryAPI.getMetadata.andReturn({
|
||||
values: function () {
|
||||
return [];
|
||||
}
|
||||
});
|
||||
mockTelemetryAPI.isTelemetryObject.andReturn(false);
|
||||
|
||||
mockTelemetryAPI.isTelemetryObject.and.returnValue(false);
|
||||
|
||||
mockTimeout = jasmine.createSpy("timeout");
|
||||
mockTimeout.andReturn(1); // Return something
|
||||
mockTimeout.and.returnValue(1); // Return something
|
||||
mockTimeout.cancel = jasmine.createSpy("cancel");
|
||||
|
||||
mockAPI = {
|
||||
@ -141,7 +142,7 @@ define(
|
||||
controller.registerChangeListeners();
|
||||
});
|
||||
it('object mutation', function () {
|
||||
var calledObject = mockObjectAPI.observe.mostRecentCall.args[0];
|
||||
var calledObject = mockObjectAPI.observe.calls.mostRecent().args[0];
|
||||
|
||||
expect(mockObjectAPI.observe).toHaveBeenCalled();
|
||||
expect(calledObject.identifier.key).toEqual(mockDomainObject.getId());
|
||||
@ -197,13 +198,13 @@ define(
|
||||
};
|
||||
|
||||
unsubscribe = jasmine.createSpy("unsubscribe");
|
||||
mockTelemetryAPI.subscribe.andReturn(unsubscribe);
|
||||
mockTelemetryAPI.subscribe.and.returnValue(unsubscribe);
|
||||
|
||||
mockChildren = [mockTelemetryObject];
|
||||
mockComposition.load.andReturn(Promise.resolve(mockChildren));
|
||||
mockCompositionAPI.get.andReturn(mockComposition);
|
||||
mockComposition.load.and.returnValue(Promise.resolve(mockChildren));
|
||||
mockCompositionAPI.get.and.returnValue(mockComposition);
|
||||
|
||||
mockTelemetryAPI.isTelemetryObject.andCallFake(function (obj) {
|
||||
mockTelemetryAPI.isTelemetryObject.and.callFake(function (obj) {
|
||||
return obj.identifier.key === mockTelemetryObject.identifier.key;
|
||||
});
|
||||
|
||||
@ -211,28 +212,13 @@ define(
|
||||
});
|
||||
|
||||
it('fetches historical data for the time period specified by the conductor bounds', function () {
|
||||
controller.getData().then(function () {
|
||||
done = true;
|
||||
});
|
||||
waitsFor(function () {
|
||||
return done;
|
||||
}, "getData to return", 100);
|
||||
|
||||
runs(function () {
|
||||
return controller.getData().then(function () {
|
||||
expect(mockTelemetryAPI.request).toHaveBeenCalledWith(mockTelemetryObject, mockBounds);
|
||||
});
|
||||
});
|
||||
|
||||
it('unsubscribes on view destruction', function () {
|
||||
controller.getData().then(function () {
|
||||
done = true;
|
||||
});
|
||||
|
||||
waitsFor(function () {
|
||||
return done;
|
||||
}, "getData to return", 100);
|
||||
|
||||
runs(function () {
|
||||
return controller.getData().then(function () {
|
||||
var destroy = getCallback(mockScope.$on, "$destroy");
|
||||
destroy();
|
||||
|
||||
@ -240,40 +226,19 @@ define(
|
||||
});
|
||||
});
|
||||
it('fetches historical data for the time period specified by the conductor bounds', function () {
|
||||
controller.getData().then(function () {
|
||||
done = true;
|
||||
});
|
||||
waitsFor(function () {
|
||||
return done;
|
||||
}, "getData to return", 100);
|
||||
|
||||
runs(function () {
|
||||
return controller.getData().then(function () {
|
||||
expect(mockTelemetryAPI.request).toHaveBeenCalledWith(mockTelemetryObject, mockBounds);
|
||||
});
|
||||
});
|
||||
|
||||
it('fetches data for, and subscribes to parent object if it is a telemetry object', function () {
|
||||
controller.getData().then(function () {
|
||||
done = true;
|
||||
});
|
||||
waitsFor(function () {
|
||||
return done;
|
||||
}, "getData to return", 100);
|
||||
|
||||
runs(function () {
|
||||
return controller.getData().then(function () {
|
||||
expect(mockTelemetryAPI.subscribe).toHaveBeenCalledWith(mockTelemetryObject, jasmine.any(Function), {});
|
||||
expect(mockTelemetryAPI.request).toHaveBeenCalledWith(mockTelemetryObject, jasmine.any(Object));
|
||||
});
|
||||
});
|
||||
it('fetches data for, and subscribes to parent object if it is a telemetry object', function () {
|
||||
controller.getData().then(function () {
|
||||
done = true;
|
||||
});
|
||||
waitsFor(function () {
|
||||
return done;
|
||||
}, "getData to return", 100);
|
||||
|
||||
runs(function () {
|
||||
return controller.getData().then(function () {
|
||||
expect(mockTelemetryAPI.subscribe).toHaveBeenCalledWith(mockTelemetryObject, jasmine.any(Function), {});
|
||||
expect(mockTelemetryAPI.request).toHaveBeenCalledWith(mockTelemetryObject, jasmine.any(Object));
|
||||
});
|
||||
@ -289,9 +254,9 @@ define(
|
||||
{name: "child 4"}
|
||||
];
|
||||
mockChildren = mockChildren.concat(mockTelemetryChildren);
|
||||
mockComposition.load.andReturn(Promise.resolve(mockChildren));
|
||||
mockComposition.load.and.returnValue(Promise.resolve(mockChildren));
|
||||
|
||||
mockTelemetryAPI.isTelemetryObject.andCallFake(function (object) {
|
||||
mockTelemetryAPI.isTelemetryObject.and.callFake(function (object) {
|
||||
if (object === mockTelemetryObject) {
|
||||
return false;
|
||||
} else {
|
||||
@ -299,15 +264,7 @@ define(
|
||||
}
|
||||
});
|
||||
|
||||
controller.getData().then(function () {
|
||||
done = true;
|
||||
});
|
||||
|
||||
waitsFor(function () {
|
||||
return done;
|
||||
}, "getData to return", 100);
|
||||
|
||||
runs(function () {
|
||||
return controller.getData().then(function () {
|
||||
mockTelemetryChildren.forEach(function (child) {
|
||||
expect(mockTelemetryAPI.subscribe).toHaveBeenCalledWith(child, jasmine.any(Function), {});
|
||||
});
|
||||
@ -364,13 +321,13 @@ define(
|
||||
key: "column1"
|
||||
};
|
||||
|
||||
mockTelemetryAPI.commonValuesForHints.andCallFake(function (metadata, hints) {
|
||||
mockTelemetryAPI.commonValuesForHints.and.callFake(function (metadata, hints) {
|
||||
if (_.eq(hints, ["domain"])) {
|
||||
return domainMetadata;
|
||||
}
|
||||
});
|
||||
|
||||
mockTelemetryAPI.getMetadata.andReturn({
|
||||
mockTelemetryAPI.getMetadata.and.returnValue({
|
||||
values: function () {
|
||||
return allMetadata;
|
||||
}
|
||||
@ -409,21 +366,21 @@ define(
|
||||
"column3": 9
|
||||
}
|
||||
];
|
||||
|
||||
controller.batchSize = 2;
|
||||
mockTelemetryAPI.request.andReturn(Promise.resolve(mockHistoricalData));
|
||||
mockTelemetryAPI.request.and.returnValue(Promise.resolve(mockHistoricalData));
|
||||
controller.getHistoricalData([mockDomainObject]);
|
||||
|
||||
waitsFor(function () {
|
||||
return !!controller.timeoutHandle;
|
||||
}, "first batch to be processed", 100);
|
||||
|
||||
runs(function () {
|
||||
//Verify that timeout is being used to yield process
|
||||
expect(mockTimeout).toHaveBeenCalled();
|
||||
mockTimeout.mostRecentCall.args[0]();
|
||||
expect(mockTimeout.calls.length).toBe(2);
|
||||
mockTimeout.mostRecentCall.args[0]();
|
||||
return new Promise(function (resolve) {
|
||||
mockTimeout.and.callFake(function () {
|
||||
resolve();
|
||||
});
|
||||
}).then(function () {
|
||||
mockTimeout.calls.mostRecent().args[0]();
|
||||
expect(mockTimeout.calls.count()).toBe(2);
|
||||
mockTimeout.calls.mostRecent().args[0]();
|
||||
expect(mockScope.rows.length).toBe(3);
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -435,7 +392,7 @@ define(
|
||||
{"column3": "value 3"}
|
||||
];
|
||||
|
||||
spyOn(controller.telemetry, "on").andCallThrough();
|
||||
spyOn(controller.telemetry, "on").and.callThrough();
|
||||
|
||||
controller.registerChangeListeners();
|
||||
expect(controller.telemetry.on).toHaveBeenCalledWith("discarded", jasmine.any(Function));
|
||||
@ -453,10 +410,10 @@ define(
|
||||
mockScope.rows = [{ a: -1 }];
|
||||
expectedRows = mockScope.rows.concat(testRows);
|
||||
|
||||
spyOn(controller.telemetry, "on").andCallThrough();
|
||||
spyOn(controller.telemetry, "on").and.callThrough();
|
||||
controller.registerChangeListeners();
|
||||
|
||||
controller.telemetry.on.calls.forEach(function (call) {
|
||||
controller.telemetry.on.calls.all().forEach(function (call) {
|
||||
if (call.args[0] === 'added') {
|
||||
call.args[1](testRows);
|
||||
}
|
||||
|
Reference in New Issue
Block a user