mirror of
https://github.com/nasa/openmct.git
synced 2025-06-13 12:48:14 +00:00
[Switcher] Initialize on timeout
Initialize view switcher state on a timeout; this avoids infinite digest cycles when deeply-nesting views. WTD-689.
This commit is contained in:
@ -10,12 +10,15 @@ define(
|
||||
|
||||
describe("The view switcher controller", function () {
|
||||
var mockScope,
|
||||
mockTimeout,
|
||||
controller;
|
||||
|
||||
beforeEach(function () {
|
||||
mockScope = jasmine.createSpyObj("$scope", [ "$watch" ]);
|
||||
mockTimeout = jasmine.createSpy("$timeout");
|
||||
mockTimeout.andCallFake(function (cb) { cb(); });
|
||||
mockScope.ngModel = {};
|
||||
controller = new ViewSwitcherController(mockScope);
|
||||
controller = new ViewSwitcherController(mockScope, mockTimeout);
|
||||
});
|
||||
|
||||
it("watches for changes in applicable views", function () {
|
||||
@ -71,6 +74,19 @@ define(
|
||||
expect(mockScope.ngModel.selected).not.toEqual(views[1]);
|
||||
});
|
||||
|
||||
// Use of a timeout avoids infinite digest problems when deeply
|
||||
// nesting switcher-driven views (e.g. in a layout.) See WTD-689
|
||||
it("updates initial selection on a timeout", function () {
|
||||
// Verify precondition
|
||||
expect(mockTimeout).not.toHaveBeenCalled();
|
||||
|
||||
// Invoke the watch for set of views
|
||||
mockScope.$watch.mostRecentCall.args[1]([]);
|
||||
|
||||
// Should have run on a timeout
|
||||
expect(mockTimeout).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
);
|
Reference in New Issue
Block a user