mirror of
https://github.com/nasa/openmct.git
synced 2025-06-06 09:21:43 +00:00
[Timeline] Add tests for timeline zoom changes
This commit is contained in:
parent
757da1dff4
commit
eb5566f041
@ -66,7 +66,7 @@ define(
|
|||||||
var duration = timespan.getDuration();
|
var duration = timespan.getDuration();
|
||||||
zoomIndex = 0;
|
zoomIndex = 0;
|
||||||
while (toMillis(bounds.width) < duration &&
|
while (toMillis(bounds.width) < duration &&
|
||||||
zoomIndex < zoomLevels.length) {
|
zoomIndex < zoomLevels.length - 1) {
|
||||||
zoomIndex += 1;
|
zoomIndex += 1;
|
||||||
}
|
}
|
||||||
bounds.x = toPixels(timespan.getStart());
|
bounds.x = toPixels(timespan.getStart());
|
||||||
|
@ -32,11 +32,7 @@ define(
|
|||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
testConfiguration = {
|
testConfiguration = {
|
||||||
levels: [
|
levels: [ 1000, 2000, 3500 ],
|
||||||
1000,
|
|
||||||
2000,
|
|
||||||
3500
|
|
||||||
],
|
|
||||||
width: 12321
|
width: 12321
|
||||||
};
|
};
|
||||||
mockScope = jasmine.createSpyObj("$scope", ['$watch']);
|
mockScope = jasmine.createSpyObj("$scope", ['$watch']);
|
||||||
@ -74,6 +70,63 @@ define(
|
|||||||
expect(controller.zoom()).toEqual(3500);
|
expect(controller.zoom()).toEqual(3500);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("observes scroll bounds", function () {
|
||||||
|
expect(mockScope.$watch)
|
||||||
|
.toHaveBeenCalledWith("scroll", jasmine.any(Function));
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("when watches have fired", function () {
|
||||||
|
var mockDomainObject,
|
||||||
|
mockPromise,
|
||||||
|
mockTimespan,
|
||||||
|
testStart,
|
||||||
|
testEnd;
|
||||||
|
|
||||||
|
beforeEach(function () {
|
||||||
|
testStart = 3000;
|
||||||
|
testEnd = 5500;
|
||||||
|
|
||||||
|
mockDomainObject = jasmine.createSpyObj('domainObject', [
|
||||||
|
'getId',
|
||||||
|
'getModel',
|
||||||
|
'getCapability',
|
||||||
|
'useCapability'
|
||||||
|
]);
|
||||||
|
mockPromise = jasmine.createSpyObj('promise', ['then']);
|
||||||
|
mockTimespan = jasmine.createSpyObj('timespan', [
|
||||||
|
'getStart',
|
||||||
|
'getEnd',
|
||||||
|
'getDuration'
|
||||||
|
]);
|
||||||
|
|
||||||
|
mockDomainObject.useCapability.andCallFake(function (c) {
|
||||||
|
return c === 'timespan' && mockPromise;
|
||||||
|
});
|
||||||
|
mockPromise.then.andCallFake(function (callback) {
|
||||||
|
callback(mockTimespan);
|
||||||
|
});
|
||||||
|
mockTimespan.getStart.andReturn(testStart);
|
||||||
|
mockTimespan.getEnd.andReturn(testEnd);
|
||||||
|
mockTimespan.getDuration.andReturn(testEnd - testStart);
|
||||||
|
|
||||||
|
mockScope.scroll = { x: 0, width: 20000 };
|
||||||
|
mockScope.domainObject = mockDomainObject;
|
||||||
|
|
||||||
|
mockScope.$watch.calls.forEach(function (call) {
|
||||||
|
call.args[1](mockScope[call.args[0]]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("zooms to fit the timeline", function () {
|
||||||
|
var x1 = mockScope.scroll.x,
|
||||||
|
x2 = mockScope.scroll.x + mockScope.scroll.width;
|
||||||
|
expect(Math.round(controller.toMillis(x1)))
|
||||||
|
.toEqual(testStart);
|
||||||
|
expect(Math.round(controller.toMillis(x2)))
|
||||||
|
.toBeGreaterThan(testEnd);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user