[Imagery] Update spec

This commit is contained in:
Pete Richards 2017-06-21 14:56:51 -07:00
parent bbeb97e93c
commit 73e452edc0
2 changed files with 77 additions and 57 deletions

View File

@ -141,4 +141,3 @@ define(
return ImageryController; return ImageryController;
} }
); );

View File

@ -30,10 +30,10 @@ define(
oldDomainObject, oldDomainObject,
newDomainObject, newDomainObject,
unsubscribe, unsubscribe,
callback,
metadata, metadata,
prefix, prefix,
controller; controller,
hasLoaded;
beforeEach(function () { beforeEach(function () {
$scope = jasmine.createSpyObj('$scope', ['$on', '$watch']); $scope = jasmine.createSpyObj('$scope', ['$on', '$watch']);
@ -53,6 +53,7 @@ define(
]), ]),
telemetry: jasmine.createSpyObj('telemetryAPI', [ telemetry: jasmine.createSpyObj('telemetryAPI', [
'subscribe', 'subscribe',
'request',
'getValueFormatter', 'getValueFormatter',
'getMetadata' 'getMetadata'
]) ])
@ -79,14 +80,30 @@ define(
}); });
return formatter; return formatter;
}); });
hasLoaded = false;
openmct.telemetry.request.andCallFake(function () {
setTimeout(function () {
hasLoaded = true;
}, 10);
return Promise.resolve([{
timestamp: 1434600258123,
value: 'some/url'
}]);
});
metadata.value.andReturn("timestamp"); metadata.value.andReturn("timestamp");
metadata.valuesForHints.andReturn(["value"]); metadata.valuesForHints.andReturn(["value"]);
controller = new ImageryController($scope, openmct); controller = new ImageryController($scope, openmct);
});
describe("when loaded", function () {
var callback;
beforeEach(function () {
waitsFor(function () { waitsFor(function () {
return openmct.telemetry.subscribe.calls.length > 0; return hasLoaded;
}, 100); }, 500);
runs(function () { runs(function () {
callback = callback =
@ -94,6 +111,53 @@ define(
}); });
}); });
it("uses LAD telemetry", function () {
expect(openmct.telemetry.request).toHaveBeenCalledWith(
newDomainObject,
{
strategy: 'latest',
size: 1
}
);
expect(controller.getTime()).toEqual(prefix + 1434600258123);
expect(controller.getImageUrl()).toEqual('some/url');
});
it("exposes the latest telemetry values", function () {
callback({
timestamp: 1434600259456,
value: "some/other/url"
});
expect(controller.getTime()).toEqual(prefix + 1434600259456);
expect(controller.getImageUrl()).toEqual("some/other/url");
});
it("allows updates to be paused and unpaused", function () {
var newTimestamp = 1434600259456,
newUrl = "some/other/url",
initialTimestamp = controller.getTime(),
initialUrl = controller.getImageUrl();
expect(initialTimestamp).not.toBe(prefix + newTimestamp);
expect(initialUrl).not.toBe(newUrl);
expect(controller.paused()).toBeFalsy();
controller.paused(true);
expect(controller.paused()).toBeTruthy();
callback({ timestamp: newTimestamp, value: newUrl });
expect(controller.getTime()).toEqual(initialTimestamp);
expect(controller.getImageUrl()).toEqual(initialUrl);
controller.paused(false);
expect(controller.paused()).toBeFalsy();
expect(controller.getTime()).toEqual(prefix + newTimestamp);
expect(controller.getImageUrl()).toEqual(newUrl);
});
it("subscribes to telemetry", function () { it("subscribes to telemetry", function () {
expect(openmct.telemetry.subscribe).toHaveBeenCalledWith( expect(openmct.telemetry.subscribe).toHaveBeenCalledWith(
newDomainObject, newDomainObject,
@ -104,7 +168,6 @@ define(
it("unsubscribes when scope is destroyed", function () { it("unsubscribes when scope is destroyed", function () {
expect(unsubscribe).not.toHaveBeenCalled(); expect(unsubscribe).not.toHaveBeenCalled();
// Find the $destroy listener and call it
$scope.$on.calls.forEach(function (call) { $scope.$on.calls.forEach(function (call) {
if (call.args[0] === '$destroy') { if (call.args[0] === '$destroy') {
call.args[1](); call.args[1]();
@ -112,51 +175,9 @@ define(
}); });
expect(unsubscribe).toHaveBeenCalled(); expect(unsubscribe).toHaveBeenCalled();
}); });
it("exposes the latest telemetry values", function () {
// 06/18/2015 4:04am UTC
var testTimestamp = 1434600258123,
testUrl = "some/url",
nextTimestamp = 1434600259456, // 4:05.456
nextUrl = "some/other/url";
// Call back with telemetry data
callback({ timestamp: testTimestamp, value: testUrl });
expect(controller.getTime()).toEqual(prefix + testTimestamp);
expect(controller.getImageUrl()).toEqual(testUrl);
callback({ timestamp: nextTimestamp, value: nextUrl });
expect(controller.getTime()).toEqual(prefix + nextTimestamp);
expect(controller.getImageUrl()).toEqual(nextUrl);
});
it("allows updates to be paused", function () {
// 06/18/2015 4:04am UTC
var testTimestamp = 1434600258123,
testUrl = "some/url",
nextTimestamp = 1434600259456, // 4:05.456
nextUrl = "some/other/url";
// Call back with telemetry data
callback({ timestamp: testTimestamp, value: testUrl });
expect(controller.getTime()).toEqual(prefix + testTimestamp);
expect(controller.getImageUrl()).toEqual(testUrl);
expect(controller.paused()).toBeFalsy();
controller.paused(true); // Pause!
expect(controller.paused()).toBeTruthy();
callback({ timestamp: nextTimestamp, value: nextUrl });
expect(controller.getTime()).toEqual(prefix + testTimestamp);
expect(controller.getImageUrl()).toEqual(testUrl);
}); });
it("initially shows an empty string for date/time", function () { it("initially shows an empty string for date/time", function () {
// Do not invoke callback...
expect(controller.getTime()).toEqual(""); expect(controller.getTime()).toEqual("");
expect(controller.getImageUrl()).toEqual(""); expect(controller.getImageUrl()).toEqual("");
}); });